Localize new commands + Add an Orb command
This commit is contained in:
parent
80b76a2dbb
commit
6e54f83ebd
|
@ -9,6 +9,7 @@ import net.minecraft.server.MinecraftServer;
|
|||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -41,17 +42,17 @@ public abstract class SubCommandBase implements ISubCommand {
|
|||
public void processSubCommand(ICommandSender commandSender, String[] args) {
|
||||
|
||||
if (args.length == 0 && !getSubCommandName().equals("help"))
|
||||
displayErrorString(commandSender, String.format("%s - %s", capitalizeFirstLetter(getSubCommandName()), getArgUsage(commandSender)));
|
||||
displayErrorString(commandSender, String.format(StatCollector.translateToLocal("commands.format.error"), capitalizeFirstLetter(getSubCommandName()), getArgUsage(commandSender)));
|
||||
|
||||
if (isBounded(0, 2, args.length) && args[0].equals("help"))
|
||||
displayHelpString(commandSender, String.format("%s - %s", capitalizeFirstLetter(getSubCommandName()), getHelpText()));
|
||||
displayHelpString(commandSender, String.format(StatCollector.translateToLocal("commands.format.help"), capitalizeFirstLetter(getSubCommandName()), getHelpText()));
|
||||
}
|
||||
|
||||
protected EntityPlayerMP getCommandSenderAsPlayer(ICommandSender commandSender) {
|
||||
if (commandSender instanceof EntityPlayerMP)
|
||||
return (EntityPlayerMP)commandSender;
|
||||
else
|
||||
throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
|
||||
throw new PlayerNotFoundException(StatCollector.translateToLocal("commands.error.arg.player.missing"));
|
||||
}
|
||||
|
||||
protected EntityPlayerMP getPlayer(ICommandSender commandSender, String playerName) {
|
||||
|
@ -77,11 +78,15 @@ public abstract class SubCommandBase implements ISubCommand {
|
|||
return given > low && given < high;
|
||||
}
|
||||
|
||||
protected void displayHelpString(ICommandSender commandSender, String display) {
|
||||
commandSender.addChatMessage(new ChatComponentText(display).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
|
||||
protected void displayHelpString(ICommandSender commandSender, String display, Object ... info) {
|
||||
commandSender.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted(display, info)).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
|
||||
}
|
||||
|
||||
protected void displayErrorString(ICommandSender commandSender, String display) {
|
||||
commandSender.addChatMessage(new ChatComponentText(display).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
protected void displayErrorString(ICommandSender commandSender, String display, Object ... info) {
|
||||
commandSender.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted(display, info)).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
}
|
||||
|
||||
protected void displaySuccessString(ICommandSender commandSender, String display, Object ... info) {
|
||||
commandSender.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted(display, info)).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.BLUE)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ import WayofTime.alchemicalWizardry.api.command.ISubCommand;
|
|||
import WayofTime.alchemicalWizardry.common.commands.sub.SubCommandBind;
|
||||
import WayofTime.alchemicalWizardry.common.commands.sub.SubCommandHelp;
|
||||
import WayofTime.alchemicalWizardry.common.commands.sub.SubCommandNetwork;
|
||||
import WayofTime.alchemicalWizardry.common.commands.sub.SubCommandOrb;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
|
@ -27,6 +29,7 @@ public class CommandBloodMagic extends CommandBase {
|
|||
subCommands.put("help", new SubCommandHelp(this));
|
||||
subCommands.put("network", new SubCommandNetwork(this));
|
||||
subCommands.put("bind", new SubCommandBind(this));
|
||||
subCommands.put("orb", new SubCommandOrb(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,9 +62,9 @@ public class CommandBloodMagic extends CommandBase {
|
|||
if (subCommand.canSenderUseSubCommand(commandSender))
|
||||
subCommand.processSubCommand(commandSender, subArgs);
|
||||
else
|
||||
commandSender.addChatMessage(new ChatComponentText("You do not have permission to use this command.").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
commandSender.addChatMessage(new ChatComponentTranslation("commands.error.perm").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
} else {
|
||||
commandSender.addChatMessage(new ChatComponentText("Unknown command!").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
commandSender.addChatMessage(new ChatComponentTranslation("commands.error.unknown").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ import net.minecraft.command.ICommandSender;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class SubCommandBind extends SubCommandBase {
|
||||
|
||||
|
@ -17,12 +19,12 @@ public class SubCommandBind extends SubCommandBase {
|
|||
|
||||
@Override
|
||||
public String getArgUsage(ICommandSender commandSender) {
|
||||
return "/bloodmagic bind [true|false] [player]";
|
||||
return StatCollector.translateToLocal("commands.bind.usage");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() {
|
||||
return "Attempts to (un)bind the currently held item.";
|
||||
return StatCollector.translateToLocal("commands.bind.help");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,11 +59,11 @@ public class SubCommandBind extends SubCommandBase {
|
|||
|
||||
if (bind) {
|
||||
EnergyItems.setItemOwner(held, playerName);
|
||||
commandSender.addChatMessage(new ChatComponentText("Binding successful"));
|
||||
commandSender.addChatMessage(new ChatComponentTranslation("commands.bind.success"));
|
||||
} else {
|
||||
if (!EnergyItems.getOwnerName(held).isEmpty()) {
|
||||
held.stackTagCompound.removeTag("ownerName");
|
||||
commandSender.addChatMessage(new ChatComponentText("Unbinding successful"));
|
||||
commandSender.addChatMessage(new ChatComponentTranslation("commands.bind.remove.success"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.minecraft.command.ICommandSender;
|
|||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class SubCommandHelp extends SubCommandBase {
|
||||
|
||||
|
@ -17,12 +18,12 @@ public class SubCommandHelp extends SubCommandBase {
|
|||
|
||||
@Override
|
||||
public String getArgUsage(ICommandSender commandSender) {
|
||||
return "/bloodmagic help";
|
||||
return StatCollector.translateToLocal("commands.help.usage");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() {
|
||||
return "Displays the help information for the \"/bloodmagic\" command.";
|
||||
return StatCollector.translateToLocal("commands.help.help");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,6 +39,6 @@ public class SubCommandHelp extends SubCommandBase {
|
|||
return;
|
||||
|
||||
for (ISubCommand subCommand : ((CommandBloodMagic)getParentCommand()).getSubCommands().values())
|
||||
commandSender.addChatMessage(new ChatComponentText(String.format("%s - %s", capitalizeFirstLetter(subCommand.getSubCommandName()), subCommand.getArgUsage(commandSender))).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
|
||||
commandSender.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("commands.format.help", capitalizeFirstLetter(subCommand.getSubCommandName()), subCommand.getArgUsage(commandSender))).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.command.ICommand;
|
|||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -17,12 +18,12 @@ public class SubCommandNetwork extends SubCommandBase {
|
|||
|
||||
@Override
|
||||
public String getArgUsage(ICommandSender commandSender) {
|
||||
return "/bloodmagic network [syphon|add|get|fill|cap] player [amount]";
|
||||
return StatCollector.translateToLocal("commands.network.usage");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() {
|
||||
return "LP network utilities";
|
||||
return StatCollector.translateToLocal("commands.network.help");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,11 +62,12 @@ public class SubCommandNetwork extends SubCommandBase {
|
|||
if (isInteger(args[2])) {
|
||||
int amount = Integer.parseInt(args[2]);
|
||||
SoulNetworkHandler.syphonAndDamageFromNetwork(givenName, player, amount);
|
||||
displaySuccessString(commandSender, "commands.network.syphon.success", amount, givenName);
|
||||
} else {
|
||||
displayErrorString(commandSender, "Invalid arguments");
|
||||
displayErrorString(commandSender, "commands.error.arg.invalid");
|
||||
}
|
||||
} else {
|
||||
displayErrorString(commandSender, "Not enough arguments");
|
||||
displayErrorString(commandSender, "commands.error.arg.missing");
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -81,11 +83,12 @@ public class SubCommandNetwork extends SubCommandBase {
|
|||
int amount = Integer.parseInt(args[2]);
|
||||
int maxOrb = SoulNetworkHandler.getMaximumForOrbTier(SoulNetworkHandler.getCurrentMaxOrb(givenName));
|
||||
SoulNetworkHandler.addCurrentEssenceToMaximum(givenName, amount, maxOrb);
|
||||
displaySuccessString(commandSender, "commands.network.add.success", amount, givenName);
|
||||
} else {
|
||||
displayErrorString(commandSender, "Invalid arguments");
|
||||
displayErrorString(commandSender, "commands.error.arg.invalid");
|
||||
}
|
||||
} else {
|
||||
displayErrorString(commandSender, "Not enough arguments");
|
||||
displayErrorString(commandSender, "commands.error.arg.missing");
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -100,12 +103,15 @@ public class SubCommandNetwork extends SubCommandBase {
|
|||
if (isInteger(args[2])) {
|
||||
int amount = Integer.parseInt(args[2]);
|
||||
SoulNetworkHandler.setCurrentEssence(givenName, amount);
|
||||
displaySuccessString(commandSender, "commands.network.set.success", givenName, amount);
|
||||
} else {
|
||||
displayErrorString(commandSender, "Invalid arguments");
|
||||
displayErrorString(commandSender, "commands.error.arg.invalid");
|
||||
}
|
||||
} else {
|
||||
displayErrorString(commandSender, "Not enough arguments");
|
||||
displayErrorString(commandSender, "commands.error.arg.missing");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case GET: {
|
||||
if (displayHelp) {
|
||||
|
@ -114,18 +120,20 @@ public class SubCommandNetwork extends SubCommandBase {
|
|||
}
|
||||
|
||||
if (args.length > 1)
|
||||
commandSender.addChatMessage(new ChatComponentText("Current Essence: " + SoulNetworkHandler.getCurrentEssence(givenName)));
|
||||
commandSender.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.divinationsigil.currentessence") + " " + SoulNetworkHandler.getCurrentEssence(givenName) + "LP"));
|
||||
|
||||
break;
|
||||
}
|
||||
case FILL: {
|
||||
if (displayHelp) {
|
||||
displayHelpString(commandSender, ValidCommands.FILL.help);
|
||||
displayHelpString(commandSender, ValidCommands.FILL.help, Integer.MAX_VALUE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (args.length > 1)
|
||||
if (args.length > 1) {
|
||||
SoulNetworkHandler.setCurrentEssence(givenName, Integer.MAX_VALUE);
|
||||
displaySuccessString(commandSender, "commands.network.fill.success", givenName);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -138,24 +146,25 @@ public class SubCommandNetwork extends SubCommandBase {
|
|||
if (args.length > 1) {
|
||||
int maxOrb = SoulNetworkHandler.getMaximumForOrbTier(SoulNetworkHandler.getCurrentMaxOrb(givenName));
|
||||
SoulNetworkHandler.setCurrentEssence(givenName, maxOrb);
|
||||
displaySuccessString(commandSender, "commands.network.cap.success", givenName);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
displayErrorString(commandSender, "Command not found!");
|
||||
displayErrorString(commandSender, "commands.error.404");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum ValidCommands {
|
||||
SYPHON("Removes the given amount of LP from the given player's LP network."),
|
||||
ADD("Adds the given amount of LP to the given player's LP network."),
|
||||
SET("Sets the given player's LP to the given amount"),
|
||||
GET("Returns the amount of LP in the given player's LP network."),
|
||||
FILL(String.format("Fills the given player's LP network to %d", Integer.MAX_VALUE)),
|
||||
CAP("Fills the given player's LP network to the max that their highest Blood Orb can store.");
|
||||
SYPHON("commands.network.syphon.help"),
|
||||
ADD("commands.network.add.help"),
|
||||
SET("commands.network.set.help"),
|
||||
GET("commands.network.get.help"),
|
||||
FILL("commands.network.fill.help"),
|
||||
CAP("commands.network.cap.help");
|
||||
|
||||
public String help;
|
||||
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
package WayofTime.alchemicalWizardry.common.commands.sub;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.command.SubCommandBase;
|
||||
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class SubCommandOrb extends SubCommandBase {
|
||||
|
||||
public SubCommandOrb(ICommand parent) {
|
||||
super(parent, "orb");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgUsage(ICommandSender commandSender) {
|
||||
return StatCollector.translateToLocal("commands.orb.usage");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() {
|
||||
return StatCollector.translateToLocal("commands.orb.help");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processSubCommand(ICommandSender commandSender, String[] args) {
|
||||
super.processSubCommand(commandSender, args);
|
||||
|
||||
if (args.length > 0) {
|
||||
|
||||
if (args[0].equalsIgnoreCase("help"))
|
||||
return;
|
||||
|
||||
String givenName = commandSender.getCommandSenderName();
|
||||
|
||||
if (args.length > 1)
|
||||
givenName = args[1];
|
||||
|
||||
boolean displayHelp = isBounded(0, 2, args.length);
|
||||
|
||||
try {
|
||||
switch (ValidCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH))) {
|
||||
case SET: {
|
||||
if (displayHelp) {
|
||||
displayHelpString(commandSender, ValidCommands.SET.help);
|
||||
break;
|
||||
}
|
||||
|
||||
if (args.length == 3) {
|
||||
if (isInteger(args[2])) {
|
||||
int amount = Integer.parseInt(args[2]);
|
||||
SoulNetworkHandler.setMaxOrbToMax(givenName, amount);
|
||||
displaySuccessString(commandSender, "commands.success");
|
||||
} else {
|
||||
displayErrorString(commandSender, "commands.error.arg.invalid");
|
||||
}
|
||||
} else {
|
||||
displayErrorString(commandSender, "commands.error.arg.missing");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case GET: {
|
||||
if (displayHelp) {
|
||||
displayHelpString(commandSender, ValidCommands.GET.help);
|
||||
break;
|
||||
}
|
||||
|
||||
if (args.length > 1)
|
||||
commandSender.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("message.orb.currenttier", SoulNetworkHandler.getCurrentMaxOrb(givenName))));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
displayErrorString(commandSender, "commands.error.404");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum ValidCommands {
|
||||
SET("commands.orb.set.help"),
|
||||
GET("commands.orb.get.help");
|
||||
|
||||
public String help;
|
||||
|
||||
ValidCommands(String help) {
|
||||
this.help = help;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private static boolean isInteger(String s) {
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
} catch(NumberFormatException e) {
|
||||
return false;
|
||||
} catch(NullPointerException e) {
|
||||
return false;
|
||||
}
|
||||
// only got here if we didn't return false
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -284,7 +284,43 @@ entity.AWWayofTime.MinorDemonGruntEarth.name=Earth Demon Grunt
|
|||
entity.AWWayofTime.MinorDemonGrunt.name=Demon Grunt
|
||||
|
||||
#Commands
|
||||
commands.soulnetwork.usage=/soulnetwork <player>
|
||||
commands.error.arg.invalid=Invalid arguments
|
||||
commands.error.arg.missing=Not enough arguments
|
||||
commands.error.arg.player.missing=You must specify which player you wish to perform this action on.
|
||||
commands.error.404=Command not found!
|
||||
commands.error.unknown=Unknown command!
|
||||
commands.error.perm=You do not have permission to use this command.
|
||||
|
||||
commands.success=Executed successfully
|
||||
|
||||
commands.format.help=%s - %s
|
||||
commands.format.error=%s - %s
|
||||
|
||||
commands.help.usage=/bloodmagic help
|
||||
commands.help.help=Displays the help information for the "/bloodmagic" command.
|
||||
|
||||
commands.network.usage=/bloodmagic network [syphon|add|get|fill|cap] player [amount]
|
||||
commands.network.help=LP network utilities
|
||||
commands.network.syphon.help=Removes the given amount of LP from the given player's LP network.
|
||||
commands.network.syphon.success=Successfully syphoned %d LP from %s.
|
||||
commands.network.add.help=Adds the given amount of LP to the given player's LP network. Follows standard LP gain rules.
|
||||
commands.network.add.success=Successfully added %d LP to %s's LP network.
|
||||
commands.network.set.help=Sets the given player's LP to the given amount.
|
||||
commands.network.set.success=Successfully set %s's LP network to %d LP.
|
||||
commands.network.get.help=Returns the amount of LP in the given player's LP network.
|
||||
commands.network.fill.help=Fills the given player's LP network to %d.
|
||||
commands.network.fill.success=Successfully filled %s's LP network.
|
||||
commands.network.cap.help=Fills the given player's LP network to the max that their highest Blood Orb can store.
|
||||
commands.network.cap.success=Successfully capped off %s's LP network.
|
||||
|
||||
commands.bind.usage=/bloodmagic bind [true|false] [player]
|
||||
commands.bind.help=Attempts to (un)bind the currently held item.
|
||||
commands.bind.success=Binding successful
|
||||
commands.bind.remove.success=Unbinding successful
|
||||
|
||||
commands.orb.usage=/bloodmagic orb [set|get] player [tier]
|
||||
commands.orb.help=Used to set or get the Player's max Blood Orb tier.
|
||||
|
||||
commands.bind.usage=/bind <player>
|
||||
commands.bind.success=Item successfully bound!
|
||||
commands.bind.failed.noPlayer=There is no player specified
|
||||
|
@ -449,6 +485,7 @@ message.destinationclearer.cleared=Destination list now cleared.
|
|||
message.divinationsigil.amount=Amount:
|
||||
message.divinationsigil.currentessence=Current Essence:
|
||||
message.divinationsigil.reagent=Reagent:
|
||||
message.orb.currenttier=Current Tier: %d
|
||||
message.masterstone.crystalvibrates=Your crystal vibrates pathetically.
|
||||
message.masterstone.energyflows=A rush of energy flows through the ritual!
|
||||
message.masterstone.nothinghappened=Nothing appears to have happened...
|
||||
|
|
Loading…
Reference in a new issue