From 723381cb2b5eddda18067b4a121ab5b5afea152b Mon Sep 17 00:00:00 2001 From: Jikoo Date: Wed, 22 Apr 2020 12:07:19 -0400 Subject: [PATCH] Fix IndexOutOfBounds on no args Closes #128 --- .../lishid/openinv/commands/SearchInvCommand.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java index 86d20d2..c471b30 100644 --- a/plugin/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java +++ b/plugin/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java @@ -40,12 +40,18 @@ public class SearchInvCommand implements TabExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { Material material = null; - int count = 1; if (args.length >= 1) { material = Material.getMaterial(args[0].toUpperCase()); } + if (material == null) { + plugin.sendMessage(sender, "messages.error.invalidMaterial", "%target%", args.length > 0 ? args[0] : "null"); + return false; + } + + int count = 1; + if (args.length >= 2) { try { count = Integer.parseInt(args[1]); @@ -55,11 +61,6 @@ public class SearchInvCommand implements TabExecutor { } } - if (material == null) { - plugin.sendMessage(sender, "messages.error.invalidMaterial", "%target%", args[0]); - return false; - } - StringBuilder players = new StringBuilder(); boolean searchInv = command.getName().equals("searchinv"); for (Player player : plugin.getServer().getOnlinePlayers()) {