Fixes some errors caused when calling a command without an argument

This commit is contained in:
Kristian Knarvik 2022-02-25 22:30:48 +01:00
parent 0ad953cc14
commit 4e44909f80
2 changed files with 10 additions and 2 deletions

View File

@ -19,7 +19,11 @@ public class TokenizedCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
arguments = Tokenizer.tokenize(String.join(" ", args)); arguments = Tokenizer.tokenize(String.join(" ", args));
if (args.length == 0) {
argumentSize = 0;
} else {
argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1;
}
return true; return true;
} }

View File

@ -21,7 +21,11 @@ public class TokenizedTabCompleter implements TabCompleter {
@Override @Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
arguments = Tokenizer.tokenize(String.join(" ", args)); arguments = Tokenizer.tokenize(String.join(" ", args));
if (args.length == 0) {
argumentSize = 0;
} else {
argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1;
}
return null; return null;
} }