From 4e44909f803fd15956345bc4132da5d340bf7524 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 25 Feb 2022 22:30:48 +0100 Subject: [PATCH] Fixes some errors caused when calling a command without an argument --- .../net/knarcraft/paidsigns/command/TokenizedCommand.java | 6 +++++- .../knarcraft/paidsigns/command/TokenizedTabCompleter.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java b/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java index bbd6802..a9f1146 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java @@ -19,7 +19,11 @@ public class TokenizedCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { arguments = Tokenizer.tokenize(String.join(" ", args)); - argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; + if (args.length == 0) { + argumentSize = 0; + } else { + argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; + } return true; } diff --git a/src/main/java/net/knarcraft/paidsigns/command/TokenizedTabCompleter.java b/src/main/java/net/knarcraft/paidsigns/command/TokenizedTabCompleter.java index 2d78bc0..d5b6b0a 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/TokenizedTabCompleter.java +++ b/src/main/java/net/knarcraft/paidsigns/command/TokenizedTabCompleter.java @@ -21,7 +21,11 @@ public class TokenizedTabCompleter implements TabCompleter { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { arguments = Tokenizer.tokenize(String.join(" ", args)); - argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; + if (args.length == 0) { + argumentSize = 0; + } else { + argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; + } return null; }