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;
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;
}
}
}
}

View File

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

View File

@ -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();
}
}

View File

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

View File

@ -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;
}
}