mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Added command to charge items
This commit is contained in:
parent
43ef02d31c
commit
16ea468c38
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -37,6 +37,7 @@ public final class SlimefunSubCommands {
|
|||||||
commands.add(new SearchCommand(plugin, cmd));
|
commands.add(new SearchCommand(plugin, cmd));
|
||||||
commands.add(new DebugFishCommand(plugin, cmd));
|
commands.add(new DebugFishCommand(plugin, cmd));
|
||||||
commands.add(new BackpackCommand(plugin, cmd));
|
commands.add(new BackpackCommand(plugin, cmd));
|
||||||
|
commands.add(new ChargeCommand(plugin, cmd));
|
||||||
|
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,11 @@ commands:
|
|||||||
player-never-joined: '&4No player with that name could be found!'
|
player-never-joined: '&4No player with that name could be found!'
|
||||||
backpack-does-not-exist: '&4The specified backpack does not exist!'
|
backpack-does-not-exist: '&4The specified backpack does not exist!'
|
||||||
restored-backpack-given: '&aYour backpack has been restored and was added to your inventory!'
|
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:
|
guide:
|
||||||
locked: 'LOCKED'
|
locked: 'LOCKED'
|
||||||
|
Loading…
Reference in New Issue
Block a user