summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokamosy <okamosy@gmail.com>2011-08-21 19:02:01 +0100
committerokamosy <okamosy@gmail.com>2011-08-21 19:02:01 +0100
commit812a3573619047a368ad55932f3af18607d0be08 (patch)
tree5c6e48267187529b77b67688b64a5212e73fdc55
parentac20207ea188a50bc8a0fdf863fd7aa444745ed9 (diff)
downloadEssentials-812a3573619047a368ad55932f3af18607d0be08.tar
Essentials-812a3573619047a368ad55932f3af18607d0be08.tar.gz
Essentials-812a3573619047a368ad55932f3af18607d0be08.tar.lz
Essentials-812a3573619047a368ad55932f3af18607d0be08.tar.xz
Essentials-812a3573619047a368ad55932f3af18607d0be08.zip
added config upgrade for powertools
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java14
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java14
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java56
-rw-r--r--Essentials/src/com/earth2me/essentials/UserData.java10
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java12
5 files changed, 79 insertions, 27 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
index 0d4759c64..3e53e3eea 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
@@ -1,5 +1,6 @@
package com.earth2me.essentials;
+import java.util.List;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -35,12 +36,15 @@ public class EssentialsEntityListener extends EntityListener
User defender = ess.getUser(eDefend);
User attacker = ess.getUser(eAttack);
ItemStack is = attacker.getItemInHand();
- String command = attacker.getPowertool(is);
- if (command != null && !command.isEmpty())
+ List<String> commandList = attacker.getPowertool(is);
+ for(String command : commandList)
{
- attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
- event.setCancelled(true);
- return;
+ if (command != null && !command.isEmpty())
+ {
+ attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
+ event.setCancelled(true);
+ return;
+ }
}
}
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index 7552e96db..5830c5875 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -430,30 +430,30 @@ public class EssentialsPlayerListener extends PlayerListener
{
return;
}
- final List<String> commands = user.getPowertool(is);
- if (commands == null || commands.isEmpty())
+ final List<String> commandList = user.getPowertool(is);
+ if (commandList == null || commandList.isEmpty())
{
return;
}
// We need to loop through each command and execute
- for (String commandPtr : commands)
+ for (String command : commandList)
{
- if (commandPtr.matches(".*\\{player\\}.*"))
+ if (command.matches(".*\\{player\\}.*"))
{
//user.sendMessage("Click a player to use this command");
continue;
}
- else if (commandPtr.startsWith("c:"))
+ else if (command.startsWith("c:"))
{
for (Player p : server.getOnlinePlayers())
{
- p.sendMessage(user.getDisplayName() + ":" + commandPtr.substring(2));
+ p.sendMessage(user.getDisplayName() + ":" + command.substring(2));
}
}
else
{
- user.getServer().dispatchCommand(user, commandPtr);
+ user.getServer().dispatchCommand(user, command);
}
}
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
index c6c7effd8..2ebc73c75 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
@@ -5,7 +5,9 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Location;
@@ -197,6 +199,59 @@ public class EssentialsUpgrade
doneFile.save();
}
+ private void updateUsersPowerToolsFormat()
+ {
+ if (doneFile.getBoolean("updateUsersPowerToolsFormat", false))
+ {
+ return;
+ }
+ final File userdataFolder = new File(ess.getDataFolder(), "userdata");
+ if (!userdataFolder.exists() || !userdataFolder.isDirectory())
+ {
+ return;
+ }
+ final File[] userFiles = userdataFolder.listFiles();
+
+ for (File file : userFiles)
+ {
+ if (!file.isFile() || !file.getName().endsWith(".yml"))
+ {
+ continue;
+ }
+ final EssentialsConf config = new EssentialsConf(file);
+ try
+ {
+ config.load();
+ if (config.hasProperty("powertools"))
+ {
+ @SuppressWarnings("unchecked")
+ final Map<Integer, Object> powertools = (Map<Integer, Object>)config.getProperty("powertools");
+ if (powertools == null)
+ {
+ continue;
+ }
+ for (Map.Entry<Integer, Object> entry : powertools.entrySet())
+ {
+ if (entry.getValue() instanceof String)
+ {
+ List<String> temp = new ArrayList<String>();
+ temp.add((String)entry.getValue());
+ ((Map<Integer, Object>)powertools).put(entry.getKey(), temp);
+ }
+ }
+ config.save();
+ }
+ }
+ catch (RuntimeException ex)
+ {
+ LOGGER.log(Level.INFO, "File: " + file.toString());
+ throw ex;
+ }
+ }
+ doneFile.setProperty("updateUsersPowerToolsFormat", true);
+ doneFile.save();
+ }
+
private void moveUsersDataToUserdataFolder()
{
final File usersFile = new File(ess.getDataFolder(), "users.yml");
@@ -457,5 +512,6 @@ public class EssentialsUpgrade
updateUsersToNewDefaultHome();
moveUsersDataToUserdataFolder();
convertWarps();
+ updateUsersPowerToolsFormat();
}
}
diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java
index 7cad0de93..c90afb6d8 100644
--- a/Essentials/src/com/earth2me/essentials/UserData.java
+++ b/Essentials/src/com/earth2me/essentials/UserData.java
@@ -182,16 +182,6 @@ public abstract class UserData extends PlayerExtension implements IConf
if (o instanceof Map)
{
- 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
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java
index 3f56772f4..a96c78db4 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.List;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
@@ -31,13 +32,13 @@ public class Commandpowertool extends EssentialsCommand
if (command.equalsIgnoreCase("list"))
{
List<String> powertools = user.getPowertool(is);
- if (powertools == null || powertools.empty())
+ if (powertools == null || powertools.isEmpty())
{
user.sendMessage(Util.format("powerToolListEmpty", itemName));
}
else
{
- user.sendMessage(Util.format("powerToolList", powertools.replace("|", ", "), itemName));
+ user.sendMessage(Util.format("powerToolList", powertools.toString(), itemName));
}
return;
}
@@ -85,7 +86,7 @@ public class Commandpowertool extends EssentialsCommand
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);
+ /*String powertools = user.getPowertool(is);
if (powertools != null)
{
if (powertools.contains(command))
@@ -96,12 +97,13 @@ public class Commandpowertool extends EssentialsCommand
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))
{
@@ -119,7 +121,7 @@ public class Commandpowertool extends EssentialsCommand
{
command = command.substring(0, command.length() - 1);
}
-
+*/
return command;
}
}