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
commite10675dfdc6ca17c42ebd63af107a8974506ead1 (patch)
tree4901a4fd6069488d1d45a6938e371ebdd2e23928
parent812a3573619047a368ad55932f3af18607d0be08 (diff)
downloadEssentials-e10675dfdc6ca17c42ebd63af107a8974506ead1.tar
Essentials-e10675dfdc6ca17c42ebd63af107a8974506ead1.tar.gz
Essentials-e10675dfdc6ca17c42ebd63af107a8974506ead1.tar.lz
Essentials-e10675dfdc6ca17c42ebd63af107a8974506ead1.tar.xz
Essentials-e10675dfdc6ca17c42ebd63af107a8974506ead1.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