mirror of
https://github.com/GTNewHorizons/BloodMagic.git
synced 2026-11-19 03:39:20 +00:00
Rework commands to be sub commands of /bloodmagic
This commit is contained in:
1 parent
fa78706fca
commit
731f92a7fd
7 files changed
+461
-3
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package WayofTime.alchemicalWizardry.common.commands.sub;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.command.SubCommandBase;
|
||||
import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable;
|
||||
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
|
||||
public class SubCommandBind extends SubCommandBase {
|
||||
|
||||
public SubCommandBind(ICommand parent) {
|
||||
super(parent, "bind");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgUsage(ICommandSender commandSender) {
|
||||
return "/bloodmagic bind [true|false] [player]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() {
|
||||
return "Attempts to (un)bind the currently held item.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processSubCommand(ICommandSender commandSender, String[] args) {
|
||||
super.processSubCommand(commandSender, args);
|
||||
|
||||
EntityPlayer player = getCommandSenderAsPlayer(commandSender);
|
||||
String playerName = player.getCommandSenderName();
|
||||
ItemStack held = player.getHeldItem();
|
||||
boolean bind = true;
|
||||
|
||||
if (held != null && held.getItem() instanceof IBindable) {
|
||||
if (args.length > 0) {
|
||||
|
||||
if (args[0].equalsIgnoreCase("help"))
|
||||
return;
|
||||
|
||||
if (isBoolean(args[0])) {
|
||||
bind = Boolean.parseBoolean(args[0]);
|
||||
|
||||
if (args.length > 2)
|
||||
playerName = args[1];
|
||||
} else {
|
||||
playerName = args[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (bind) {
|
||||
EnergyItems.setItemOwner(held, playerName);
|
||||
commandSender.addChatMessage(new ChatComponentText("Binding successful"));
|
||||
} else {
|
||||
if (!EnergyItems.getOwnerName(held).isEmpty()) {
|
||||
held.stackTagCompound.removeTag("ownerName");
|
||||
commandSender.addChatMessage(new ChatComponentText("Unbinding successful"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isBoolean(String string) {
|
||||
return string.equalsIgnoreCase("true") || string.equalsIgnoreCase("false");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user