diff options
author | okamosy <okamosy@gmail.com> | 2011-08-21 02:50:48 +0100 |
---|---|---|
committer | okamosy <okamosy@gmail.com> | 2011-08-21 02:50:48 +0100 |
commit | 45f88016fce4d170cac22bbbdc040fdbfe3d14f1 (patch) | |
tree | 18796a767c114c46508939ba7a3c923662048333 | |
parent | d14f278ecf7e6a4f3c851a8b28a052d15d47771b (diff) | |
download | Essentials-45f88016fce4d170cac22bbbdc040fdbfe3d14f1.tar Essentials-45f88016fce4d170cac22bbbdc040fdbfe3d14f1.tar.gz Essentials-45f88016fce4d170cac22bbbdc040fdbfe3d14f1.tar.lz Essentials-45f88016fce4d170cac22bbbdc040fdbfe3d14f1.tar.xz Essentials-45f88016fce4d170cac22bbbdc040fdbfe3d14f1.zip |
Added ability to assign multiple powertools to an item
Added option to list commands assigned powertools
-rw-r--r-- | Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java | 29 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java | 92 | ||||
-rw-r--r-- | Essentials/src/messages.properties | 9 | ||||
-rw-r--r-- | Essentials/src/messages_da.properties | 9 | ||||
-rw-r--r-- | Essentials/src/messages_de.properties | 9 | ||||
-rw-r--r-- | Essentials/src/messages_en.properties | 9 | ||||
-rw-r--r-- | Essentials/src/messages_fr.properties | 9 | ||||
-rw-r--r-- | Essentials/src/messages_nl.properties | 9 | ||||
-rw-r--r-- | Essentials/src/plugin.yml | 2 |
9 files changed, 149 insertions, 28 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index ff32a9636..1dbc72772 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -435,21 +435,26 @@ public class EssentialsPlayerListener extends PlayerListener { return; } - if (command.matches(".*\\{player\\}.*")) + + // We need to loop through each command and execute + for (String commandPtr : command.split("\\|")) { - //user.sendMessage("Click a player to use this command"); - return; - } - if (command.startsWith("c:")) - { - for (Player p : server.getOnlinePlayers()) + if (commandPtr.matches(".*\\{player\\}.*")) { - p.sendMessage(user.getDisplayName() + ":" + command.substring(2)); + //user.sendMessage("Click a player to use this command"); + continue; + } + else if (commandPtr.startsWith("c:")) + { + for (Player p : server.getOnlinePlayers()) + { + p.sendMessage(user.getDisplayName() + ":" + commandPtr.substring(2)); + } + } + else + { + user.getServer().dispatchCommand(user, commandPtr); } - } - else - { - user.getServer().dispatchCommand(user, command); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index c7bd34705..90f4803ca 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -17,23 +17,109 @@ public class Commandpowertool extends EssentialsCommand @Override protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { - ItemStack is = user.getItemInHand(); if (is == null || is.getType() == Material.AIR) { user.sendMessage(Util.i18n("powerToolAir")); return; } + + String itemName = is.getType().toString().toLowerCase().replaceAll("_", " "); String command = getFinalArg(args, 0); if (command != null && !command.isEmpty()) { - user.sendMessage(Util.format("powerToolAttach",is.getType().toString().toLowerCase().replaceAll("_", " "))); + if (command.equalsIgnoreCase("list")) + { + String powertools = user.getPowertool(is); + if (powertools == null) + { + user.sendMessage(Util.format("powerToolListEmpty", itemName)); + } + else + { + user.sendMessage(Util.format("powerToolList", powertools.replace("|", ", "), itemName)); + } + return; + } + if (command.startsWith("r:")) + { + try + { + String removedCommand = command.substring(2); + command = removePowerTool(user, removedCommand, is, itemName); + user.sendMessage(Util.format("powerToolRemove", removedCommand, itemName)); + } + catch (Exception e) + { + user.sendMessage(e.getMessage()); + return; + } + } + else + { + if (command.startsWith("a:")) + { + try + { + command = appendPowerTool(user, command, is, itemName); + } + catch (Exception e) + { + user.sendMessage(e.getMessage()); + return; + } + } + + user.sendMessage(Util.format("powerToolAttach", command.replace("|", ", "), itemName)); + } } else { - user.sendMessage(Util.format("powerToolRemove", is.getType().toString().toLowerCase().replaceAll("_", " "))); + user.sendMessage(Util.format("powerToolRemoveAll", itemName)); } + charge(user); user.setPowertool(is, command); } + + private String appendPowerTool(User user, String command, ItemStack is, String itemName) throws Exception + { + command = command.substring(2); // Ignore the first 2 chars + String powertools = user.getPowertool(is); + if (powertools != null) + { + if (powertools.contains(command)) + { + throw new Exception((Util.format("powerToolAlreadySet", command, itemName))); + } + + StringBuilder newCommand = new StringBuilder(); + command = newCommand.append(powertools).append("|").append(command).toString(); + } + + return command; + } + + private String removePowerTool(User user, String command, ItemStack is, String itemName) throws Exception + { + String powertools = user.getPowertool(is); + if (!powertools.contains(command)) + { + throw new Exception((Util.format("powerToolNoSuchCommandAssigned", command, itemName))); + } + + command = powertools.replace(command, "").replace("||", "|"); + + // Trim off any leading/trailing '|' chars + if (command.startsWith("|")) + { + command = command.substring(1); + } + if (command.endsWith("|")) + { + command = command.substring(0, command.length() - 1); + } + + return command; + } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 089d05670..fe4e63459 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -225,8 +225,13 @@ playerUnmuted = \u00a77You have been unmuted pong = Pong! possibleWorlds = \u00a77Possible worlds are the numbers 0 through {0}. powerToolAir = Command can''t be attached to air. -powerToolAttach = Command assigned to {0} -powerToolRemove = Command removed from {0} +powerToolAlreadySet = Command \u00a7c{0}\u00a7f is already assigned to {1}. +powerToolAttach = \u00a7c{0}\u00a7f command assigned to {1}. +powerToolList = {1} has the following commands: \u00a7c{0}\u00a7f. +powerToolListEmpty = {0} has no commands assigned. +powerToolNoSuchCommandAssigned = Command \u00a7c{0}\u00a7f has not been assigned to {1}. +powerToolRemove = Command \u00a7c{0}\u00a7f removed from {1}. +powerToolRemoveAll = All commands removed from {0}. protectionOwner = \u00a76[EssentialsProtect] Protection owner: {0} pTimeCurrent = \u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed = \u00a7e{0}''s\u00a7f time is fixed to {1}. diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index 41b34ab0e..cacc9a86b 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -225,8 +225,13 @@ playerUnmuted = \u00a77You have been unmuted pong = Pong! possibleWorlds = \u00a77Mulige verdener er numrene 0 igennem {0}. powerToolAir = Kommando kan ikke blive tildelt luft. -powerToolAttach = Kommando tildelt til {0} -powerToolRemove = Kommando fjernet fra {0} +powerToolAlreadySet = Command \u00a7c{0}\u00a7f is already assigned to {1}. +powerToolAttach = \u00a7c{0}\u00a7f command assigned to {1}. +powerToolList = {1} has the following commands: \u00a7c{0}\u00a7f. +powerToolListEmpty = {0} has no commands assigned. +powerToolNoSuchCommandAssigned = Command \u00a7c{0}\u00a7f has not been assigned to {1}. +powerToolRemove = Command \u00a7c{0}\u00a7f removed from {1}. +powerToolRemoveAll = All commands removed from {0}. protectionOwner = \u00a76[EssentialsProtect] Beskyttelses ejer: {0} pTimeCurrent = \u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed = \u00a7e{0}''s\u00a7f time is fixed to {1}. diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index d85cd4350..a4bcea0b2 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -225,8 +225,13 @@ playerUnmuted = \u00a77Du bist nicht mehr stumm. pong = Pong! possibleWorlds = \u00a77M\u00f6gliche Welten sind nummeriet von 0 bis {0}. powerToolAir = Befehl kann nicht mit Luft verbunden werden. -powerToolAttach = Befehl verbunden mit {0} -powerToolRemove = Befehl entfernt von {0} +powerToolAlreadySet = Command \u00a7c{0}\u00a7f is already assigned to {1}. +powerToolAttach = \u00a7c{0}\u00a7f command assigned to {1}. +powerToolList = {1} has the following commands: \u00a7c{0}\u00a7f. +powerToolListEmpty = {0} has no commands assigned. +powerToolNoSuchCommandAssigned = Command \u00a7c{0}\u00a7f has not been assigned to {1}. +powerToolRemove = Command \u00a7c{0}\u00a7f removed from {1}. +powerToolRemoveAll = All commands removed from {0}. protectionOwner = \u00a76[EssentialsProtect] Besitzer dieses Blocks: {0} pTimeCurrent = \u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed = \u00a7e{0}''s\u00a7f time is fixed to {1}. diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 4c1ad26d4..0c30aec96 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -225,8 +225,13 @@ playerUnmuted = \u00a77You have been unmuted pong = Pong! possibleWorlds = \u00a77Possible worlds are the numbers 0 through {0}. powerToolAir = Command can''t be attached to air. -powerToolAttach = Command assigned to {0} -powerToolRemove = Command removed from {0} +powerToolAlreadySet = Command \u00a7c{0}\u00a7f is already assigned to {1}. +powerToolAttach = \u00a7c{0}\u00a7f command assigned to {1}. +powerToolList = {1} has the following commands: \u00a7c{0}\u00a7f. +powerToolListEmpty = {0} has no commands assigned. +powerToolNoSuchCommandAssigned = Command \u00a7c{0}\u00a7f has not been assigned to {1}. +powerToolRemove = Command \u00a7c{0}\u00a7f removed from {1}. +powerToolRemoveAll = All commands removed from {0}. protectionOwner = \u00a76[EssentialsProtect] Protection owner: {0} pTimeCurrent = \u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed = \u00a7e{0}''s\u00a7f time is fixed to {1}. diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 0849c78d6..1abae6fbc 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -225,8 +225,13 @@ playerUnmuted = \u00a77You have been unmuted pong = Pong! possibleWorlds = \u00a77Les mondes possibles sont les nombres 0 par {0}. powerToolAir = La commande ne peut pas \u00eatre attach\u00e9e \u00e0 l''air. -powerToolAttach = Commande assign\u00e9e \u00e0 {0} -powerToolRemove = Commande enlev\u00e9e \u00e0 {0} +powerToolAlreadySet = Command \u00a7c{0}\u00a7f is already assigned to {1}. +powerToolAttach = \u00a7c{0}\u00a7f command assigned to {1}. +powerToolList = {1} has the following commands: \u00a7c{0}\u00a7f. +powerToolListEmpty = {0} has no commands assigned. +powerToolNoSuchCommandAssigned = Command \u00a7c{0}\u00a7f has not been assigned to {1}. +powerToolRemove = Command \u00a7c{0}\u00a7f removed from {1}. +powerToolRemoveAll = All commands removed from {0}. protectionOwner = \u00a76[EssentialsProtect] Propri\u00e9taire de la protection : {0} pTimeCurrent = \u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed = \u00a7e{0}''s\u00a7f time is fixed to {1}. diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index a76084a55..dc41e499b 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -225,8 +225,13 @@ playerUnmuted = \u00a77Speler mag weer praten pong = Pong! possibleWorlds = \u00a77Mogelijk zijn de werelden de nummer 0 tot en met {0}. powerToolAir = Command kan niet worden bevestigd aan lucht. -powerToolAttach = Command toegewezen aan {0} -powerToolRemove = Command verwijderd van {0} +powerToolAlreadySet = Command \u00a7c{0}\u00a7f is already assigned to {1}. +powerToolAttach = \u00a7c{0}\u00a7f command assigned to {1}. +powerToolList = {1} has the following commands: \u00a7c{0}\u00a7f. +powerToolListEmpty = {0} has no commands assigned. +powerToolNoSuchCommandAssigned = Command \u00a7c{0}\u00a7f has not been assigned to {1}. +powerToolRemove = Command \u00a7c{0}\u00a7f removed from {1}. +powerToolRemoveAll = All commands removed from {0}. protectionOwner = \u00a76[EssentialsProtect] Beschermingeigenaar: {0} pTimeCurrent = \u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed = \u00a7e{0}''s\u00a7f time is fixed to {1}. diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 1acef22e8..031accc27 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -204,7 +204,7 @@ commands: aliases: [pong,eping,epong] powertool: description: Assigns a command to the item in hand, {player} will be replaced by the name of the player that you click. - usage: /<command> [command] <arguments> + usage: /<command> [a:r:][command] <arguments> aliases: [pt,epowertool,ept] ptime: description: Adjust player's client time. Add @ prefix to fix. |