diff options
-rw-r--r-- | Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java | 84 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/IUser.java | 4 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Teleport.java | 18 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/User.java | 1 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/UserData.java | 20 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandhome.java | 57 | ||||
-rw-r--r-- | Essentials/src/messages.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_da.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_de.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_en.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_fr.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_nl.properties | 2 |
12 files changed, 130 insertions, 66 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index 25bf6291d..c5d590e14 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -252,6 +252,78 @@ public class EssentialsUpgrade doneFile.save(); } + private void updateUsersHomesFormat() + { + if (doneFile.getBoolean("updateUsersHomesFormat", 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("home") && config.hasProperty("home.default")) + { + @SuppressWarnings("unchecked") + final String defworld = (String)config.getProperty("home.default"); + final Location defloc = config.getLocation("home.worlds." + defworld, ess.getServer()); + + String worldName = defloc.getWorld().getName().toLowerCase(); + config.setProperty("homes.home", defloc); + + List<String> worlds = config.getKeys("home.worlds"); + Location loc; + + if (worlds == null) + { + continue; + } + for (String world : worlds) + { + if (defworld.equalsIgnoreCase(world)) + { + continue; + } + loc = config.getLocation("home.worlds." + world, ess.getServer()); + if (loc == null) + { + continue; + } + worldName = loc.getWorld().getName().toLowerCase(); + if (worldName != null && !worldName.isEmpty()) + { + config.setProperty("homes." + worldName, loc); + } + } + config.removeProperty("home"); + config.save(); + } + + } + catch (RuntimeException ex) + { + LOGGER.log(Level.INFO, "File: " + file.toString()); + throw ex; + } + } + doneFile.setProperty("updateUsersHomesFormat", true); + doneFile.save(); + } + private void moveUsersDataToUserdataFolder() { final File usersFile = new File(ess.getDataFolder(), "users.yml"); @@ -288,11 +360,11 @@ public class EssentialsUpgrade if (world != null) { user.setHome("home", new Location(world, - ((Number)vals.get(0)).doubleValue(), - ((Number)vals.get(1)).doubleValue(), - ((Number)vals.get(2)).doubleValue(), - ((Number)vals.get(3)).floatValue(), - ((Number)vals.get(4)).floatValue())); + ((Number)vals.get(0)).doubleValue(), + ((Number)vals.get(1)).doubleValue(), + ((Number)vals.get(2)).doubleValue(), + ((Number)vals.get(3)).floatValue(), + ((Number)vals.get(4)).floatValue())); } } } @@ -513,6 +585,6 @@ public class EssentialsUpgrade moveUsersDataToUserdataFolder(); convertWarps(); updateUsersPowerToolsFormat(); - //TODO: Convert 2.5.7 homes to new format + updateUsersHomesFormat(); } } diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index 0f470a7ab..c48d5d772 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -22,7 +22,7 @@ public interface IUser boolean isAuthorized(String node); boolean isAuthorized(IEssentialsCommand cmd); - + boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix); void setLastTeleportTimestamp(long time); @@ -46,7 +46,7 @@ public interface IUser void setLastLocation(); Location getHome(String name); - + Location getHome(Location loc); String getName(); diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index badc0e267..14574b83c 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.commands.NotEnoughArgumentsException; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.logging.Logger; @@ -258,21 +259,6 @@ public class Teleport implements Runnable back(null); } - public void home(Trade chargeFor) throws Exception - { - home(user, chargeFor); - } - - public void home(String home, Trade chargeFor) throws Exception - { - home(user, home, chargeFor); - } - - public void home(IUser user, Trade chargeFor) throws Exception - { - home(user, "0", chargeFor); - } - public void home(IUser user, String home, Trade chargeFor) throws Exception { final Location loc = user.getHome(home); @@ -284,7 +270,7 @@ public class Teleport implements Runnable } else { - throw new Exception(user == this.user ? Util.i18n("noHomeSet") : Util.i18n("noHomeSetPlayer")); + throw new NotEnoughArgumentsException(); } } teleport(new Target(loc), chargeFor); diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index f8f7d7afa..3a14bca8b 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -1,6 +1,7 @@ package com.earth2me.essentials; import com.earth2me.essentials.commands.IEssentialsCommand; +import com.earth2me.essentials.commands.NotEnoughArgumentsException; import com.earth2me.essentials.register.payment.Method; import java.util.Calendar; import java.util.GregorianCalendar; diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 1467f496d..80f23cc05 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.commands.NotEnoughArgumentsException; import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -107,10 +108,21 @@ public abstract class UserData extends PlayerExtension implements IConf public Location getHome(String name) { - Location loc = (Location)homes.get(name); + Location loc = config.getLocation("homes." + name, getServer()); if (loc == null) { - loc = (Location)homes.get(getHomes().get(Integer.parseInt(name) - 1)); + try + { + loc = config.getLocation("homes." + getHomes().get(Integer.parseInt(name) - 1), getServer()); + } + catch (IndexOutOfBoundsException e) + { + return null; + } + catch (NumberFormatException e) + { + return null; + } } return loc; @@ -121,14 +133,14 @@ public abstract class UserData extends PlayerExtension implements IConf Location loc; for (String home : getHomes()) { - loc = (Location)homes.get(home); + loc = config.getLocation("homes." + home, getServer()); if (world.getWorld() == loc.getWorld()) { return loc; } } - loc = (Location)homes.get(getHomes().get(0)); + loc = config.getLocation("homes." + getHomes().get(0), getServer()); return loc; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index cb7ba57ae..b06dec10b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -19,51 +19,44 @@ public class Commandhome extends EssentialsCommand { Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); - if (args.length == 0) + User u = user; + String homeName = ""; + String[] nameParts; + if (args.length > 0) { - List<String> homes = user.getHomes(); - if (homes.isEmpty()) - { - throw new Exception(Util.i18n("noHomeSet")); - } - else if (homes.size() == 1) + nameParts = args[0].split(":"); + if (nameParts[0].length() == args[0].length()) { - user.getTeleport().home(homes.get(0), charge); + homeName = nameParts[0]; } else { - //TODO: move to messages file - user.sendMessage("Homes: " + homes.toString()); + u = getPlayer(server, nameParts[0].split(" "), 0, true); + if (nameParts.length > 1) + { + homeName = nameParts[1]; + } } - } - else + try { - User u; - String homeName; - String[] nameParts = args[0].split(":"); - if (nameParts.length == 1) + user.getTeleport().home(u, homeName, charge); + } + catch (NotEnoughArgumentsException e) + { + List<String> homes = u.getHomes(); + if (homes.isEmpty()) { - u = user; - homeName = nameParts[0]; + throw new Exception(u == user ? Util.i18n("noHomeSet") : Util.i18n("noHomeSetPlayer")); + } + else if ((homes.size() == 1) && u == user) + { + user.getTeleport().home(u, homes.get(0), charge); } else { - try - { - u = getPlayer(server, args, 0); - } - catch (NoSuchFieldException ex) - { - u = ess.getOfflineUser(args[0]); - } - if (u == null) - { - throw new Exception(Util.i18n("playerNotFound")); - } - homeName = nameParts[1]; + user.sendMessage(Util.format("homes", homes.toString())); } - user.getTeleport().home(u, homeName, charge); } } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 93bea8f26..aa4808268 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -63,7 +63,6 @@ disabled = disabled dontMoveMessage = \u00a77Teleportation will commence in {0}. Don''t move. downloadingGeoIp = Downloading GeoIP database ... this might take a while (country: 0.6 MB, city: 20MB) duplicatedUserdata = Duplicated userdata: {0} and {1} -emptyWorldName = Set Home: World name is null or empty. enableUnlimited = \u00a77Giving unlimited amount of {0} to {1}. enabled = enabled errorCallingCommand = Error calling command /{0} @@ -96,6 +95,7 @@ helpConsole = To view help from the console, type ?. helpOp = \u00a7c[HelpOp]\u00a7f \u00a77{0}:\u00a7f {1} helpPages = Page \u00a7c{0}\u00a7f of \u00a7c{1}\u00a7f: holeInFloor = Hole in floor +homes = Homes: {0} homeSet = \u00a77Home set. homeSetToBed = \u00a77Your home is now set to this bed. hour = hour diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index eb34951ea..2b4a9d28e 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -63,7 +63,6 @@ disabled = deaktiveret dontMoveMessage = \u00a77Teleportering vil begynde om {0}. Bev\u00e6g dig ikke. downloadingGeoIp = Downloader GeoIP database ... det her kan tage et stykke tid (land: 0.6 MB, by: 20MB) duplicatedUserdata = Duplikerede userdata: {0} og {1} -emptyWorldName = S\u00e6t Hjem: World navn er null eller tom. enableUnlimited = \u00a77Giver ubegr\u00e6nset m\u00e6ngde af {0} til {1}. enabled = aktiveret errorCallingCommand = Fejl ved opkald af kommando /{0} @@ -96,6 +95,7 @@ helpConsole = For at se hj\u00e6lp fra konsolen, skriv ?. helpOp = \u00a7c[HelpOp]\u00a7f \u00a77{0}:\u00a7f {1} helpPages = Side \u00a7c{0}\u00a7f af \u00a7c{1}\u00a7f: holeInFloor = Hul i gulv +homes = Homes: {0} homeSet = \u00a77Hjem sat. homeSetToBed = \u00a77Dit hjem er nu sat til denne seng. hour = time diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index cd6888c26..ab36074af 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -63,7 +63,6 @@ disabled = deaktiviert dontMoveMessage = \u00a77Teleportvorgang startet in {0}. Beweg dich nicht. downloadingGeoIp = Lade GeoIP-Datenbank ... dies kann etwas dauern (country: 0.6 MB, city: 20MB) duplicatedUserdata = Doppelte Datei in userdata: {0} und {1} -emptyWorldName = /sethome: Weltname ist null oder leer. enableUnlimited = \u00a77Gebe {1} unendliche Mengen von {0}. enabled = aktiviert errorCallingCommand = Fehler beim Aufrufen des Befehls /{0} @@ -96,6 +95,7 @@ helpConsole = Um die Hilfe der Konsole zu sehen, schreibe ?. helpOp = \u00a7c[Hilfe]\u00a7f \u00a77{0}:\u00a7f {1} helpPages = Seite \u00a7c{0}\u00a7f von \u00a7c{1}\u00a7f: holeInFloor = Loch im Boden +homes = Homes: {0} homeSet = \u00a77Zuhause gesetzt. homeSetToBed = \u00a77Dein Zuhause ist nun an diesem Bett. hour = Stunde diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index a2a7bf32b..3a4b5b9cf 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -63,7 +63,6 @@ disabled = disabled dontMoveMessage = \u00a77Teleportation will commence in {0}. Don''t move. downloadingGeoIp = Downloading GeoIP database ... this might take a while (country: 0.6 MB, city: 20MB) duplicatedUserdata = Duplicated userdata: {0} and {1} -emptyWorldName = Set Home: World name is null or empty. enableUnlimited = \u00a77Giving unlimited amount of {0} to {1}. enabled = enabled errorCallingCommand = Error calling command /{0} @@ -96,6 +95,7 @@ helpConsole = To view help from the console, type ?. helpOp = \u00a7c[HelpOp]\u00a7f \u00a77{0}:\u00a7f {1} helpPages = Page \u00a7c{0}\u00a7f of \u00a7c{1}\u00a7f: holeInFloor = Hole in floor +homes = Homes: {0} homeSet = \u00a77Home set. homeSetToBed = \u00a77Your home is now set to this bed. hour = hour diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index de388e2ad..d58a84f65 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -63,7 +63,6 @@ disabled = d\u00e9sactiv\u00e9 dontMoveMessage = \u00a77La t\u00e9l\u00e9portation commence dans {0}. Ne bougez pas. downloadingGeoIp = T\u00e9l\u00e9chargement de la base de donn\u00e9es GeoIP ... cela peut prendre un moment (campagne : 0.6 Mo, ville : 20Mo) duplicatedUserdata = Donn\u00e9e utilisateur dupliqu\u00e9e: {0} et {1} -emptyWorldName = Set Home: Le nom du monte est nul ou vide. enableUnlimited = \u00a77Donner un nombre illimit\u00e9 de {0} \u00e0 {1}. enabled = activ\u00e9 errorCallingCommand = Erreur en appelant la commande /{0} @@ -96,6 +95,7 @@ helpConsole = Pour voir l''aide tapez ? helpOp = \u00a7c[Aide Admin]\u00a7f \u00a77{0}:\u00a7f {1} helpPages = Page \u00a7c{0}\u00a7f sur \u00a7c{1}\u00a7f. holeInFloor = Trou dans le Sol. +homes = Homes: {0} homeSet = \u00a77Home d\u00e9fini. homeSetToBed = \u00a77Votre home est d\u00e9sormais d\u00e9fini sur ce lit. hour = heure diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index c9d3d7f4b..d73a9e508 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -63,7 +63,6 @@ disabled = uitgeschakeld dontMoveMessage = \u00a77Beginnen met teleporteren in {0}. Niet bewegen. downloadingGeoIp = Bezig met downloaden van GeoIP database ... Dit kan een tijdje duren (country: 0.6 MB, city: 20MB) duplicatedUserdata = Dubbele userdata: {0} en {1}. -emptyWorldName = Set Home: Naam van wereld is leeg. enableUnlimited = \u00a77Oneindig aantal {0} aan {1} gegeven. enabled = ingeschakeld errorCallingCommand = Fout bij het aanroepen van de opdracht /{0} @@ -96,6 +95,7 @@ helpConsole = type ? om de consolehelp weer te geven. helpOp = \u00a7c[HelpOp]\u00a7f \u00a77{0}:\u00a7f {1} helpPages = Pagina \u00a7c{0}\u00a7f van de \u00a7c{1}\u00a7f: holeInFloor = Gat in de vloer +homes = Homes: {0} homeSet = \u00a77Home ingesteld. homeSetToBed = \u00a77Je home is is nu verplaatst naar dit bed. hour = uur |