summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokamosy <okamosy@gmail.com>2011-08-21 02:50:48 +0100
committerokamosy <okamosy@gmail.com>2011-08-21 02:50:48 +0100
commit8be8e2350969fc6d86743880f45e1c24ba78f46c (patch)
tree339ff84894165118302d762229659d7fbcf93521
parent5e2eecd55089ec8bbb4eeda8354566d0fb665504 (diff)
downloadEssentials-8be8e2350969fc6d86743880f45e1c24ba78f46c.tar
Essentials-8be8e2350969fc6d86743880f45e1c24ba78f46c.tar.gz
Essentials-8be8e2350969fc6d86743880f45e1c24ba78f46c.tar.lz
Essentials-8be8e2350969fc6d86743880f45e1c24ba78f46c.tar.xz
Essentials-8be8e2350969fc6d86743880f45e1c24ba78f46c.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.java29
-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
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.