From 3b7fe970aa35316e06d3a9eefc2f2c7bf7fec645 Mon Sep 17 00:00:00 2001 From: Arcaratus Date: Sat, 3 Jan 2015 10:23:17 -0500 Subject: [PATCH 1/8] Commands Part 1 --- .../common/commands/CommandBind.java | 77 +++++++++++++ .../common/commands/CommandSN.java | 107 ++++++++++++++++++ .../common/commands/CommandUnbind.java | 52 +++++++++ 3 files changed, 236 insertions(+) create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandBind.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandUnbind.java diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandBind.java b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandBind.java new file mode 100644 index 00000000..ff647e1e --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandBind.java @@ -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; + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java new file mode 100644 index 00000000..0454f619 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java @@ -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; + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandUnbind.java b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandUnbind.java new file mode 100644 index 00000000..786d53f5 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandUnbind.java @@ -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]); + } + } +} From 4d90e540b82289c5f7f6773356ed9e3cbb4575c9 Mon Sep 17 00:00:00 2001 From: Arcaratus Date: Sat, 3 Jan 2015 10:25:50 -0500 Subject: [PATCH 2/8] Commands Part 2 --- .../alchemicalWizardry/AlchemicalWizardry.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java index 5973a38b..f4305c7f 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java @@ -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.commands.CommandBind; +import WayofTime.alchemicalWizardry.commands.CommandUnbind; +import WayofTime.alchemicalWizardry.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()); + } } From 40aa2534eee9ffad928c1354e779815c46acf6fb Mon Sep 17 00:00:00 2001 From: Arcaratus Date: Sat, 3 Jan 2015 10:26:56 -0500 Subject: [PATCH 3/8] Commands Part 2 --- .../WayofTime/alchemicalWizardry/AlchemicalWizardry.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java index f4305c7f..2e57a777 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java @@ -255,9 +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.commands.CommandBind; -import WayofTime.alchemicalWizardry.commands.CommandUnbind; -import WayofTime.alchemicalWizardry.commands.CommandSN; +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; From 30e4ed064d92da3368f0ecf1b2416c9a87e71931 Mon Sep 17 00:00:00 2001 From: Arcaratus Date: Sat, 3 Jan 2015 10:27:40 -0500 Subject: [PATCH 4/8] Commands Part 2 --- .../alchemicalWizardry/common/commands/CommandUnbind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandUnbind.java b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandUnbind.java index 786d53f5..7c2988ff 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandUnbind.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandUnbind.java @@ -1,4 +1,4 @@ -package com.arc.bloodarsenal.commands; +package WayofTime.alchemicalWizardry.common.commands; import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable; import WayofTime.alchemicalWizardry.common.items.EnergyItems; From b5eec00c7b1cbef35779063e3a61d5202e93399b Mon Sep 17 00:00:00 2001 From: Arcaratus Date: Sat, 3 Jan 2015 10:27:56 -0500 Subject: [PATCH 5/8] Commands Part 2 --- .../alchemicalWizardry/common/commands/CommandSN.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java index 0454f619..5a3a136b 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java @@ -1,4 +1,4 @@ -package com.arc.bloodarsenal.commands; +package WayofTime.alchemicalWizardry.common.commands; import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; import net.minecraft.command.CommandBase; @@ -11,10 +11,7 @@ import java.util.List; public class CommandSN extends CommandBase { - public CommandSN() - { - - } + public CommandSN() {} public String getCommandName() { From 5e91c1a91f2d68e0cac4b4a49ee4ce30c525f012 Mon Sep 17 00:00:00 2001 From: Arcaratus Date: Sat, 3 Jan 2015 10:28:09 -0500 Subject: [PATCH 6/8] Commands Part 2 --- .../alchemicalWizardry/common/commands/CommandBind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandBind.java b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandBind.java index ff647e1e..6a2c5a1f 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandBind.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandBind.java @@ -1,4 +1,4 @@ -package com.arc.bloodarsenal.commands; +package WayofTime.alchemicalWizardry.common.commands; import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable; import WayofTime.alchemicalWizardry.common.items.EnergyItems; From b7bd031028cecd23f7813a597ee7cdd7cf951c47 Mon Sep 17 00:00:00 2001 From: Arcaratus Date: Sat, 3 Jan 2015 10:50:57 -0500 Subject: [PATCH 7/8] Commands Part 3 --- .../assets/alchemicalwizardry/lang/en_US.lang | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang b/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang index 11e8d0d2..959ad876 100644 --- a/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang +++ b/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang @@ -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 \ No newline at end of file +entity.AWWayofTime.MinorDemonGrunt.name=Demon Grunt + +#Commands +commands.soulnetwork.usage=/soulnetwork +commands.bind.usage=/bind +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 [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 From b82c13521d26cd2add7a4e8a5cacad30ddde84af Mon Sep 17 00:00:00 2001 From: Arcaratus Date: Sat, 3 Jan 2015 10:53:16 -0500 Subject: [PATCH 8/8] Commands Part 3 --- .../common/commands/CommandSN.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java index 5a3a136b..ac89f1bf 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/commands/CommandSN.java @@ -30,7 +30,7 @@ public class CommandSN extends CommandBase public void processCommand(ICommandSender icommandsender, String[] astring) { - EntityPlayerMP targetPlayer = getPlayer(icommandsender, astring[1]); + EntityPlayerMP targetPlayer = getPlayer(icommandsender, astring[0]); String owner = targetPlayer.getDisplayName(); if (astring.length >= 2 && astring.length <= 3) @@ -48,7 +48,8 @@ public class CommandSN extends CommandBase if (amount > SoulNetworkHandler.getCurrentEssence(owner)) { - SoulNetworkHandler.syphonFromNetwork(owner, 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 @@ -59,7 +60,8 @@ public class CommandSN extends CommandBase } else if ("fill".equalsIgnoreCase(astring[1])) { - SoulNetworkHandler.addCurrentEssenceToMaximum(owner, Integer.MAX_VALUE, Integer.MAX_VALUE); + 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])) @@ -67,6 +69,15 @@ public class CommandSN extends CommandBase 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) {