diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BanItemCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BanItemCommand.java index d1383b8257..bc8170c483 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BanItemCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BanItemCommand.java @@ -8,6 +8,8 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; /** * This is our class for the /sf banitem subcommand. @@ -29,15 +31,25 @@ public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) { if (args.length >= 2) { SlimefunItem item = SlimefunItem.getById(args[1]); if (item != null) { - item.disable(); - Slimefun.getItemCfg().setValue(args[1] + ".enabled", false); - Slimefun.getItemCfg().save(); - Slimefun.getLocalization().sendMessage(sender, "commands.banitem.success", true); + banItem(item, sender); return; } Slimefun.getLocalization() .sendMessage( sender, "messages.invalid-item", true, msg -> msg.replace(PLACEHOLDER_ITEM, args[1])); + return; + } + if (sender instanceof Player player) { + ItemStack itemOnHand = player.getInventory().getItemInMainHand(); + if (!itemOnHand.getType().isAir()) { + SlimefunItem item = SlimefunItem.getByItem(itemOnHand); + if (item != null) { + banItem(item, sender); + return; + } + } + Slimefun.getLocalization().sendMessage(sender, "invalid-item-in-hand", true); + return; } Slimefun.getLocalization() .sendMessage( @@ -55,4 +67,11 @@ public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) { public String getDescription() { return "commands.banitem.description"; } + + private static void banItem(SlimefunItem slimefunItem, CommandSender sender) { + slimefunItem.disable(); + Slimefun.getItemCfg().setValue(slimefunItem.getId() + ".enabled", false); + Slimefun.getItemCfg().save(); + Slimefun.getLocalization().sendMessage(sender, "commands.banitem.success", true); + } }