forked from SteamWar/SteamWar
Fix AbstractCommand with empty args for execute
This commit is contained in:
@@ -88,7 +88,7 @@ public abstract class AbstractCommand<T> {
|
|||||||
initialize();
|
initialize();
|
||||||
List<Runnable> errors = new ArrayList<>();
|
List<Runnable> errors = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
boolean executed = rootNode.execute(sender, new NodeData(alias, fixArgs(args), (s, args1) -> {
|
boolean executed = rootNode.execute(sender, new NodeData(alias, fixArgs(args, true), (s, args1) -> {
|
||||||
errors.add(() -> sendMessage(sender, s, args1));
|
errors.add(() -> sendMessage(sender, s, args1));
|
||||||
}));
|
}));
|
||||||
if (executed) return;
|
if (executed) return;
|
||||||
@@ -105,7 +105,7 @@ public abstract class AbstractCommand<T> {
|
|||||||
public final List<String> tabComplete(T sender, String alias, String[] args) throws IllegalArgumentException {
|
public final List<String> tabComplete(T sender, String alias, String[] args) throws IllegalArgumentException {
|
||||||
initialize();
|
initialize();
|
||||||
List<Collection<String>> tabCompletes = new ArrayList<>();
|
List<Collection<String>> tabCompletes = new ArrayList<>();
|
||||||
rootNode.tabComplete(sender, new NodeData(alias, fixArgs(args), (s, args1) -> {}), tabCompletes);
|
rootNode.tabComplete(sender, new NodeData(alias, fixArgs(args, false), (s, args1) -> {}), tabCompletes);
|
||||||
return tabCompletes.stream()
|
return tabCompletes.stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
@@ -115,7 +115,7 @@ public abstract class AbstractCommand<T> {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] fixArgs(String[] args) {
|
private String[] fixArgs(String[] args, boolean allowEmpty) {
|
||||||
int removedCount = 0;
|
int removedCount = 0;
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
String arg = args[i];
|
String arg = args[i];
|
||||||
@@ -128,7 +128,7 @@ public abstract class AbstractCommand<T> {
|
|||||||
if (removedCount != 0) {
|
if (removedCount != 0) {
|
||||||
args = Arrays.copyOf(args, args.length - removedCount);
|
args = Arrays.copyOf(args, args.length - removedCount);
|
||||||
}
|
}
|
||||||
if (args.length == 0) {
|
if (args.length == 0 && !allowEmpty) {
|
||||||
return new String[]{""};
|
return new String[]{""};
|
||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
|
|||||||
Reference in New Issue
Block a user