diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java new file mode 100644 index 000000000..86e56d941 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java @@ -0,0 +1,44 @@ +package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; + +import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable; +import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; +import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +class ChargeCommand extends SubCommand { + + ChargeCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { + super(plugin, cmd, "charge", false); + } + + protected String getDescription() { + return "commands.charge.description"; + } + + @Override + public void onExecute(CommandSender sender, String[] args) { + if (sender instanceof Player) { + if (sender.hasPermission("slimefun.charge.command")) { + Player p = ((Player) sender).getPlayer(); + final ItemStack item = p.getInventory().getItemInMainHand(); + final SlimefunItem slimefunItem = SlimefunItem.getByItem(item); + if (slimefunItem instanceof Rechargeable){ + ((Rechargeable) slimefunItem).addItemCharge(item, ((Rechargeable) slimefunItem).getMaxItemCharge(item)); + SlimefunPlugin.getLocalization().sendMessage(sender, "commands.charge.charge-success", true); + } else { + SlimefunPlugin.getLocalization().sendMessage(sender, "commands.charge.not-rechargeable", true); + } + } + else { + SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true); + } + } + else { + SlimefunPlugin.getLocalization().sendMessage(sender, "messages.only-players", true); + } + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java index 0d337f1f4..10378c3ff 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java @@ -37,6 +37,7 @@ public final class SlimefunSubCommands { commands.add(new SearchCommand(plugin, cmd)); commands.add(new DebugFishCommand(plugin, cmd)); commands.add(new BackpackCommand(plugin, cmd)); + commands.add(new ChargeCommand(plugin, cmd)); return commands; } diff --git a/src/main/resources/languages/messages_en.yml b/src/main/resources/languages/messages_en.yml index f4fac7169..15e947949 100644 --- a/src/main/resources/languages/messages_en.yml +++ b/src/main/resources/languages/messages_en.yml @@ -21,6 +21,11 @@ commands: player-never-joined: '&4No player with that name could be found!' backpack-does-not-exist: '&4The specified backpack does not exist!' restored-backpack-given: '&aYour backpack has been restored and was added to your inventory!' + + charge: + description: Charges the item you are holding + charge-success: Item has been charged! + not-rechargeable: This item can not be charged! guide: locked: 'LOCKED'