From 4ed1e3914c8f34ad2b32bf3ccc3c45a2e2a6d50b Mon Sep 17 00:00:00 2001 From: Legit4K <44619264+Legit4K@users.noreply.github.com> Date: Wed, 25 Aug 2021 03:55:30 +0100 Subject: [PATCH] Add null safety While this does account for null item validation, the CommandInstance overrides all errors on the commands that throw an IllegalAccessException --- .../tplus/command/commands/BotCommand.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java b/src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java index 44a4d89..aba7605 100644 --- a/src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java +++ b/src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java @@ -120,10 +120,16 @@ public class BotCommand extends CommandInstance { usage = "" ) public void give(CommandSender sender, List args) { - String item = args.get(0); - ItemStack itemToGive = new ItemStack(Material.matchMaterial(item)); - TerminatorPlus.getInstance().getManager().fetch().forEach(b -> b.setDefaultItem(itemToGive)); - sender.sendMessage(ChatColor.GREEN + "Successfully gave all bots a " + item); + String i = args.get(0); + Material item = Material.matchMaterial(i); + ItemStack itemToGive = new ItemStack(item); + + if (item == null) { + sender.sendMessage(ChatColor.RED + "Failed to give all bots a " + ChatColor.YELLOW + item); + } else { + TerminatorPlus.getInstance().getManager().fetch().forEach(b -> b.setDefaultItem(itemToGive)); + sender.sendMessage(ChatColor.GREEN + "Successfully gave all bots a " + ChatColor.BLUE + item); + } } @Command(