Commands Part 1
This commit is contained in:
parent
7245c556e2
commit
3b7fe970aa
|
@ -0,0 +1,77 @@
|
||||||
|
package com.arc.bloodarsenal.commands;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable;
|
||||||
|
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
|
||||||
|
import net.minecraft.command.CommandBase;
|
||||||
|
import net.minecraft.command.CommandException;
|
||||||
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandBind extends CommandBase
|
||||||
|
{
|
||||||
|
public CommandBind() {}
|
||||||
|
|
||||||
|
public String getCommandName()
|
||||||
|
{
|
||||||
|
return "bind";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRequiredPermissionLevel()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommandUsage(ICommandSender icommandsender)
|
||||||
|
{
|
||||||
|
return "commands.bind.usage";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processCommand(ICommandSender iCommandSender, String[] astring)
|
||||||
|
{
|
||||||
|
EntityPlayerMP entityplayermp = getCommandSenderAsPlayer(iCommandSender);
|
||||||
|
ItemStack item = entityplayermp.getCurrentEquippedItem();
|
||||||
|
EntityPlayerMP targetPlayer = getPlayer(iCommandSender, astring[0]);
|
||||||
|
|
||||||
|
if (targetPlayer == null)
|
||||||
|
{
|
||||||
|
throw new CommandException("commands.bind.failed.noPlayer", new Object[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item != null && item.getItem() instanceof IBindable)
|
||||||
|
{
|
||||||
|
if (EnergyItems.getOwnerName(item).isEmpty())
|
||||||
|
{
|
||||||
|
EnergyItems.checkAndSetItemOwner(item, targetPlayer);
|
||||||
|
func_152373_a(iCommandSender, this, "commands.bind.success", new Object[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new CommandException("commands.bind.failed.alreadyBound", new Object[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!(item.getItem() instanceof IBindable))
|
||||||
|
{
|
||||||
|
throw new CommandException("commands.bind.failed.notBindable", new Object[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List addTabCompletionOptions(ICommandSender iCommandSender, String[] astring)
|
||||||
|
{
|
||||||
|
return getListOfStringsMatchingLastWord(astring, this.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String[] getPlayer()
|
||||||
|
{
|
||||||
|
return MinecraftServer.getServer().getAllUsernames();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUsernameIndex(String[] astring, int par2)
|
||||||
|
{
|
||||||
|
return par2 == 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
package com.arc.bloodarsenal.commands;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
|
||||||
|
import net.minecraft.command.CommandBase;
|
||||||
|
import net.minecraft.command.CommandException;
|
||||||
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandSN extends CommandBase
|
||||||
|
{
|
||||||
|
public CommandSN()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommandName()
|
||||||
|
{
|
||||||
|
return "soulnetwork";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRequiredPermissionLevel()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommandUsage(ICommandSender icommandsender)
|
||||||
|
{
|
||||||
|
return "commands.soulnetwork.usage";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processCommand(ICommandSender icommandsender, String[] astring)
|
||||||
|
{
|
||||||
|
EntityPlayerMP targetPlayer = getPlayer(icommandsender, astring[1]);
|
||||||
|
String owner = targetPlayer.getDisplayName();
|
||||||
|
|
||||||
|
if (astring.length >= 2 && astring.length <= 3)
|
||||||
|
{
|
||||||
|
if ("add".equalsIgnoreCase(astring[1]))
|
||||||
|
{
|
||||||
|
int amount = parseIntBounded(icommandsender, astring[2], Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
|
|
||||||
|
SoulNetworkHandler.addCurrentEssenceToMaximum(owner, amount, Integer.MAX_VALUE);
|
||||||
|
func_152373_a(icommandsender, this, "commands.soulnetwork.add.success", new Object[] {amount, owner});
|
||||||
|
}
|
||||||
|
else if ("subtract".equalsIgnoreCase(astring[1]))
|
||||||
|
{
|
||||||
|
int amount = parseIntBounded(icommandsender, astring[2], Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
|
|
||||||
|
if (amount > SoulNetworkHandler.getCurrentEssence(owner))
|
||||||
|
{
|
||||||
|
SoulNetworkHandler.syphonFromNetwork(owner, SoulNetworkHandler.getCurrentEssence(owner));
|
||||||
|
func_152373_a(icommandsender, this, "commands.soulnetwork.subtract.success", new Object[] {SoulNetworkHandler.getCurrentEssence(owner), owner});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SoulNetworkHandler.syphonFromNetwork(owner, amount);
|
||||||
|
func_152373_a(icommandsender, this, "commands.soulnetwork.subtract.success", new Object[] {amount, owner});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ("fill".equalsIgnoreCase(astring[1]))
|
||||||
|
{
|
||||||
|
SoulNetworkHandler.addCurrentEssenceToMaximum(owner, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||||
|
func_152373_a(icommandsender, this, "commands.soulnetwork.fill.success", new Object[] {owner});
|
||||||
|
}
|
||||||
|
else if ("empty".equalsIgnoreCase(astring[1]))
|
||||||
|
{
|
||||||
|
SoulNetworkHandler.syphonFromNetwork(owner, SoulNetworkHandler.getCurrentEssence(owner));
|
||||||
|
func_152373_a(icommandsender, this, "commands.soulnetwork.empty.success", new Object[] {owner});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (astring.length == 0)
|
||||||
|
{
|
||||||
|
throw new CommandException("commands.soulnetwork.noPlayer", new Object[0]);
|
||||||
|
}
|
||||||
|
else if (astring.length == 1)
|
||||||
|
{
|
||||||
|
throw new CommandException("commands.soulnetwork.noCommand", new Object[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List addTabCompletionOptions(ICommandSender iCommandSender, String[] astring)
|
||||||
|
{
|
||||||
|
if (astring.length == 1)
|
||||||
|
{
|
||||||
|
return getListOfStringsMatchingLastWord(astring, this.getPlayer());
|
||||||
|
}
|
||||||
|
else if (astring.length == 2)
|
||||||
|
{
|
||||||
|
return getListOfStringsMatchingLastWord(astring, new String[] {"add", "subtract", "fill", "empty"});
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String[] getPlayer()
|
||||||
|
{
|
||||||
|
return MinecraftServer.getServer().getAllUsernames();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUsernameIndex(String[] astring, int par2)
|
||||||
|
{
|
||||||
|
return par2 == 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.arc.bloodarsenal.commands;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable;
|
||||||
|
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
|
||||||
|
import net.minecraft.command.CommandBase;
|
||||||
|
import net.minecraft.command.CommandException;
|
||||||
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public class CommandUnbind extends CommandBase
|
||||||
|
{
|
||||||
|
public CommandUnbind() {}
|
||||||
|
|
||||||
|
public String getCommandName()
|
||||||
|
{
|
||||||
|
return "unbind";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRequiredPermissionLevel()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommandUsage(ICommandSender icommandsender)
|
||||||
|
{
|
||||||
|
return "commands.unbind.usage";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processCommand(ICommandSender iCommandSender, String[] astring)
|
||||||
|
{
|
||||||
|
EntityPlayerMP entityplayermp = getCommandSenderAsPlayer(iCommandSender);
|
||||||
|
ItemStack item = entityplayermp.getCurrentEquippedItem();
|
||||||
|
|
||||||
|
if (item != null && item.getItem() instanceof IBindable)
|
||||||
|
{
|
||||||
|
if (!EnergyItems.getOwnerName(item).isEmpty())
|
||||||
|
{
|
||||||
|
item.stackTagCompound.setString("ownerName", "");
|
||||||
|
func_152373_a(iCommandSender, this, "commands.unbind.success", new Object[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new CommandException("commands.unbind.failed.notBindable", new Object[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!(item.getItem() instanceof IBindable))
|
||||||
|
{
|
||||||
|
throw new CommandException("commands.unbind.failed.notBindable", new Object[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue