Merge pull request #194 from Arcaratus/master

Added SN commands
This commit is contained in:
WayofTime 2015-01-03 11:13:44 -05:00
commit beab450a62
5 changed files with 278 additions and 2 deletions

View file

@ -255,6 +255,9 @@ import WayofTime.alchemicalWizardry.common.tileEntity.TESpellParadigmBlock;
import WayofTime.alchemicalWizardry.common.tileEntity.TETeleposer;
import WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable;
import WayofTime.alchemicalWizardry.common.tileEntity.gui.GuiHandler;
import WayofTime.alchemicalWizardry.common.commands.CommandBind;
import WayofTime.alchemicalWizardry.common.commands.CommandUnbind;
import WayofTime.alchemicalWizardry.common.commands.CommandSN;
import WayofTime.alchemicalWizardry.common.tweaker.MineTweakerIntegration;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
@ -265,6 +268,7 @@ import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
@ -1519,7 +1523,7 @@ public class AlchemicalWizardry
continue;
}
strLine = strLine.replace('”', '"').replace('“','"');
strLine = strLine.replace('”', '"').replace('“','"');
if(Minecraft.getMinecraft() != null && Minecraft.getMinecraft().fontRenderer != null)
{
@ -1619,4 +1623,12 @@ public class AlchemicalWizardry
}
}
}
@Mod.EventHandler
public void initCommands(FMLServerStartingEvent event)
{
event.registerServerCommand(new CommandBind());
event.registerServerCommand(new CommandUnbind());
event.registerServerCommand(new CommandSN());
}
}

View file

@ -0,0 +1,77 @@
package WayofTime.alchemicalWizardry.common.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;
}
}

View file

@ -0,0 +1,115 @@
package WayofTime.alchemicalWizardry.common.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[0]);
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))
{
int lp = SoulNetworkHandler.getCurrentEssence(owner);
SoulNetworkHandler.syphonFromNetwork(owner, lp);
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]))
{
int amount = Integer.MAX_VALUE - SoulNetworkHandler.getCurrentEssence(owner);
SoulNetworkHandler.addCurrentEssenceToMaximum(owner, amount, 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 ("get".equalsIgnoreCase(astring[1]))
{
int amount = SoulNetworkHandler.getCurrentEssence(owner);
func_152373_a(icommandsender, this, "commands.soulnetwork.get.success", new Object[] {amount, owner});
}
else
{
throw new CommandException("commands.soulnetwork.notACommand", new Object[0]);
}
}
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;
}
}

View file

@ -0,0 +1,52 @@
package WayofTime.alchemicalWizardry.common.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]);
}
}
}

View file

@ -233,4 +233,24 @@ entity.AWWayofTime.MinorDemonGruntWind.name=Wind Demon Grunt
entity.AWWayofTime.MinorDemonGruntFire.name=Fire Demon Grunt
entity.AWWayofTime.MinorDemonGruntIce.name=Ice Demon Grunt
entity.AWWayofTime.MinorDemonGruntEarth.name=Earth Demon Grunt
entity.AWWayofTime.MinorDemonGrunt.name=Demon Grunt
entity.AWWayofTime.MinorDemonGrunt.name=Demon Grunt
#Commands
commands.soulnetwork.usage=/soulnetwork <player>
commands.bind.usage=/bind <player>
commands.bind.success=Item successfully bound!
commands.bind.failed.noPlayer=There is no player specified
commands.bind.failed.alreadyBound=Item is already bound; use /unbind to unbind it
commands.bind.failed.notBindable=Item cannot be bound
commands.unbind.usage=/unbind
commands.unbind.success=Item successfully unbound!
commands.unbind.failed.notBindable=Item cannot be unbound
commands.soulnetwork.usage=/soulnetwork <player> <add|subtract|fill|empty|get> [amount]
commands.soulnetwork.add.success=Successfully added %dLP to %s's Soul Network!
commands.soulnetwork.subtract.success=Successfully subtracted %dLP from %s's Soul Network!
commands.soulnetwork.fill.success=Successfully filled %s's Soul Network!
commands.soulnetwork.empty.success=Successfully emptied %s's Soul Network!
commands.soulnetwork.get.success=There is %dLP in %s's Soul Network!
commands.soulnetwork.noPlayer=There is no player specified
commands.soulnetwork.noCommand=There is no command specified
commands.soulnetwork.notACommand=That is not a valid command