summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokamosy <okamosy@gmail.com>2011-08-21 19:33:37 +0100
committerokamosy <okamosy@gmail.com>2011-08-21 19:33:37 +0100
commit9127025ec3c8ee8e6b2a764eb01f1fb7c776a6a6 (patch)
treeedc89d536b76029bdacca7255cb74b8c33c3f751
parentf63dbe6454808d02b4208998e0eb13b91687a9fb (diff)
downloadEssentials-9127025ec3c8ee8e6b2a764eb01f1fb7c776a6a6.tar
Essentials-9127025ec3c8ee8e6b2a764eb01f1fb7c776a6a6.tar.gz
Essentials-9127025ec3c8ee8e6b2a764eb01f1fb7c776a6a6.tar.lz
Essentials-9127025ec3c8ee8e6b2a764eb01f1fb7c776a6a6.tar.xz
Essentials-9127025ec3c8ee8e6b2a764eb01f1fb7c776a6a6.zip
Completed changing powertool config from tokenized string to lists
-rw-r--r--Essentials/src/com/earth2me/essentials/UserData.java15
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java38
2 files changed, 29 insertions, 24 deletions
diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java
index c90afb6d8..b72f105ee 100644
--- a/Essentials/src/com/earth2me/essentials/UserData.java
+++ b/Essentials/src/com/earth2me/essentials/UserData.java
@@ -196,24 +196,15 @@ public abstract class UserData extends PlayerExtension implements IConf
return (List<String>)powertools.get(stack.getTypeId());
}
- public List<String> getPowertoolList(ItemStack stack)
+ public void setPowertool(ItemStack stack, List<String> commandList)
{
- 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)
- {
- if (command == null || command.isEmpty())
+ if (commandList == null || commandList.isEmpty())
{
powertools.remove(stack.getTypeId());
}
else
{
- powertools.put(stack.getTypeId(), command);
+ powertools.put(stack.getTypeId(), commandList);
}
config.setProperty("powertools", powertools);
config.save();
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java
index a96c78db4..c1450046a 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java
@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
+import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.Server;
@@ -19,6 +20,7 @@ public class Commandpowertool extends EssentialsCommand
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
ItemStack is = user.getItemInHand();
+ List<String> powertools = user.getPowertool(is);
if (is == null || is.getType() == Material.AIR)
{
user.sendMessage(Util.i18n("powerToolAir"));
@@ -31,7 +33,6 @@ public class Commandpowertool extends EssentialsCommand
{
if (command.equalsIgnoreCase("list"))
{
- List<String> powertools = user.getPowertool(is);
if (powertools == null || powertools.isEmpty())
{
user.sendMessage(Util.format("powerToolListEmpty", itemName));
@@ -46,9 +47,15 @@ public class Commandpowertool extends EssentialsCommand
{
try
{
- String removedCommand = command.substring(2);
- command = removePowerTool(user, removedCommand, is, itemName);
- user.sendMessage(Util.format("powerToolRemove", removedCommand, itemName));
+ command = command.substring(2);
+ if (!powertools.contains(command))
+ {
+ user.sendMessage(Util.format("powerToolNoSuchCommandAssigned", command, itemName));
+ return;
+ }
+
+ powertools.remove(command);
+ user.sendMessage(Util.format("powerToolRemove", command, itemName));
}
catch (Exception e)
{
@@ -60,18 +67,25 @@ public class Commandpowertool extends EssentialsCommand
{
if (command.startsWith("a:"))
{
- try
- {
- command = appendPowerTool(user, command, is, itemName);
- }
- catch (Exception e)
+ command = command.substring(2);
+ if(powertools.contains(command))
{
- user.sendMessage(e.getMessage());
+ user.sendMessage(Util.format("powerToolAlreadySet", command, itemName));
return;
}
}
+ else if (powertools != null && !powertools.isEmpty())
+ {
+ // Replace all commands with this one
+ powertools.clear();
+ }
+ else
+ {
+ powertools = new ArrayList<String>();
+ }
- user.sendMessage(Util.format("powerToolAttach", command.replace("|", ", "), itemName));
+ powertools.add(command);
+ user.sendMessage(Util.format("powerToolAttach", powertools.toString(), itemName));
}
}
else
@@ -80,7 +94,7 @@ public class Commandpowertool extends EssentialsCommand
}
charge(user);
- user.setPowertool(is, command);
+ user.setPowertool(is, powertools);
}
private String appendPowerTool(User user, String command, ItemStack is, String itemName) throws Exception