Adding Home upgrade script.

Tidying up home code.
This commit is contained in:
KHobbits 2011-08-23 06:09:34 +01:00
parent 9dc54340f8
commit 6ee7017603
12 changed files with 133 additions and 69 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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())
nameParts = args[0].split(":");
if (nameParts[0].length() == args[0].length())
{
throw new Exception(Util.i18n("noHomeSet"));
}
else if (homes.size() == 1)
{
user.getTeleport().home(homes.get(0), charge);
}
else
{
//TODO: move to messages file
user.sendMessage("Homes: " + homes.toString());
}
}
else
{
User u;
String homeName;
String[] nameParts = args[0].split(":");
if (nameParts.length == 1)
{
u = user;
homeName = nameParts[0];
}
else
{
try
u = getPlayer(server, nameParts[0].split(" "), 0, true);
if (nameParts.length > 1)
{
u = getPlayer(server, args, 0);
homeName = nameParts[1];
}
catch (NoSuchFieldException ex)
{
u = ess.getOfflineUser(args[0]);
}
if (u == null)
{
throw new Exception(Util.i18n("playerNotFound"));
}
homeName = nameParts[1];
}
}
try
{
user.getTeleport().home(u, homeName, charge);
}
catch (NotEnoughArgumentsException e)
{
List<String> homes = u.getHomes();
if (homes.isEmpty())
{
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
{
user.sendMessage(Util.format("homes", homes.toString()));
}
}
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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