Added ability to assign multiple powertools to an item

Added option to list commands assigned powertools
This commit is contained in:
okamosy 2011-08-21 02:50:48 +01:00
parent d14f278ecf
commit 45f88016fc
9 changed files with 149 additions and 28 deletions

View File

@ -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("\\|"))
{
if (commandPtr.matches(".*\\{player\\}.*"))
{
//user.sendMessage("Click a player to use this command");
return;
continue;
}
if (command.startsWith("c:"))
else if (commandPtr.startsWith("c:"))
{
for (Player p : server.getOnlinePlayers())
{
p.sendMessage(user.getDisplayName() + ":" + command.substring(2));
p.sendMessage(user.getDisplayName() + ":" + commandPtr.substring(2));
}
}
else
{
user.getServer().dispatchCommand(user, command);
user.getServer().dispatchCommand(user, commandPtr);
}
}
}

View File

@ -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("powerToolRemove", is.getType().toString().toLowerCase().replaceAll("_", " ")));
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("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;
}
}

View File

@ -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}.

View File

@ -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}.

View File

@ -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}.

View File

@ -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}.

View File

@ -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}.

View File

@ -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}.

View File

@ -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.