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();
|
||||
List<Runnable> errors = new ArrayList<>();
|
||||
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));
|
||||
}));
|
||||
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 {
|
||||
initialize();
|
||||
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()
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
@@ -115,7 +115,7 @@ public abstract class AbstractCommand<T> {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String[] fixArgs(String[] args) {
|
||||
private String[] fixArgs(String[] args, boolean allowEmpty) {
|
||||
int removedCount = 0;
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
@@ -128,7 +128,7 @@ public abstract class AbstractCommand<T> {
|
||||
if (removedCount != 0) {
|
||||
args = Arrays.copyOf(args, args.length - removedCount);
|
||||
}
|
||||
if (args.length == 0) {
|
||||
if (args.length == 0 && !allowEmpty) {
|
||||
return new String[]{""};
|
||||
}
|
||||
return args;
|
||||
|
||||
Reference in New Issue
Block a user