diff options
author | KHobbits <rob@khobbits.co.uk> | 2011-08-24 05:18:35 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2011-08-24 05:18:35 +0100 |
commit | 3d913f9fcc392e3b04be29417205da9a9d27ee5a (patch) | |
tree | 76af7addd239990c13fb3f8fdbbb0e8b7ad2ce84 | |
parent | 6c738294d1a37ad10e351838b6b8923a41b37628 (diff) | |
download | Essentials-3d913f9fcc392e3b04be29417205da9a9d27ee5a.tar Essentials-3d913f9fcc392e3b04be29417205da9a9d27ee5a.tar.gz Essentials-3d913f9fcc392e3b04be29417205da9a9d27ee5a.tar.lz Essentials-3d913f9fcc392e3b04be29417205da9a9d27ee5a.tar.xz Essentials-3d913f9fcc392e3b04be29417205da9a9d27ee5a.zip |
Make home throw an exception if the world doesn't exist.
Add multiverse/missing world support to home upgrade.
7 files changed, 56 insertions, 20 deletions
diff --git a/Essentials/nbproject/pmd.settings b/Essentials/nbproject/pmd.settings index 6a34e356c..824aa3ac9 100644 --- a/Essentials/nbproject/pmd.settings +++ b/Essentials/nbproject/pmd.settings @@ -1 +1,2 @@ DoNotUseThreads +SignatureDeclareThrowsException diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 82d4876f5..6c6567461 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -155,7 +155,7 @@ public class EssentialsConf extends Configuration return getProperty(path) != null; } - public Location getLocation(String path, Server server) + public Location getLocation(String path, Server server) throws Exception { String worldName = getString((path != null ? path + "." : "") + "world"); if (worldName == null || worldName.isEmpty()) @@ -165,7 +165,7 @@ public class EssentialsConf extends Configuration World world = server.getWorld(worldName); if (world == null) { - return null; + throw new Exception(Util.i18n("invalidWorld")); } return new Location(world, getDouble((path != null ? path + "." : "") + "x", 0), diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index 8a771778d..ffe4f5375 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -280,7 +280,7 @@ public class EssentialsUpgrade { @SuppressWarnings("unchecked") final String defworld = (String)config.getProperty("home.default"); - final Location defloc = config.getLocation("home.worlds." + defworld, ess.getServer()); + final Location defloc = getFakeLocation(config,"home.worlds." + defworld); if (defloc != null) { config.setProperty("homes.home", defloc); @@ -300,7 +300,7 @@ public class EssentialsUpgrade { continue; } - loc = config.getLocation("home.worlds." + world, ess.getServer()); + loc = getFakeLocation(config, "home.worlds." + world); if (loc == null) { continue; @@ -570,6 +570,25 @@ public class EssentialsUpgrade } return null; } + public Location getFakeLocation(EssentialsConf config, String path) + { + String worldName = config.getString((path != null ? path + "." : "") + "world"); + if (worldName == null || worldName.isEmpty()) + { + return null; + } + World world = getFakeWorld(worldName); + if (world == null) + { + return null; + } + return new Location(world, + config.getDouble((path != null ? path + "." : "") + "x", 0), + config.getDouble((path != null ? path + "." : "") + "y", 0), + config.getDouble((path != null ? path + "." : "") + "z", 0), + (float)config.getDouble((path != null ? path + "." : "") + "yaw", 0), + (float)config.getDouble((path != null ? path + "." : "") + "pitch", 0)); + } public void beforeSettings() { diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index c48d5d772..91a121e0a 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -45,9 +45,9 @@ public interface IUser void setLastLocation(); - Location getHome(String name); + Location getHome(String name) throws Exception; - Location getHome(Location loc); + Location getHome(Location loc) throws Exception; String getName(); diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 3a14bca8b..29bbd89cc 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -193,7 +193,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser return !ess.getSettings().itemSpawnBlacklist().contains(itemId); } - public Location getHome() + public Location getHome() throws Exception { return getHome(getHomes().get(0)); } diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 030b5a479..e5c7385b2 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -106,7 +106,7 @@ public abstract class UserData extends PlayerExtension implements IConf } - public Location getHome(String name) + public Location getHome(String name) throws Exception { Location loc = config.getLocation("homes." + name, getServer()); if (loc == null) @@ -128,7 +128,7 @@ public abstract class UserData extends PlayerExtension implements IConf return loc; } - public Location getHome(Location world) + public Location getHome(Location world) throws Exception { Location loc; for (String home : getHomes()) @@ -166,9 +166,10 @@ public abstract class UserData extends PlayerExtension implements IConf config.removeProperty("homes." + name); config.save(); } - else { + else + { //TODO: move this message to messages file - throw new Exception("Home "+name+" doesn't exist"); + throw new Exception("Home " + name + " doesn't exist"); } } @@ -261,7 +262,14 @@ public abstract class UserData extends PlayerExtension implements IConf private Location _getLastLocation() { - return config.getLocation("lastlocation", getServer()); + try + { + return config.getLocation("lastlocation", getServer()); + } + catch (Exception e) + { + return null; + } } public Location getLastLocation() diff --git a/Essentials/test/com/earth2me/essentials/UserTest.java b/Essentials/test/com/earth2me/essentials/UserTest.java index 4724c96d6..35244ac90 100644 --- a/Essentials/test/com/earth2me/essentials/UserTest.java +++ b/Essentials/test/com/earth2me/essentials/UserTest.java @@ -46,7 +46,7 @@ public class UserTest extends TestCase OfflinePlayer base1alt = server.createPlayer(base1.getName(), ess); assertEquals(base1alt, ess.getUser(base1alt).getBase()); } - + public void testHome() { User user = ess.getUser(base1); @@ -54,13 +54,21 @@ public class UserTest extends TestCase user.setHome(); OfflinePlayer base2 = server.createPlayer(base1.getName(), ess); User user2 = ess.getUser(base2); - Location home = user2.getHome(loc); - assertEquals(loc.getWorld().getName(), home.getWorld().getName()); - assertEquals(loc.getX(), home.getX()); - assertEquals(loc.getY(), home.getY()); - assertEquals(loc.getZ(), home.getZ()); - assertEquals(loc.getYaw(), home.getYaw()); - assertEquals(loc.getPitch(), home.getPitch()); + try + { + Location home = user2.getHome(loc); + assertEquals(loc.getWorld().getName(), home.getWorld().getName()); + assertEquals(loc.getX(), home.getX()); + assertEquals(loc.getY(), home.getY()); + assertEquals(loc.getZ(), home.getZ()); + assertEquals(loc.getYaw(), home.getYaw()); + assertEquals(loc.getPitch(), home.getPitch()); + } + catch (Exception ex) + { + fail("Exception"); + } + } public void testMoney() |