added config upgrade for powertools

This commit is contained in:
okamosy 2011-08-21 19:02:01 +01:00
parent ac20207ea1
commit 812a357361
5 changed files with 79 additions and 27 deletions

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import java.util.List;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -35,12 +36,15 @@ public class EssentialsEntityListener extends EntityListener
User defender = ess.getUser(eDefend); User defender = ess.getUser(eDefend);
User attacker = ess.getUser(eAttack); User attacker = ess.getUser(eAttack);
ItemStack is = attacker.getItemInHand(); ItemStack is = attacker.getItemInHand();
String command = attacker.getPowertool(is); List<String> commandList = attacker.getPowertool(is);
if (command != null && !command.isEmpty()) for(String command : commandList)
{ {
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName())); if (command != null && !command.isEmpty())
event.setCancelled(true); {
return; attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
event.setCancelled(true);
return;
}
} }
} }
} }

View File

@ -430,30 +430,30 @@ public class EssentialsPlayerListener extends PlayerListener
{ {
return; return;
} }
final List<String> commands = user.getPowertool(is); final List<String> commandList = user.getPowertool(is);
if (commands == null || commands.isEmpty()) if (commandList == null || commandList.isEmpty())
{ {
return; return;
} }
// We need to loop through each command and execute // 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"); //user.sendMessage("Click a player to use this command");
continue; continue;
} }
else if (commandPtr.startsWith("c:")) else if (command.startsWith("c:"))
{ {
for (Player p : server.getOnlinePlayers()) for (Player p : server.getOnlinePlayers())
{ {
p.sendMessage(user.getDisplayName() + ":" + commandPtr.substring(2)); p.sendMessage(user.getDisplayName() + ":" + command.substring(2));
} }
} }
else else
{ {
user.getServer().dispatchCommand(user, commandPtr); user.getServer().dispatchCommand(user, command);
} }
} }
} }

View File

@ -5,7 +5,9 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Location; import org.bukkit.Location;
@ -197,6 +199,59 @@ public class EssentialsUpgrade
doneFile.save(); 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() private void moveUsersDataToUserdataFolder()
{ {
final File usersFile = new File(ess.getDataFolder(), "users.yml"); final File usersFile = new File(ess.getDataFolder(), "users.yml");
@ -457,5 +512,6 @@ public class EssentialsUpgrade
updateUsersToNewDefaultHome(); updateUsersToNewDefaultHome();
moveUsersDataToUserdataFolder(); moveUsersDataToUserdataFolder();
convertWarps(); convertWarps();
updateUsersPowerToolsFormat();
} }
} }

View File

@ -182,16 +182,6 @@ public abstract class UserData extends PlayerExtension implements IConf
if (o instanceof Map) 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; return (Map<Integer, Object>)o;
} }
else else

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -31,13 +32,13 @@ public class Commandpowertool extends EssentialsCommand
if (command.equalsIgnoreCase("list")) if (command.equalsIgnoreCase("list"))
{ {
List<String> powertools = user.getPowertool(is); List<String> powertools = user.getPowertool(is);
if (powertools == null || powertools.empty()) if (powertools == null || powertools.isEmpty())
{ {
user.sendMessage(Util.format("powerToolListEmpty", itemName)); user.sendMessage(Util.format("powerToolListEmpty", itemName));
} }
else else
{ {
user.sendMessage(Util.format("powerToolList", powertools.replace("|", ", "), itemName)); user.sendMessage(Util.format("powerToolList", powertools.toString(), itemName));
} }
return; return;
} }
@ -85,7 +86,7 @@ public class Commandpowertool extends EssentialsCommand
private String appendPowerTool(User user, String command, ItemStack is, String itemName) throws Exception private String appendPowerTool(User user, String command, ItemStack is, String itemName) throws Exception
{ {
command = command.substring(2); // Ignore the first 2 chars command = command.substring(2); // Ignore the first 2 chars
String powertools = user.getPowertool(is); /*String powertools = user.getPowertool(is);
if (powertools != null) if (powertools != null)
{ {
if (powertools.contains(command)) if (powertools.contains(command))
@ -96,12 +97,13 @@ public class Commandpowertool extends EssentialsCommand
StringBuilder newCommand = new StringBuilder(); StringBuilder newCommand = new StringBuilder();
command = newCommand.append(powertools).append("|").append(command).toString(); command = newCommand.append(powertools).append("|").append(command).toString();
} }
*/
return command; return command;
} }
private String removePowerTool(User user, String command, ItemStack is, String itemName) throws Exception private String removePowerTool(User user, String command, ItemStack is, String itemName) throws Exception
{ {
/*
String powertools = user.getPowertool(is); String powertools = user.getPowertool(is);
if (!powertools.contains(command)) if (!powertools.contains(command))
{ {
@ -119,7 +121,7 @@ public class Commandpowertool extends EssentialsCommand
{ {
command = command.substring(0, command.length() - 1); command = command.substring(0, command.length() - 1);
} }
*/
return command; return command;
} }
} }