Add null safety

While this does account for null item validation, the CommandInstance overrides all errors on the commands that throw an IllegalAccessException
This commit is contained in:
Legit4K
2021-08-25 03:55:30 +01:00
committed by GitHub
parent 425658b308
commit 4ed1e3914c

View File

@@ -120,10 +120,16 @@ public class BotCommand extends CommandInstance {
usage = "<item>" usage = "<item>"
) )
public void give(CommandSender sender, List<String> args) { public void give(CommandSender sender, List<String> args) {
String item = args.get(0); String i = args.get(0);
ItemStack itemToGive = new ItemStack(Material.matchMaterial(item)); 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)); TerminatorPlus.getInstance().getManager().fetch().forEach(b -> b.setDefaultItem(itemToGive));
sender.sendMessage(ChatColor.GREEN + "Successfully gave all bots a " + item); sender.sendMessage(ChatColor.GREEN + "Successfully gave all bots a " + ChatColor.BLUE + item);
}
} }
@Command( @Command(