summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java33
-rw-r--r--Essentials/src/com/earth2me/essentials/UserData.java32
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java92
-rw-r--r--Essentials/src/messages.properties9
-rw-r--r--Essentials/src/messages_da.properties9
-rw-r--r--Essentials/src/messages_de.properties9
-rw-r--r--Essentials/src/messages_en.properties9
-rw-r--r--Essentials/src/messages_fr.properties9
-rw-r--r--Essentials/src/messages_nl.properties9
-rw-r--r--Essentials/src/plugin.yml2
10 files changed, 177 insertions, 36 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index ff32a9636..7552e96db 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> commands = user.getPowertool(is);
+ if (commands == null || commands.isEmpty())
{
return;
}
- if (command.matches(".*\\{player\\}.*"))
+
+ // We need to loop through each command and execute
+ for (String commandPtr : commands)
{
- //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/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java
index 896339642..7cad0de93 100644
--- a/Essentials/src/com/earth2me/essentials/UserData.java
+++ b/Essentials/src/com/earth2me/essentials/UserData.java
@@ -173,26 +173,46 @@ 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;
+ for(Map.Entry<Integer, Object> entry : ((Map<Integer, Object>)o).entrySet())
+ {
+ if(entry.getValue() instanceof String)
+ {
+ List<String> temp = new ArrayList<String>();
+ temp.add((String)entry.getValue());
+ ((Map<Integer, Object>)o).put(entry.getKey(), temp);
+ }
+ }
+
+ 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 (List<String>)powertools.get(stack.getTypeId());
+ }
+
+ public List<String> getPowertoolList(ItemStack stack)
{
- return powertools.get(stack.getTypeId());
+ Map<String, Object> tools = (Map<String, Object>)config.getProperty("powertools");
+ List<String> commands;
+
+ commands = (List<String>)tools.get(stack.getTypeId());
+ return commands;
}
public void setPowertool(ItemStack stack, String command)
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java
index c7bd34705..3f56772f4 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"))
+ {
+ List<String> powertools = user.getPowertool(is);
+ if (powertools == null || powertools.empty())
+ {
+ 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 964060099..29ea5f50e 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 a94a04a33..c73371f89 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 1360bc3cc..58cf40708 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 0673d41ed..c226901fb 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 ea5af2d44..51cc63509 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 3dbb00a74..7e5b6e31f 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..d8a772a3a 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.