diff options
-rw-r--r-- | Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java | 14 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java | 33 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java | 56 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/UserData.java | 19 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java | 68 | ||||
-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 |
12 files changed, 201 insertions, 45 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java index 0d4759c64..3e53e3eea 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import java.util.List; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -35,12 +36,15 @@ public class EssentialsEntityListener extends EntityListener User defender = ess.getUser(eDefend); User attacker = ess.getUser(eAttack); ItemStack is = attacker.getItemInHand(); - String command = attacker.getPowertool(is); - if (command != null && !command.isEmpty()) + List<String> commandList = attacker.getPowertool(is); + for(String command : commandList) { - attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName())); - event.setCancelled(true); - return; + if (command != null && !command.isEmpty()) + { + attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName())); + event.setCancelled(true); + return; + } } } } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index ff32a9636..5830c5875 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -430,26 +430,31 @@ public class EssentialsPlayerListener extends PlayerListener { return; } - final String command = user.getPowertool(is); - if (command == null || command.isEmpty()) + final List<String> commandList = user.getPowertool(is); + if (commandList == null || commandList.isEmpty()) { return; } - if (command.matches(".*\\{player\\}.*")) + + // We need to loop through each command and execute + for (String command : commandList) { - //user.sendMessage("Click a player to use this command"); - return; - } - if (command.startsWith("c:")) - { - for (Player p : server.getOnlinePlayers()) + if (command.matches(".*\\{player\\}.*")) { - p.sendMessage(user.getDisplayName() + ":" + command.substring(2)); + //user.sendMessage("Click a player to use this command"); + continue; + } + else if (command.startsWith("c:")) + { + for (Player p : server.getOnlinePlayers()) + { + p.sendMessage(user.getDisplayName() + ":" + command.substring(2)); + } + } + else + { + user.getServer().dispatchCommand(user, command); } - } - else - { - user.getServer().dispatchCommand(user, command); } } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index c6c7effd8..2ebc73c75 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -5,7 +5,9 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Location; @@ -197,6 +199,59 @@ public class EssentialsUpgrade doneFile.save(); } + private void updateUsersPowerToolsFormat() + { + if (doneFile.getBoolean("updateUsersPowerToolsFormat", false)) + { + return; + } + final File userdataFolder = new File(ess.getDataFolder(), "userdata"); + if (!userdataFolder.exists() || !userdataFolder.isDirectory()) + { + return; + } + final File[] userFiles = userdataFolder.listFiles(); + + for (File file : userFiles) + { + if (!file.isFile() || !file.getName().endsWith(".yml")) + { + continue; + } + final EssentialsConf config = new EssentialsConf(file); + try + { + config.load(); + if (config.hasProperty("powertools")) + { + @SuppressWarnings("unchecked") + final Map<Integer, Object> powertools = (Map<Integer, Object>)config.getProperty("powertools"); + if (powertools == null) + { + continue; + } + for (Map.Entry<Integer, Object> entry : powertools.entrySet()) + { + if (entry.getValue() instanceof String) + { + List<String> temp = new ArrayList<String>(); + temp.add((String)entry.getValue()); + ((Map<Integer, Object>)powertools).put(entry.getKey(), temp); + } + } + config.save(); + } + } + catch (RuntimeException ex) + { + LOGGER.log(Level.INFO, "File: " + file.toString()); + throw ex; + } + } + doneFile.setProperty("updateUsersPowerToolsFormat", true); + doneFile.save(); + } + private void moveUsersDataToUserdataFolder() { final File usersFile = new File(ess.getDataFolder(), "users.yml"); @@ -457,5 +512,6 @@ public class EssentialsUpgrade updateUsersToNewDefaultHome(); moveUsersDataToUserdataFolder(); convertWarps(); + updateUsersPowerToolsFormat(); } } diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 896339642..b72f105ee 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -173,37 +173,38 @@ public abstract class UserData extends PlayerExtension implements IConf config.setProperty("unlimited", unlimited); config.save(); } - private Map<Integer, String> powertools; + private Map<Integer, Object> powertools; @SuppressWarnings("unchecked") - private Map<Integer, String> getPowertools() + private Map<Integer, Object> getPowertools() { Object o = config.getProperty("powertools"); + if (o instanceof Map) { - return (Map<Integer, String>)o; + return (Map<Integer, Object>)o; } else { - return new HashMap<Integer, String>(); + return new HashMap<Integer, Object>(); } } - public String getPowertool(ItemStack stack) + public List<String> getPowertool(ItemStack stack) { - return powertools.get(stack.getTypeId()); + return (List<String>)powertools.get(stack.getTypeId()); } - public void setPowertool(ItemStack stack, String command) + public void setPowertool(ItemStack stack, List<String> commandList) { - if (command == null || command.isEmpty()) + if (commandList == null || commandList.isEmpty()) { powertools.remove(stack.getTypeId()); } else { - powertools.put(stack.getTypeId(), command); + powertools.put(stack.getTypeId(), commandList); } config.setProperty("powertools", powertools); config.save(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index c7bd34705..bc1ccd801 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -2,6 +2,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; +import java.util.ArrayList; +import java.util.List; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; @@ -17,23 +19,81 @@ public class Commandpowertool extends EssentialsCommand @Override protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { - ItemStack is = user.getItemInHand(); + List<String> powertools = user.getPowertool(is); 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")) + { + if (powertools == null || powertools.isEmpty()) + { + user.sendMessage(Util.format("powerToolListEmpty", itemName)); + } + else + { + user.sendMessage(Util.format("powerToolList", powertools.toString(), itemName)); + } + return; + } + if (command.startsWith("r:")) + { + try + { + command = command.substring(2); + if (!powertools.contains(command)) + { + user.sendMessage(Util.format("powerToolNoSuchCommandAssigned", command, itemName)); + return; + } + + powertools.remove(command); + user.sendMessage(Util.format("powerToolRemove", command, itemName)); + } + catch (Exception e) + { + user.sendMessage(e.getMessage()); + return; + } + } + else + { + if (command.startsWith("a:")) + { + command = command.substring(2); + if(powertools.contains(command)) + { + user.sendMessage(Util.format("powerToolAlreadySet", command, itemName)); + return; + } + } + else if (powertools != null && !powertools.isEmpty()) + { + // Replace all commands with this one + powertools.clear(); + } + else + { + powertools = new ArrayList<String>(); + } + + powertools.add(command); + user.sendMessage(Util.format("powerToolAttach", powertools.toString(), itemName)); + } } else { - user.sendMessage(Util.format("powerToolRemove", is.getType().toString().toLowerCase().replaceAll("_", " "))); + user.sendMessage(Util.format("powerToolRemoveAll", itemName)); } + charge(user); - user.setPowertool(is, command); + user.setPowertool(is, powertools); } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 3a9dd2d23..93bea8f26 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 870f24c5a..eb34951ea 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 31c9c3eb2..cd6888c26 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 057d06869..a2a7bf32b 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 da166c8d9..de388e2ad 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 173698b1f..c9d3d7f4b 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 2406c337d..5d180763f 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> [list|a:|r:][command] <arguments> aliases: [pt,epowertool,ept] ptime: description: Adjust player's client time. Add @ prefix to fix. |