converted powertool config to use lists instead of tokenized strings

Powertool update
This commit is contained in:
okamosy 2011-08-21 17:52:58 +01:00
parent 6f88e7bb98
commit 43d7fb367b
4 changed files with 32 additions and 12 deletions

View file

@ -430,14 +430,14 @@ public class EssentialsPlayerListener extends PlayerListener
{ {
return; return;
} }
final String command = user.getPowertool(is); final List<String> commands = user.getPowertool(is);
if (command == null || command.isEmpty()) if (commands == null || commands.isEmpty())
{ {
return; return;
} }
// We need to loop through each command and execute // We need to loop through each command and execute
for (String commandPtr : command.split("\\|")) for (String commandPtr : commands)
{ {
if (commandPtr.matches(".*\\{player\\}.*")) if (commandPtr.matches(".*\\{player\\}.*"))
{ {

View file

@ -173,26 +173,46 @@ public abstract class UserData extends PlayerExtension implements IConf
config.setProperty("unlimited", unlimited); config.setProperty("unlimited", unlimited);
config.save(); config.save();
} }
private Map<Integer, String> powertools; private Map<Integer, Object> powertools;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Map<Integer, String> getPowertools() private Map<Integer, Object> getPowertools()
{ {
Object o = config.getProperty("powertools"); Object o = config.getProperty("powertools");
if (o instanceof Map) 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 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 List<String> getPowertoolList(ItemStack stack)
{
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) public void setPowertool(ItemStack stack, String command)

View file

@ -30,8 +30,8 @@ public class Commandpowertool extends EssentialsCommand
{ {
if (command.equalsIgnoreCase("list")) if (command.equalsIgnoreCase("list"))
{ {
String powertools = user.getPowertool(is); List<String> powertools = user.getPowertool(is);
if (powertools == null) if (powertools == null || powertools.empty())
{ {
user.sendMessage(Util.format("powerToolListEmpty", itemName)); user.sendMessage(Util.format("powerToolListEmpty", itemName));
} }

View file

@ -204,7 +204,7 @@ commands:
aliases: [pong,eping,epong] aliases: [pong,eping,epong]
powertool: powertool:
description: Assigns a command to the item in hand, {player} will be replaced by the name of the player that you click. description: Assigns a command to the item in hand, {player} will be replaced by the name of the player that you click.
usage: /<command> [a:r:][command] <arguments> usage: /<command> [list|a:|r:][command] <arguments>
aliases: [pt,epowertool,ept] aliases: [pt,epowertool,ept]
ptime: ptime:
description: Adjust player's client time. Add @ prefix to fix. description: Adjust player's client time. Add @ prefix to fix.