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;
}
final String command = user.getPowertool(is);
if (command == null || command.isEmpty())
final List<String> commands = user.getPowertool(is);
if (commands == null || commands.isEmpty())
{
return;
}
// We need to loop through each command and execute
for (String commandPtr : command.split("\\|"))
for (String commandPtr : commands)
{
if (commandPtr.matches(".*\\{player\\}.*"))
{

View file

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

View file

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

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> [a:r:][command] <arguments>
usage: /<command> [list|a:|r:][command] <arguments>
aliases: [pt,epowertool,ept]
ptime:
description: Adjust player's client time. Add @ prefix to fix.