From 15ce10671eb39dc4050e4ce128b223a2bc89a57e Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Fri, 2 Dec 2011 18:19:26 -0700 Subject: [PATCH 01/24] Fix colors bleeding into the next name, Fixes #285 --- .../com/onarandombox/MultiverseCore/commands/WhoCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java index 82a66fb3..2ba65398 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java @@ -92,7 +92,7 @@ public class WhoCommand extends MultiverseCommand { result = "Empty"; } else { for (Player player : players) { - result += player.getDisplayName() + " "; + result += player.getDisplayName() + " " + ChatColor.WHITE; } } From f6e49bd8eb3a1c13f6e19b704cc0607a09f776ce Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Tue, 6 Dec 2011 18:14:34 -0700 Subject: [PATCH 02/24] Fix pitch/yaw switched for mvss on reload --- .../configuration/LocationConfigProperty.java | 22 ++-- .../MultiverseCore/utils/AnchorManager.java | 4 +- .../utils/LocationManipulation.java | 119 ++++++++---------- 3 files changed, 68 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java index 49ace4a0..50aeaf85 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java @@ -23,7 +23,7 @@ public class LocationConfigProperty implements MVConfigProperty { this.configNode = name; this.section = section; this.help = help; - this.setValue(this.getLocationFromConfig(this.configNode, defaultValue)); + this.setValue(this.getLocationFromConfig(defaultValue)); } public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode, String help) { @@ -31,7 +31,7 @@ public class LocationConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; - this.setValue(this.getLocationFromConfig(this.configNode, defaultValue)); + this.setValue(this.getLocationFromConfig(defaultValue)); } @Override @@ -46,7 +46,7 @@ public class LocationConfigProperty implements MVConfigProperty { @Override public boolean parseValue(String value) { - Location parsed = LocationManipulation.getLocationFromString(value); + Location parsed = LocationManipulation.stringToLocation(value); return this.setValue(parsed); } @@ -80,14 +80,14 @@ public class LocationConfigProperty implements MVConfigProperty { return true; } - private Location getLocationFromConfig(String node, Location defaultValue) { - double x = this.section.getDouble(configNode + ".x", defaultValue.getX()); - double y = this.section.getDouble(configNode + ".y", defaultValue.getY()); - double z = this.section.getDouble(configNode + ".z", defaultValue.getZ()); - double p = this.section.getDouble(configNode + ".pitch", defaultValue.getPitch()); - double yaw = this.section.getDouble(configNode + ".yaw", defaultValue.getYaw()); - String w = this.section.getString(configNode + ".world", defaultValue.getWorld().getName()); - Location found = LocationManipulation.getLocationFromString(w + ":" + x + "," + y + "," + z + ":" + p + ":" + yaw); + private Location getLocationFromConfig(Location defaultValue) { + double x = this.section.getDouble(this.configNode + ".x", defaultValue.getX()); + double y = this.section.getDouble(this.configNode + ".y", defaultValue.getY()); + double z = this.section.getDouble(this.configNode + ".z", defaultValue.getZ()); + double pitch = this.section.getDouble(this.configNode + ".pitch", defaultValue.getPitch()); + double yaw = this.section.getDouble(this.configNode + ".yaw", defaultValue.getYaw()); + String w = this.section.getString(this.configNode + ".world", defaultValue.getWorld().getName()); + Location found = LocationManipulation.stringToLocation(w + ":" + x + "," + y + "," + z + ":" + yaw + ":" + pitch); if (found != null) { return found; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java index 450fb6c1..9b325cbc 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java @@ -42,7 +42,7 @@ public class AnchorManager { Set anchorKeys = anchors.getKeys(false); for (String key : anchorKeys) { //world:x,y,z:pitch:yaw - Location anchorLocation = LocationManipulation.getLocationFromString(anchors.getString(key, "")); + Location anchorLocation = LocationManipulation.stringToLocation(anchors.getString(key, "")); if (anchorLocation != null) { MultiverseCore.staticLog(Level.INFO, "Loading anchor: '" + key + "'..."); this.anchors.put(key, anchorLocation); @@ -77,7 +77,7 @@ public class AnchorManager { } public boolean saveAnchorLocation(String anchor, String location) { - Location parsed = LocationManipulation.getLocationFromString(location); + Location parsed = LocationManipulation.stringToLocation(location); return parsed != null && this.saveAnchorLocation(anchor, parsed); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java index 0b380ef9..277d9bf4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java @@ -15,6 +15,7 @@ import org.bukkit.entity.Vehicle; import org.bukkit.util.Vector; import java.text.DecimalFormat; +import java.util.Formatter; import java.util.HashMap; import java.util.Map; @@ -35,44 +36,73 @@ public class LocationManipulation { /** * Convert a Location into a Colon separated string to allow us to store it in text. - * world:x,y,z:pitch:yaw + *

+ * WORLD:X,Y,Z:yaw:pitch + *

+ * The corresponding String2Loc function is {@link #stringToLocation } * - * @param location - * @return + * @param location The Location to save. + * @return The location as a string in this format: WORLD:x,y,z:yaw:pitch */ public static String locationToString(Location location) { if (location == null) { return ""; } StringBuilder l = new StringBuilder(); - l.append(location.getWorld().getName() + ":"); - l.append(location.getBlockX() + ","); - l.append(location.getBlockY() + ","); - l.append(location.getBlockZ() + ":"); - l.append(location.getYaw() + ":"); - l.append(location.getPitch()); - return l.toString(); + Formatter formatter = new Formatter(l); + formatter.format("%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + return formatter.toString(); } /** - * Convert a String to a Location. + * Returns a new location from a given string. The format is as follows: + *

+ * WORLD:X,Y,Z:yaw:pitch + *

+ * The corresponding Location2String function is {@link #stringToLocation } * - * @param world - * @param xStr - * @param yStr - * @param zStr - * @param yawStr - * @param pitchStr - * @return + * @param locationString The location represented as a string (WORLD:X,Y,Z:yaw:pitch) + * @return A new location defined by the string or null if the string was invalid. */ - public Location stringToLocation(World world, String xStr, String yStr, String zStr, String yawStr, String pitchStr) { - double x = Double.parseDouble(xStr); - double y = Double.parseDouble(yStr); - double z = Double.parseDouble(zStr); - float yaw = Float.valueOf(yawStr); - float pitch = Float.valueOf(pitchStr); + public static Location stringToLocation(String locationString) { + //format: + //world:x,y,z:pitch:yaw + if (locationString == null) { + return null; + } - return new Location(world, x, y, z, yaw, pitch); + // Split the whole string, format is: + // {'world', 'x,y,z'[, 'pitch', 'yaw']} + String[] split = locationString.split(":"); + if (split.length < 2 || split.length > 4) { + return null; + } + // Split the xyz string, format is: + // {'x', 'y', 'z'} + String[] xyzsplit = split[1].split(","); + if (xyzsplit.length != 3) { + return null; + } + + // Verify the world is valid + World w = Bukkit.getWorld(split[0]); + if (w == null) { + return null; + } + + try { + float pitch = 0; + float yaw = 0; + if (split.length == 3) { + yaw = (float) Double.parseDouble(split[2]); + } + if (split.length == 4) { + pitch = (float) Double.parseDouble(split[2]); + } + return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch); + } catch (NumberFormatException e) { + return null; + } } /** @@ -221,43 +251,4 @@ public class LocationManipulation { int z = vector.getZ() < 0 ? vector.getZ() == 0 ? 0 : -1 : 1; return location.add(x, 0, z); } - - public static Location getLocationFromString(String value) { - //format: - //world:x,y,z:pitch:yaw - if (value == null) { - return null; - } - - // Split the whole string, format is: - // {'world', 'x,y,z'[, 'pitch', 'yaw']} - String[] split = value.split(":"); - if (split.length < 2 || split.length > 4) { - return null; - } - // Split the xyz string, format is: - // {'x', 'y', 'z'} - String[] xyzsplit = split[1].split(","); - if (xyzsplit.length != 3) { - return null; - } - - // Verify the world is valid - World w = Bukkit.getWorld(split[0]); - if (w == null) { - return null; - } - - try { - if (split.length == 2) { - return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2])); - } - if (split.length == 3) { - return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), (float) Double.parseDouble(split[2]), (float) 0.0); - } - return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), (float) Double.parseDouble(split[2]), (float) Double.parseDouble(split[3])); - } catch (NumberFormatException e) { - return null; - } - } } From 3a5bc6adda4751121896a1562d0961d07abdd046 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Tue, 6 Dec 2011 18:40:09 -0700 Subject: [PATCH 03/24] Actually fixed #294 --- .../MultiverseCore/configuration/LocationConfigProperty.java | 1 + .../MultiverseCore/listeners/MVPlayerListener.java | 3 --- .../MultiverseCore/utils/LocationManipulation.java | 5 +++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java index 50aeaf85..df6bc64c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java @@ -77,6 +77,7 @@ public class LocationConfigProperty implements MVConfigProperty { this.section.set(configNode + ".pitch", this.value.getPitch()); this.section.set(configNode + ".yaw", this.value.getYaw()); this.section.set(configNode + ".world", this.value.getWorld().getName()); + return true; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 6598e020..f5389abd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -173,10 +173,7 @@ public class MVPlayerListener extends PlayerListener { // TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what // TODO: we want to do here. if (newloc != null) { - System.out.println("Found a new location!"); event.setFrom(newloc); - } else { - System.out.println("Did NOT find a new location!"); } } // Wait for the adjust, then return! diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java index 277d9bf4..0eee83ee 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java @@ -15,6 +15,7 @@ import org.bukkit.entity.Vehicle; import org.bukkit.util.Vector; import java.text.DecimalFormat; +import java.util.Arrays; import java.util.Formatter; import java.util.HashMap; import java.util.Map; @@ -93,11 +94,11 @@ public class LocationManipulation { try { float pitch = 0; float yaw = 0; - if (split.length == 3) { + if (split.length >= 3) { yaw = (float) Double.parseDouble(split[2]); } if (split.length == 4) { - pitch = (float) Double.parseDouble(split[2]); + pitch = (float) Double.parseDouble(split[3]); } return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch); } catch (NumberFormatException e) { From 8916f0dbbc2e8dc9c9eaac89771f4f4f924da6c3 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Wed, 7 Dec 2011 00:16:42 -0500 Subject: [PATCH 04/24] Combine JUnit dependencies --- pom.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index a3748cc0..ddb0875d 100644 --- a/pom.xml +++ b/pom.xml @@ -187,10 +187,9 @@ - org.junit + junit junit 4.8.2 - test org.powermock @@ -219,11 +218,6 @@ 3.0 test - - junit - junit - 4.8.1 - From 56e4e493b189ed12d0ae85d4f23fc7dda8854338 Mon Sep 17 00:00:00 2001 From: "main()" Date: Thu, 8 Dec 2011 19:08:07 +0100 Subject: [PATCH 05/24] Fixed all javadoc warnings and some typos. --- .../MultiverseCore/MultiverseCore.java | 23 ++++----- .../MultiverseCore/event/MVTeleportEvent.java | 4 +- .../MultiverseCore/utils/BlockSafety.java | 14 +++--- .../utils/LocationManipulation.java | 47 +++++++++---------- .../MultiverseCore/utils/MVPermissions.java | 15 +++--- .../MultiverseCore/utils/MVPlayerSession.java | 2 - .../MultiverseCore/utils/UpdateChecker.java | 7 ++- 7 files changed, 50 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 80301446..e42be439 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -53,8 +53,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { /** * This method is used to find out who is teleporting a player. - * @param playerName - * @return + * @param playerName The teleported player. + * @return The player that teleported the other one. */ public static String getPlayerTeleporter(String playerName) { if(teleportQueue.containsKey(playerName)) { @@ -370,9 +370,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { } /** - * Grab and return the Teleport class. + * Grab and return the {@link SafeTTeleporter}. * - * @return + * @return The {@link SafeTTeleporter}. */ public SafeTTeleporter getTeleporter() { return new SafeTTeleporter(this); @@ -405,8 +405,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { * Print messages to the server Log as well as to our DebugLog. 'debugLog' is used to seperate Heroes information * from the Servers Log Output. * - * @param level - * @param msg + * @param level The Log-{@link Level} + * @param msg The message */ public void log(Level level, String msg) { staticLog(level, msg); @@ -432,8 +432,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { * Print messages to the Debug Log, if the servers in Debug Mode then we also wan't to print the messages to the * standard Server Console. * - * @param level - * @param msg + * @param level The Log-{@link Level} + * @param msg The message */ public static void staticDebugLog(Level level, String msg) { log.log(level, "[MVCore-Debug] " + msg); @@ -443,7 +443,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { /** * Parse the Authors Array into a readable String with ',' and 'and'. * - * @return + * @return The readable authors-{@link String} */ private String getAuthors() { String authors = ""; @@ -476,9 +476,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { /** * This code should get moved somewhere more appropriate, but for now, it's here. - * - * @param env - * @return */ public Environment getEnvFromString(String env) { // Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way @@ -513,7 +510,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { /** * Returns the number of plugins that have specifically hooked into core. * - * @return + * @return The number if plugins that have hooked into core. */ public int getPluginCount() { return this.pluginCount; diff --git a/src/main/java/com/onarandombox/MultiverseCore/event/MVTeleportEvent.java b/src/main/java/com/onarandombox/MultiverseCore/event/MVTeleportEvent.java index da230bbb..ed28b35a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/event/MVTeleportEvent.java +++ b/src/main/java/com/onarandombox/MultiverseCore/event/MVTeleportEvent.java @@ -53,9 +53,9 @@ public class MVTeleportEvent extends Event implements Cancellable { } /** - * Returns the player who requested the Teleport + * Gets the {@link CommandSender} who requested the Teleport * - * @return + * @return The {@link CommandSender} who requested the Teleport */ public CommandSender getTeleporter() { return this.teleporter; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/BlockSafety.java b/src/main/java/com/onarandombox/MultiverseCore/utils/BlockSafety.java index e29902a8..f3937611 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/BlockSafety.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/BlockSafety.java @@ -43,10 +43,11 @@ public class BlockSafety { } /** - * This function checks whether the block at the coordinates given is safe or not by checking for Laval/Fire/Air + * This function checks whether the block at the coordinates given is safe or not by checking for Lava/Fire/Air * etc. This also ensures there is enough space for a player to spawn! * - * @return + * @param l The {@link Location} + * @return Whether the player can spawn safely at the given {@link Location} */ public boolean playerCanSpawnHereSafely(Location l) { World world = l.getWorld(); @@ -107,9 +108,6 @@ public class BlockSafety { /** * If someone has a better way of this... Please either tell us, or submit a pull request! - * - * @param type - * @return */ private boolean isSolidBlock(Material type) { switch (type) { @@ -196,10 +194,10 @@ public class BlockSafety { } /** - * Checks recursively below location L for 2 blocks of water + * Checks recursively below a {@link Location} for 2 blocks of water * - * @param l - * @return + * @param l The {@link Location} + * @return Whether there are 2 blocks of water */ public boolean hasTwoBlocksofWaterBelow(Location l) { if (l.getBlockY() < 0) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java index 0eee83ee..fb44f105 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java @@ -15,7 +15,6 @@ import org.bukkit.entity.Vehicle; import org.bukkit.util.Vector; import java.text.DecimalFormat; -import java.util.Arrays; import java.util.Formatter; import java.util.HashMap; import java.util.Map; @@ -37,10 +36,10 @@ public class LocationManipulation { /** * Convert a Location into a Colon separated string to allow us to store it in text. - *

+ *

* WORLD:X,Y,Z:yaw:pitch - *

- * The corresponding String2Loc function is {@link #stringToLocation } + *

+ * The corresponding String2Loc function is {@link #stringToLocation} * * @param location The Location to save. * @return The location as a string in this format: WORLD:x,y,z:yaw:pitch @@ -57,10 +56,10 @@ public class LocationManipulation { /** * Returns a new location from a given string. The format is as follows: - *

+ *

* WORLD:X,Y,Z:yaw:pitch - *

- * The corresponding Location2String function is {@link #stringToLocation } + *

+ * The corresponding Location2String function is {@link #stringToLocation} * * @param locationString The location represented as a string (WORLD:X,Y,Z:yaw:pitch) * @return A new location defined by the string or null if the string was invalid. @@ -109,8 +108,8 @@ public class LocationManipulation { /** * Returns a colored string with the coords * - * @param l - * @return + * @param l The {@link Location} + * @return The {@link String} */ public static String strCoords(Location l) { String result = ""; @@ -128,8 +127,8 @@ public class LocationManipulation { /** * Converts a location to a printable readable formatted string including pitch/yaw * - * @param l - * @return + * @param l The {@link Location} + * @return The {@link String} */ public static String strCoordsRaw(Location l) { String result = ""; @@ -147,8 +146,8 @@ public class LocationManipulation { /** * Return the NESW Direction a Location is facing. * - * @param location - * @return + * @param location The {@link Location} + * @return The NESW Direction */ public static String getDirection(Location location) { double r = (location.getYaw() % 360) + 180; @@ -177,10 +176,10 @@ public class LocationManipulation { } /** - * Returns the float yaw position for the given cardianl direction + * Returns the float yaw position for the given cardinal direction * - * @param orientation - * @return + * @param orientation The cardinal direction + * @return The yaw */ public static float getYaw(String orientation) { if (orientation == null) { @@ -195,8 +194,8 @@ public class LocationManipulation { /** * Returns a speed float from a given vector. * - * @param v - * @return + * @param v The {@link Vector} + * @return The speed */ public static float getSpeed(Vector v) { return (float) Math.sqrt(v.getX() * v.getX() + v.getZ() * v.getZ()); @@ -208,9 +207,9 @@ public class LocationManipulation { /** * Returns a translated vector from the given direction * - * @param v - * @param direction - * @return + * @param v The old {@link Vector} + * @param direction The new direction + * @return The translated {@link Vector} */ public static Vector getTranslatedVector(Vector v, String direction) { if (direction == null) { @@ -240,10 +239,10 @@ public class LocationManipulation { } /** - * Returns the next Location that an entity is traveling at + * Returns the next Location that a {@link Vehicle} is traveling at * - * @param v - * @return + * @param v The {@link Vehicle} + * @return The {@link Location} */ public static Location getNextBlock(Vehicle v) { Vector vector = v.getVelocity(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java index 4c02ebbc..072e6762 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java @@ -39,9 +39,9 @@ public class MVPermissions implements PermissionsInterface { /** * Check if a Player can teleport to the Destination world from there current world. * - * @param p The player to check. - * @param w - * @return + * @param p The {@link Player} to check. + * @param w The {@link MultiverseWorld} the player wants to teleport to. + * @return Whether the player can teleport to the given {@link MultiverseWorld}. */ public boolean canTravelFromWorld(Player p, MultiverseWorld w) { List blackList = w.getWorldBlacklist(); @@ -72,9 +72,9 @@ public class MVPermissions implements PermissionsInterface { /** * Check if the Player has the permissions to enter this world. * - * @param p - * @param w - * @return + * @param p The {@link Player} player that wants to enter + * @param w The {@link MultiverseWorld} he wants to enter + * @return Whether he has the permission to enter the world */ public boolean canEnterWorld(Player p, MultiverseWorld w) { // If we're not enforcing access, anyone can enter. @@ -285,9 +285,6 @@ public class MVPermissions implements PermissionsInterface { /** * If the given permission was 'multiverse.core.tp.self', this would return 'multiverse.core.tp.*'. - * - * @param seperated - * @return */ private String getParentPerm(String[] seperated) { if (seperated.length == 1) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java index e13f5f65..7a293cc2 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java @@ -35,8 +35,6 @@ public class MVPlayerSession { /** * Grab whether the cooldown on Portal use has expired or not. - * - * @return */ public boolean getTeleportable() { Long time = (new Date()).getTime(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java b/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java index edb464ad..8ed7bd99 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java @@ -85,11 +85,10 @@ public class UpdateChecker { } /** - * Convert the given Version String to a Normalised Version String so we can compare it. + * Convert the given Version String to a Normalized Version String so we can compare it. * - * @param version - * - * @return + * @param version The version string + * @return The normalized version string */ public static String normalisedVersion(String version) { return normalisedVersion(version, ".", 4); From dbf109f0510e5b3453e644a890837c96a17410ad Mon Sep 17 00:00:00 2001 From: "main()" Date: Thu, 8 Dec 2011 19:17:55 +0100 Subject: [PATCH 06/24] Raw types are evil. --- .../com/onarandombox/MultiverseCore/MVWorld.java | 12 ++++++------ .../MultiverseCore/api/MultiverseWorld.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 8df6bc31..01699b83 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -45,7 +45,7 @@ public class MVWorld implements MultiverseWorld { private String name; // The Worlds Name, EG its folder name. private Map> masterList; - private Map propertyList; + private Map> propertyList; private String generator; private Permission permission; @@ -82,7 +82,7 @@ public class MVWorld implements MultiverseWorld { // Start NEW config awesomeness. ConfigPropertyFactory fac = new ConfigPropertyFactory(this.worldSection); - this.propertyList = new HashMap(); + this.propertyList = new HashMap>(); // The format of these are either: // getNewProperty(name, defaultValue, helpText) // or @@ -344,8 +344,8 @@ public class MVWorld implements MultiverseWorld { } @Override - public MVConfigProperty getProperty(String name) throws PropertyDoesNotExistException { - MVConfigProperty p = this.getKnownProperty(name); + public MVConfigProperty getProperty(String name) throws PropertyDoesNotExistException { + MVConfigProperty p = this.getKnownProperty(name); if (p == null) { throw new PropertyDoesNotExistException(name); } @@ -358,7 +358,7 @@ public class MVWorld implements MultiverseWorld { * @param name The known name of a property * @return The property object. */ - private MVConfigProperty getKnownProperty(String name) { + private MVConfigProperty getKnownProperty(String name) { if (this.propertyList.containsKey(name)) { return this.propertyList.get(name); } else if (this.propertyAliases.containsKey(name)) { @@ -377,7 +377,7 @@ public class MVWorld implements MultiverseWorld { * @return True if the property was saved, false if not. */ private boolean setKnownProperty(String name, String value, CommandSender sender) { - MVConfigProperty property; + MVConfigProperty property; if (this.propertyList.containsKey(name)) { property = this.getKnownProperty(name); } else if (this.propertyAliases.containsKey(name)) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index e4915aff..d7ac5fa1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -49,7 +49,7 @@ public interface MultiverseWorld { * @return A valid MVWorldProperty. * @throws PropertyDoesNotExistException Thrown if the property was not found in the world. */ - public MVConfigProperty getProperty(String property) throws PropertyDoesNotExistException; + public MVConfigProperty getProperty(String property) throws PropertyDoesNotExistException; /** * Gets the string representation of a property. From 8b721886f5f187d89a7177c4da8b2d699d2e45a2 Mon Sep 17 00:00:00 2001 From: "main()" Date: Thu, 8 Dec 2011 19:34:54 +0100 Subject: [PATCH 07/24] Yes, the MVConfigMigrator is old and uses deprecated stuff. --- .../MultiverseCore/configuration/MVConfigMigrator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/MVConfigMigrator.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/MVConfigMigrator.java index b9f055a4..5b9e33ce 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/MVConfigMigrator.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/MVConfigMigrator.java @@ -17,6 +17,7 @@ import java.util.Arrays; import java.util.List; import java.util.logging.Level; +@SuppressWarnings("deprecation") public abstract class MVConfigMigrator { public List createdDefaults = new ArrayList(); From 5b17df65e96e627446063ed47a254c5bacbab5ed Mon Sep 17 00:00:00 2001 From: "main()" Date: Thu, 8 Dec 2011 19:35:20 +0100 Subject: [PATCH 08/24] Removed unused imports --- .../onarandombox/MultiverseCore/commands/CreateCommand.java | 1 - .../com/onarandombox/MultiverseCore/commands/ListCommand.java | 1 - .../MultiverseCore/commands/ModifyClearCommand.java | 1 - .../onarandombox/MultiverseCore/commands/ModifySetCommand.java | 1 - .../com/onarandombox/MultiverseCore/commands/WhoCommand.java | 1 - .../MultiverseCore/listeners/MVEntityListener.java | 3 --- .../MultiverseCore/utils/webpaste/PastebinPasteService.java | 1 - 7 files changed, 9 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index 0283eb27..fae7c8ea 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.commands; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.utils.WorldManager; import com.pneumaticraft.commandhandler.CommandHandler; import org.bukkit.ChatColor; import org.bukkit.World.Environment; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java index 657b2c09..388cd8a3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java @@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.commands; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.pneumaticraft.commandhandler.Command; import org.bukkit.ChatColor; import org.bukkit.World.Environment; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java index 0bd68fe3..586006d3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java @@ -11,7 +11,6 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.enums.Action; -import com.onarandombox.MultiverseCore.utils.WorldManager; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java index 40e32d77..45203998 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java @@ -12,7 +12,6 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.enums.EnglishChatColor; import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException; -import com.onarandombox.MultiverseCore.utils.WorldManager; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java index 2ba65398..6e19f216 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java @@ -10,7 +10,6 @@ package com.onarandombox.MultiverseCore.commands; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.utils.WorldManager; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java index 339df8a5..497adb9f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java @@ -11,9 +11,6 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.utils.PermissionTools; -import com.onarandombox.MultiverseCore.utils.SafeTTeleporter; -import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.*; import org.bukkit.event.entity.*; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java index 042b679b..1dae09c4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java @@ -8,7 +8,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; -import java.util.regex.Matcher; import java.util.regex.Pattern; public class PastebinPasteService implements PasteService { From 24efbf2ea9a67f671145dd675e4cb38b3bd662c9 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Thu, 8 Dec 2011 18:25:05 -0500 Subject: [PATCH 09/24] Remove UNKNOWN version number from pom.xml --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ddb0875d..5501d653 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,6 @@ World Management Plugin UTF-8 - UNKNOWN @@ -86,7 +85,7 @@ maven-version-number - ${project.version}-${project.build.number} + ${project.version}-${BUILD_NUMBER} From af439b678e546ffeb1925ee1d19d5bae7991ecb6 Mon Sep 17 00:00:00 2001 From: 4am Date: Thu, 8 Dec 2011 19:19:17 -0500 Subject: [PATCH 10/24] Changed runCommand to look in world container directory (defined in bukkit.yml) instead of in the server folder when attempting to load world files. --- .../com/onarandombox/MultiverseCore/commands/ImportCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java index e0dbb524..1edf1828 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java @@ -106,7 +106,7 @@ public class ImportCommand extends MultiverseCommand { this.showHelp(sender); return; } - File worldFile = new File(this.plugin.getServerFolder(), worldName); + File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName); if (this.worldManager.isMVWorld(worldName) && worldFile.exists()) { sender.sendMessage(ChatColor.RED + "Multiverse already knows about this world!"); return; From 5159fe7a17d39ca6f6b043020fe515c1856be12a Mon Sep 17 00:00:00 2001 From: fernferret Date: Fri, 9 Dec 2011 00:06:34 -0700 Subject: [PATCH 11/24] Add new repo to the POM. --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 5501d653..7250861b 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,10 @@ OnARandomBox http://repo.onarandombox.com/artifactory/repo + + opencraft + http://pneumaticsystem.com:25578/nexus/content/repositories/opencraft + From 10a4ec1c0b59353cdbcaf2f70f27cd2cc2f43aca Mon Sep 17 00:00:00 2001 From: fernferret Date: Fri, 9 Dec 2011 00:39:57 -0700 Subject: [PATCH 12/24] Add WorldContainer to tests, they pass again. Yay! --- .../onarandombox/MultiverseCore/test/TestWorldStuff.java | 6 +++--- .../MultiverseCore/test/utils/TestInstanceCreator.java | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java index 31536bba..69297887 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java @@ -39,9 +39,9 @@ import com.onarandombox.MultiverseCore.utils.WorldManager; @PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, WorldManager.class }) public class TestWorldStuff { - TestInstanceCreator creator; - Server mockServer; - CommandSender mockCommandSender; + private TestInstanceCreator creator; + private Server mockServer; + private CommandSender mockCommandSender; @Before public void setUp() throws Exception { diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java index 96691765..fa3f63b1 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java @@ -44,6 +44,7 @@ public class TestInstanceCreator { public static final File pluginDirectory = new File("bin/test/server/plugins/coretest"); public static final File serverDirectory = new File("bin/test/server"); + public static final File worldsDirectory = new File("bin/test/server"); public boolean setUp() { try { @@ -87,6 +88,7 @@ public class TestInstanceCreator { when(mockServer.getName()).thenReturn("TestBukkit"); Logger.getLogger("Minecraft").setParent(Util.logger); when(mockServer.getLogger()).thenReturn(Util.logger); + when(mockServer.getWorldContainer()).thenReturn(worldsDirectory); // Give the server some worlds when(mockServer.getWorld(anyString())).thenAnswer(new Answer() { From 08736cca16792c93cc96102244f428162333a412 Mon Sep 17 00:00:00 2001 From: fernferret Date: Fri, 9 Dec 2011 01:00:49 -0700 Subject: [PATCH 13/24] Time for bed. Too many mistakes. Fixed the Core Pom (again) --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7250861b..313826e6 100644 --- a/pom.xml +++ b/pom.xml @@ -16,8 +16,8 @@ http://repo.onarandombox.com/artifactory/repo - opencraft - http://pneumaticsystem.com:25578/nexus/content/repositories/opencraft + econ + http://pneumaticsystem.com:25578/nexus/content/repositories/bukkit-econ From ff8b9eb3b7f4356991a70a8b648de27d4c2c15db Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Fri, 9 Dec 2011 10:04:46 -0500 Subject: [PATCH 14/24] Remove onarandombox repo; fix the build version number replacement --- pom.xml | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 313826e6..e6abd7eb 100644 --- a/pom.xml +++ b/pom.xml @@ -8,16 +8,13 @@ World Management Plugin UTF-8 + UNKNOWN - OnARandomBox - http://repo.onarandombox.com/artifactory/repo - - - econ - http://pneumaticsystem.com:25578/nexus/content/repositories/bukkit-econ + pneumaticsystem + http://pneumaticsystem.com:25578/nexus/content/groups/public @@ -34,9 +31,25 @@ jenkins - http://ci.onarandombox.com + http://pneumaticsystem.com:25579 + + + + jenkins + + + env.BUILD_NUMBER + + + + ${env.BUILD_NUMBER} + + + + clean package @@ -89,7 +102,7 @@ maven-version-number - ${project.version}-${BUILD_NUMBER} + ${project.version}-${project.build.number} From f091a321742f3bdfd44c1d2707255eb4b810fd9a Mon Sep 17 00:00:00 2001 From: "main()" Date: Fri, 9 Dec 2011 16:53:50 +0100 Subject: [PATCH 15/24] Now saving mob exceptions correctly. Fixes #287 --- .../java/com/onarandombox/MultiverseCore/MVWorld.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 01699b83..ae1d0cc9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -271,9 +271,10 @@ public class MVWorld implements MultiverseWorld { @Override public boolean addToVariable(String property, String value) { + property = property.toLowerCase(); if (this.masterList.keySet().contains(property)) { - if (property.equalsIgnoreCase("animals") || property.equalsIgnoreCase("monsters")) { + if (property.equals("animals") || property.equals("monsters")) { this.masterList.get(property).add(value.toUpperCase()); this.worldSection.set(property.toLowerCase() + ".exceptions", this.masterList.get(property)); this.syncMobs(); @@ -289,15 +290,16 @@ public class MVWorld implements MultiverseWorld { @Override public boolean removeFromVariable(String property, String value) { + property = property.toLowerCase(); if (this.masterList.keySet().contains(property)) { - if (property.equalsIgnoreCase("animals") || property.equalsIgnoreCase("monsters")) { + if (property.equals("animals") || property.equals("monsters")) { this.masterList.get(property).remove(value.toUpperCase()); - this.worldSection.set("" + property.toLowerCase() + ".exceptions", this.masterList.get(property)); + this.worldSection.set(property + ".exceptions", this.masterList.get(property)); this.syncMobs(); } else { this.masterList.get(property).remove(value); - this.worldSection.set("" + property.toLowerCase(), this.masterList.get(property)); + this.worldSection.set(property, this.masterList.get(property)); } saveConfig(); return true; From 70f03e80bcfdd3adde50cd728d186204bc69ec47 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Fri, 9 Dec 2011 19:58:11 -0700 Subject: [PATCH 16/24] Update the POM to use parallelized tests. Don't try and run our cool classes. --- pom.xml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pom.xml b/pom.xml index e6abd7eb..4ff0ac85 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,26 @@ maven-source-plugin 2.1.2 + + org.apache.maven.plugins + maven-surefire-plugin + 2.11 + + methods + 10 + + **/TestCommandSender.java + **/TestInstanceCreator.java + + + + + org.apache.maven.surefire + surefire-junit47 + 2.11 + + + From a33d1420ba0e0a9ac17adeebacc093c7b35de87d Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 10 Dec 2011 00:36:40 -0700 Subject: [PATCH 17/24] Add game mode test. This test should pass, but alas it fails :( --- .../MultiverseCore/test/TestWorldStuff.java | 85 ++++++++++++++----- .../test/utils/TestCommandSender.java | 17 +--- .../test/utils/TestInstanceCreator.java | 2 +- .../test/utils/WorldCreatorMatcher.java | 4 +- 4 files changed, 73 insertions(+), 35 deletions(-) diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java index 69297887..4e389f24 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java @@ -7,15 +7,13 @@ package com.onarandombox.MultiverseCore.test; -import static junit.framework.Assert.*; -import static org.mockito.Mockito.*; - -import java.io.File; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Server; -import org.bukkit.WorldCreator; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException; +import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; +import com.onarandombox.MultiverseCore.test.utils.WorldCreatorMatcher; +import com.onarandombox.MultiverseCore.utils.WorldManager; +import org.bukkit.*; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; @@ -30,10 +28,10 @@ import org.mockito.internal.verification.VerificationModeFactory; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; -import com.onarandombox.MultiverseCore.test.utils.WorldCreatorMatcher; -import com.onarandombox.MultiverseCore.utils.WorldManager; +import java.io.File; + +import static junit.framework.Assert.*; +import static org.mockito.Mockito.*; @RunWith(PowerMockRunner.class) @PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, WorldManager.class }) @@ -76,7 +74,7 @@ public class TestWorldStuff { // Initialize a fake command Command mockCommand = mock(Command.class); when(mockCommand.getName()).thenReturn("mv"); - String[] normalArgs = new String[] { "import", "world", "normal" }; + String[] normalArgs = new String[]{ "import", "world", "normal" }; // Ensure we have a fresh copy of MV, 0 worlds. assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size()); @@ -109,21 +107,21 @@ public class TestWorldStuff { assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size()); // Import the first world. - String[] normalArgs = new String[] { "import", "world", "normal" }; + String[] normalArgs = new String[]{ "import", "world", "normal" }; plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs); // We should now have one world imported! assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size()); // Import the second world. - String[] netherArgs = new String[] { "import", "world_nether", "nether" }; + String[] netherArgs = new String[]{ "import", "world_nether", "nether" }; plugin.onCommand(mockCommandSender, mockCommand, "", netherArgs); // We should now have 2 worlds imported! assertEquals(2, creator.getCore().getMVWorldManager().getMVWorlds().size()); // Import the third world. - String[] skyArgs = new String[] { "import", "world_skylands", "end" }; + String[] skyArgs = new String[]{ "import", "world_the_end", "end" }; plugin.onCommand(mockCommandSender, mockCommand, "", skyArgs); // We should now have 2 worlds imported! @@ -132,7 +130,7 @@ public class TestWorldStuff { // Verify that the commandSender has been called 3 times. verify(mockCommandSender).sendMessage("Starting import of world 'world'..."); verify(mockCommandSender).sendMessage("Starting import of world 'world_nether'..."); - verify(mockCommandSender).sendMessage("Starting import of world 'world_skylands'..."); + verify(mockCommandSender).sendMessage("Starting import of world 'world_the_end'..."); verify(mockCommandSender, VerificationModeFactory.times(3)).sendMessage("Complete!"); } @@ -155,7 +153,7 @@ public class TestWorldStuff { assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size()); // Create the world - String[] normalArgs = new String[] { "create", "newworld", "normal" }; + String[] normalArgs = new String[]{ "create", "newworld", "normal" }; plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs); // We should now have one world! @@ -168,4 +166,53 @@ public class TestWorldStuff { WorldCreatorMatcher matcher = new WorldCreatorMatcher(new WorldCreator("newworld")); verify(mockServer).createWorld(Matchers.argThat(matcher)); } + + @Test + public void testModifyGameMode() { + // Pull a core instance from the server. + Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core"); + Command mockCommand = mock(Command.class); + when(mockCommand.getName()).thenReturn("mv"); + + // Ensure that there are no worlds imported. This is a fresh setup. + assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size()); + this.createInitialWorlds(plugin, mockCommand); + + // Ensure that the default worlds have been created. + assertEquals(3, creator.getCore().getMVWorldManager().getMVWorlds().size()); + MultiverseWorld mainWorld = creator.getCore().getMVWorldManager().getMVWorld("world"); + + // Ensure that the default mode was normal. + assertEquals(GameMode.SURVIVAL, mainWorld.getGameMode()); + + // Set the mode to creative in world. + plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "mode", "creative", "world" }); + verify(mockCommandSender).sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + "mode" + ChatColor.WHITE + " was set to " + ChatColor.GREEN + "creative"); + // Ensure the world is now a creative world + assertEquals(GameMode.CREATIVE, mainWorld.getGameMode()); + + // More tests, with alternate syntax. + plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "gamemode", "0", "world" }); + verify(mockCommandSender).sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + "gamemode" + ChatColor.WHITE + " was set to " + ChatColor.GREEN + "0"); + assertEquals(GameMode.SURVIVAL, mainWorld.getGameMode()); + + // Now fail one. + plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "mode", "fish", "world" }); + try { + verify(mockCommandSender).sendMessage(mainWorld.getProperty("mode").getHelp()); + } catch (PropertyDoesNotExistException e) { + fail("Mode property did not exist."); + } + + } + + private void createInitialWorlds(Plugin plugin, Command command) { + plugin.onCommand(mockCommandSender, command, "", new String[]{ "import", "world", "normal" }); + plugin.onCommand(mockCommandSender, command, "", new String[]{ "import", "world_nether", "nether" }); + plugin.onCommand(mockCommandSender, command, "", new String[]{ "import", "world_the_end", "end" }); + verify(mockCommandSender).sendMessage("Starting import of world 'world'..."); + verify(mockCommandSender).sendMessage("Starting import of world 'world_nether'..."); + verify(mockCommandSender).sendMessage("Starting import of world 'world_the_end'..."); + verify(mockCommandSender, times(3)).sendMessage("Complete!"); + } } diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java index 341b7045..f7ed865b 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java @@ -7,9 +7,6 @@ package com.onarandombox.MultiverseCore.test.utils; -import java.util.Set; -import java.util.logging.Logger; - import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -18,6 +15,9 @@ import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; +import java.util.Set; +import java.util.logging.Logger; + public class TestCommandSender implements CommandSender { private Server server; @@ -40,7 +40,7 @@ public class TestCommandSender implements CommandSender { */ @Override public void sendMessage(String message) { - logger.info(ChatColor.stripColor(message)); + logger.info("." + ChatColor.stripColor(message) + "."); } /** @@ -67,7 +67,6 @@ public class TestCommandSender implements CommandSender { * Checks if this object contains an override for the specified permission, by fully qualified name * * @param name Name of the permission - * * @return true if the permission is set, otherwise false */ @Override @@ -79,7 +78,6 @@ public class TestCommandSender implements CommandSender { * Checks if this object contains an override for the specified {@link org.bukkit.permissions.Permission} * * @param perm Permission to check - * * @return true if the permission is set, otherwise false */ @Override @@ -93,7 +91,6 @@ public class TestCommandSender implements CommandSender { * If a permission override is not set on this object, the default value of the permission will be returned. * * @param name Name of the permission - * * @return Value of the permission */ @Override @@ -107,7 +104,6 @@ public class TestCommandSender implements CommandSender { * If a permission override is not set on this object, the default value of the permission will be returned * * @param perm Permission to get - * * @return Value of the permission */ @Override @@ -121,7 +117,6 @@ public class TestCommandSender implements CommandSender { * @param plugin Plugin responsible for this attachment, may not be null or disabled * @param name Name of the permission to attach * @param value Value of the permission - * * @return The PermissionAttachment that was just created */ @Override @@ -133,7 +128,6 @@ public class TestCommandSender implements CommandSender { * Adds a new empty {@link org.bukkit.permissions.PermissionAttachment} to this object * * @param plugin Plugin responsible for this attachment, may not be null or disabled - * * @return The PermissionAttachment that was just created */ @Override @@ -149,7 +143,6 @@ public class TestCommandSender implements CommandSender { * @param name Name of the permission to attach * @param value Value of the permission * @param ticks Amount of ticks to automatically remove this attachment after - * * @return The PermissionAttachment that was just created */ @Override @@ -162,7 +155,6 @@ public class TestCommandSender implements CommandSender { * * @param plugin Plugin responsible for this attachment, may not be null or disabled * @param ticks Amount of ticks to automatically remove this attachment after - * * @return The PermissionAttachment that was just created */ @Override @@ -174,7 +166,6 @@ public class TestCommandSender implements CommandSender { * Removes the given {@link org.bukkit.permissions.PermissionAttachment} from this object * * @param attachment Attachment to remove - * * @throws IllegalArgumentException Thrown when the specified attachment isn't part of this object */ @Override diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java index fa3f63b1..c8c85946 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java @@ -79,7 +79,7 @@ public class TestInstanceCreator { File worldNetherFile = new File(core.getServerFolder(), "world_nether"); Util.log("Creating world-folder: " + worldNetherFile.getAbsolutePath()); worldNetherFile.mkdirs(); - File worldSkylandsFile = new File(core.getServerFolder(), "world_skylands"); + File worldSkylandsFile = new File(core.getServerFolder(), "world_the_end"); Util.log("Creating world-folder: " + worldSkylandsFile.getAbsolutePath()); worldSkylandsFile.mkdirs(); diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java index 7eeb7bcc..529906fd 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java @@ -42,10 +42,10 @@ public class WorldCreatorMatcher extends ArgumentMatcher { Util.log("Checking Environments..."); return false; } else if (careAboutSeeds && ((WorldCreator) creator).seed() != this.worldCreator.seed()) { - System.out.print("Checking Seeds..."); + Util.log("Checking Seeds..."); return false; } else if (careAboutGenerators && !((WorldCreator) creator).generator().equals(this.worldCreator.generator())) { - System.out.print("Checking Gens..."); + Util.log("Checking Gens..."); return false; } Util.log("Creators matched!!!"); From e5d468f03f3cf12d1d82d73db58c459838ef5fc5 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 10 Dec 2011 00:41:28 -0700 Subject: [PATCH 18/24] Fix properties not reporting when the value was wrong, but the key was. --- .../java/com/onarandombox/MultiverseCore/MVWorld.java | 11 ++++++++--- .../MultiverseCore/test/utils/TestCommandSender.java | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index ae1d0cc9..804fae3b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -331,10 +331,15 @@ public class MVWorld implements MultiverseWorld { // TODO: Provide better feedback @Override public boolean setProperty(String name, String value, CommandSender sender) throws PropertyDoesNotExistException { - if (this.setKnownProperty(name, value, sender) || this.setKnownProperty(this.propertyAliases.get(name), value, sender)) { - return true; + if (!this.isValidPropertyName(name)) { + throw new PropertyDoesNotExistException(name); } - throw new PropertyDoesNotExistException(name); + return this.setKnownProperty(name, value, sender) || this.setKnownProperty(this.propertyAliases.get(name), value, sender); + + } + + private boolean isValidPropertyName(String name) { + return this.propertyList.containsKey(name) || this.propertyAliases.containsKey(name); } @Override diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java index f7ed865b..f4e89a78 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java @@ -40,7 +40,7 @@ public class TestCommandSender implements CommandSender { */ @Override public void sendMessage(String message) { - logger.info("." + ChatColor.stripColor(message) + "."); + logger.info(ChatColor.stripColor(message)); } /** From d8cb6497f01f2300780c2f5263bfc2d8d914aaa8 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 10 Dec 2011 00:53:02 -0700 Subject: [PATCH 19/24] Display the spawn location when changing it. Closes #295. I'm closing this issue and "moving" the rest of it, the ability to import/create a world without using the checker to Issue #300 --- src/main/java/com/onarandombox/MultiverseCore/MVWorld.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 804fae3b..4f334795 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -661,6 +661,7 @@ public class MVWorld implements MultiverseWorld { } // If it's not, find a better one. this.plugin.log(Level.WARNING, "Spawn location from world.dat file was unsafe. Adjusting..."); + this.plugin.log(Level.WARNING, "Original Location: " + LocationManipulation.strCoordsRaw(spawnLocation)); Location newSpawn = teleporter.getSafeLocation(spawnLocation, 16, 16); // I think we could also do this, as I think this is what Notch does. // Not sure how it will work in the nether... From 0b2233cf7bc829c0d2a02f20c4503c7149a70609 Mon Sep 17 00:00:00 2001 From: "main()" Date: Sat, 10 Dec 2011 11:04:29 +0100 Subject: [PATCH 20/24] We have to use the WorldContainer in the CreateCommand, too. (This should have been changed in af439b678e546ffeb1925ee1d19d5bae7991ecb6) --- .../com/onarandombox/MultiverseCore/commands/CreateCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index fae7c8ea..9b990d3b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -46,7 +46,7 @@ public class CreateCommand extends MultiverseCommand { return; } String worldName = args.get(0); - File worldFile = new File(this.plugin.getServerFolder(), worldName); + File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName); String env = args.get(1); String seed = CommandHandler.getFlag("-s", args); String generator = CommandHandler.getFlag("-g", args); From c0ae0e3eea4a6e8c28de4f8b0fdebd976db30620 Mon Sep 17 00:00:00 2001 From: "main()" Date: Sat, 10 Dec 2011 11:21:26 +0100 Subject: [PATCH 21/24] Javadoc wants

, not

--- .../onarandombox/MultiverseCore/api/Core.java | 2 +- .../MultiverseCore/api/MVDestination.java | 26 +++++++++---------- .../MultiverseCore/api/MVWorldManager.java | 4 +-- .../MultiverseCore/api/MultiverseWorld.java | 10 +++---- .../event/MVWorldPropertyChangeEvent.java | 4 +-- .../MultiverseCore/utils/PermissionTools.java | 2 +- .../MultiverseCore/test/utils/MockBlock.java | 6 ++--- .../test/utils/TestCommandSender.java | 6 ++--- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java index a0bc591e..75cda2d3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java @@ -16,7 +16,7 @@ import org.bukkit.entity.Player; /** * Multiverse 2 Core API - *

+ *

* This API contains a bunch of useful things you can get out of Multiverse in general! */ public interface Core { diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java index b0ac0b44..fd0f6cce 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java @@ -21,7 +21,7 @@ import org.bukkit.util.Vector; public interface MVDestination { /** * Returns the identifier or prefix that is required for this destination. - *

+ *

* Portals have a prefix of "p" for example and OpenWarp (third party plugin) uses "ow". This is derived from a * hash and cannot have duplicate values. Read that as your plugin cannot use 'p' because it's already used. * Please check the wiki when adding a custom destination! @@ -32,7 +32,7 @@ public interface MVDestination { /** * Allows you to determine if a Destination is valid for the type it thinks it is. - *

+ *

* An example of this would be the exact destination. A valid string would be: e:0,0,0 where an invalid one would * be e:1:2:3. The first string would return true the second would return false. This is simply a convenience * method @@ -48,11 +48,11 @@ public interface MVDestination { /** * Returns the location a specific entity will spawn at. - *

+ *

* To just retrieve the location as it is stored you can just pass null, but be warned some destinations may return * null back to you if you do this. It is always safer to pass an actual entity. This is used so things like * minecarts can be teleported. - *

+ *

* Do not forget to use {@link #getVelocity()} as destinations can use this too! * * @param entity The entity to be teleported. @@ -63,7 +63,7 @@ public interface MVDestination { /** * Returns the velocity vector for this destination. - *

+ *

* Plugins wishing to fully support MVDestinations MUST implement this. * * @return A vector representing the speed/direction the player should travel when arriving @@ -72,7 +72,7 @@ public interface MVDestination { /** * Sets the destination string. - *

+ *

* This should be used when you want to tell this destination object about a change in where it should take people. * The destination param should be match the result from {@link #getIdentifier()}. A valid example would be that if * {@link #getIdentifier()} returned "ow" our destination string could be "ow:TownCenter" but could not be @@ -85,7 +85,7 @@ public interface MVDestination { /** * Returns true if the destination is valid and players will be taken to it. - *

+ *

* Even if destinations are in the correct format (p:MyPortal) MyPortal may not exist, and therefore this would * return false. * @@ -95,7 +95,7 @@ public interface MVDestination { /** * Gives you a general friendly description of the type of destination. - *

+ *

* For example, the PlayerDestination sets this to "Player". You can use this to show where a player will be taken. * * @return A friendly string description of the type of destination. @@ -104,7 +104,7 @@ public interface MVDestination { /** * Gives you a specific name of the destination. - *

+ *

* For example, the PlayerDestination sets this to The Player's Name. * * @return A friendly string stating the name of the destination. @@ -114,7 +114,7 @@ public interface MVDestination { /** * Returns a string that can easily be saved in the config that contains all the details needed to rebuild this * destination. - *

+ *

* ex: e:0,0,0:50:50 * * @return The savable config string. @@ -123,9 +123,9 @@ public interface MVDestination { /** * Returns the permissions string required to go here. - *

+ *

* ex: multiverse.access.world - *

+ *

* NOTE: This is NOT the permission to use the teleport command. * * @return the permissions string required to go here. @@ -134,7 +134,7 @@ public interface MVDestination { /** * Should the Multiverse SafeTeleporter be used? - *

+ *

* If not, MV will blindly take people to the location specified. * * @return True if the SafeTeleporter will be used, false if not. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java index 52c77702..086e01a1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java @@ -19,7 +19,7 @@ import java.util.List; /** * Multiverse 2 World Manager API - *

+ *

* This API contains all of the world managing * functions that your heart desires! */ @@ -142,7 +142,7 @@ public interface MVWorldManager { /** * Loads the Worlds & Settings for any worlds that bukkit loaded before us. - *

+ *

* This way people will _always_ have some worlds in the list. */ public void loadDefaultWorlds(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index d7ac5fa1..89c54b51 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -17,7 +17,7 @@ import java.util.List; /** * The API for a Multiverse Handled World. - *

+ *

* Currently INCOMPLETE */ public interface MultiverseWorld { @@ -97,7 +97,7 @@ public interface MultiverseWorld { /** * Sets the environment of a world. - *

+ *

* Note: This will ONLY take effect once the world is unloaded/reloaded. * * @param environment A {@link org.bukkit.World.Environment}. @@ -127,7 +127,7 @@ public interface MultiverseWorld { /** * Gets the alias of this world. - *

+ *

* This alias allows users to have a world named "world" but show up in the list as "FernIsland" * * @return The alias of the world as a String. @@ -472,7 +472,7 @@ public interface MultiverseWorld { /** * Sets whether or not Multiverse should auto-load this world. - *

+ *

* True is default. * * @param autoLoad True if multiverse should autoload this world the spawn, false if not. @@ -489,7 +489,7 @@ public interface MultiverseWorld { /** * Sets whether or not a player who dies in this world will respawn in their * bed or follow the normal respawn pattern. - *

+ *

* True is default. * * @param autoLoad True if players dying in this world respawn at their bed. diff --git a/src/main/java/com/onarandombox/MultiverseCore/event/MVWorldPropertyChangeEvent.java b/src/main/java/com/onarandombox/MultiverseCore/event/MVWorldPropertyChangeEvent.java index 4fadfade..6a102da8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/event/MVWorldPropertyChangeEvent.java +++ b/src/main/java/com/onarandombox/MultiverseCore/event/MVWorldPropertyChangeEvent.java @@ -14,9 +14,9 @@ import org.bukkit.event.Event; /** * This event is fired *before* the property is actually changed. - *

+ *

* If it is cancled, no change will happen. - *

+ *

* If you want to get the values of the world before the change, query the world. * If you want to get the value being changed, use getProperty() */ diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java index 056dbe94..84e9c2be 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java @@ -106,7 +106,7 @@ public class PermissionTools { /** * Checks to see if player can go to a world given their current status. - *

+ *

* The return is a little backwards, and will return a value safe for event.setCancelled. * * @param fromWorld The MultiverseWorld they are in. diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java index 3eb3b18d..9519f29b 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java @@ -263,7 +263,7 @@ public class MockBlock implements Block{ /** * Captures the current state of this block. You may then cast that state * into any accepted type, such as Furnace or Sign. - *

+ *

* The returned object will never be updated, and you are not guaranteed that * (for example) a sign is still a sign after you capture its state. * @@ -352,7 +352,7 @@ public class MockBlock implements Block{ /** * Checks if this block is empty. - *

+ *

* A block is considered empty when {@link #getType()} returns {@link org.bukkit.Material#AIR}. * * @return true if this block is empty @@ -364,7 +364,7 @@ public class MockBlock implements Block{ /** * Checks if this block is liquid. - *

+ *

* A block is considered liquid when {@link #getType()} returns {@link org.bukkit.Material#WATER}, {@link * org.bukkit.Material#STATIONARY_WATER}, {@link org.bukkit.Material#LAVA} or {@link * org.bukkit.Material#STATIONARY_LAVA}. diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java index f4e89a78..c7089599 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java @@ -87,7 +87,7 @@ public class TestCommandSender implements CommandSender { /** * Gets the value of the specified permission, if set. - *

+ *

* If a permission override is not set on this object, the default value of the permission will be returned. * * @param name Name of the permission @@ -100,7 +100,7 @@ public class TestCommandSender implements CommandSender { /** * Gets the value of the specified permission, if set. - *

+ *

* If a permission override is not set on this object, the default value of the permission will be returned * * @param perm Permission to get @@ -174,7 +174,7 @@ public class TestCommandSender implements CommandSender { /** * Recalculates the permissions for this object, if the attachments have changed values. - *

+ *

* This should very rarely need to be called from a plugin. */ @Override From c9cd2a0f5c2a7578dd5f6b7684e74deead53b7cc Mon Sep 17 00:00:00 2001 From: "main()" Date: Sat, 10 Dec 2011 21:03:38 +0100 Subject: [PATCH 22/24] Prevented properties from getting null if they were invalid in worlds.yml --- .../configuration/BooleanConfigProperty.java | 7 ++----- .../MultiverseCore/configuration/ColorConfigProperty.java | 7 ++----- .../configuration/DifficultyConfigProperty.java | 7 ++----- .../MultiverseCore/configuration/DoubleConfigProperty.java | 7 ++----- .../configuration/GameModeConfigProperty.java | 7 ++----- .../configuration/IntegerConfigProperty.java | 7 ++----- .../configuration/LocationConfigProperty.java | 7 ++----- .../MultiverseCore/configuration/StringConfigProperty.java | 7 ++----- 8 files changed, 16 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/BooleanConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/BooleanConfigProperty.java index f94e9d9e..498faea2 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/BooleanConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/BooleanConfigProperty.java @@ -17,11 +17,7 @@ public class BooleanConfigProperty implements MVConfigProperty { private String help; public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String help) { - this.name = name; - this.configNode = name; - this.section = section; - this.help = help; - this.setValue(this.section.getBoolean(this.configNode, defaultValue)); + this(section, name, defaultValue, name, help); } public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String configNode, String help) { @@ -29,6 +25,7 @@ public class BooleanConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; + this.value = defaultValue; this.setValue(this.section.getBoolean(this.configNode, defaultValue)); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/ColorConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/ColorConfigProperty.java index d9b9d5fb..7ba3c551 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/ColorConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/ColorConfigProperty.java @@ -18,11 +18,7 @@ public class ColorConfigProperty implements MVConfigProperty { private String help; public ColorConfigProperty(ConfigurationSection section, String name, EnglishChatColor defaultValue, String help) { - this.name = name; - this.configNode = name; - this.section = section; - this.help = help; - this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); + this(section, name, defaultValue, name, help); } public ColorConfigProperty(ConfigurationSection section, String name, EnglishChatColor defaultValue, String configNode, String help) { @@ -30,6 +26,7 @@ public class ColorConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; + this.value = defaultValue; this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/DifficultyConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/DifficultyConfigProperty.java index 88d9c3fc..8b0097c7 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/DifficultyConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/DifficultyConfigProperty.java @@ -18,11 +18,7 @@ public class DifficultyConfigProperty implements MVConfigProperty { private String help; public DifficultyConfigProperty(ConfigurationSection section, String name, Difficulty defaultValue, String help) { - this.name = name; - this.configNode = name; - this.section = section; - this.help = help; - this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); + this(section, name, defaultValue, name, help); } public DifficultyConfigProperty(ConfigurationSection section, String name, Difficulty defaultValue, String configNode, String help) { @@ -30,6 +26,7 @@ public class DifficultyConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; + this.value = defaultValue; this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/DoubleConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/DoubleConfigProperty.java index 197a6f2f..0cfb0122 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/DoubleConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/DoubleConfigProperty.java @@ -17,11 +17,7 @@ public class DoubleConfigProperty implements MVConfigProperty { private String help; public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String help) { - this.name = name; - this.configNode = name; - this.section = section; - this.help = help; - this.setValue(this.section.getDouble(this.configNode, defaultValue)); + this(section, name, defaultValue, name, help); } public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String configNode, String help) { @@ -29,6 +25,7 @@ public class DoubleConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; + this.value = defaultValue; this.setValue(this.section.getDouble(this.configNode, defaultValue)); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/GameModeConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/GameModeConfigProperty.java index 3603427b..976c1a88 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/GameModeConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/GameModeConfigProperty.java @@ -18,11 +18,7 @@ public class GameModeConfigProperty implements MVConfigProperty { private String help; public GameModeConfigProperty(ConfigurationSection section, String name, GameMode defaultValue, String help) { - this.name = name; - this.configNode = name; - this.section = section; - this.help = help; - this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); + this(section, name, defaultValue, name, help); } public GameModeConfigProperty(ConfigurationSection section, String name, GameMode defaultValue, String configNode, String help) { @@ -30,6 +26,7 @@ public class GameModeConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; + this.value = defaultValue; this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/IntegerConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/IntegerConfigProperty.java index 958c4312..af5b3b0a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/IntegerConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/IntegerConfigProperty.java @@ -17,11 +17,7 @@ public class IntegerConfigProperty implements MVConfigProperty { private String help; public IntegerConfigProperty(ConfigurationSection section, String name, Integer defaultValue, String help) { - this.name = name; - this.configNode = name; - this.section = section; - this.help = help; - this.setValue(this.section.getInt(this.configNode, defaultValue)); + this(section, name, defaultValue, name, help); } public IntegerConfigProperty(ConfigurationSection section, String name, Integer defaultValue, String configNode, String help) { @@ -29,6 +25,7 @@ public class IntegerConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; + this.value = defaultValue; this.setValue(this.section.getInt(this.configNode, defaultValue)); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java index df6bc64c..ef886e64 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java @@ -19,11 +19,7 @@ public class LocationConfigProperty implements MVConfigProperty { private String help; public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String help) { - this.name = name; - this.configNode = name; - this.section = section; - this.help = help; - this.setValue(this.getLocationFromConfig(defaultValue)); + this(section, name, defaultValue, name, help); } public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode, String help) { @@ -31,6 +27,7 @@ public class LocationConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; + this.value = defaultValue; this.setValue(this.getLocationFromConfig(defaultValue)); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/StringConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/StringConfigProperty.java index bbfddc4d..69e2afde 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/StringConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/StringConfigProperty.java @@ -17,11 +17,7 @@ public class StringConfigProperty implements MVConfigProperty { private String help; public StringConfigProperty(ConfigurationSection section, String name, String defaultValue, String help) { - this.name = name; - this.configNode = name; - this.section = section; - this.help = help; - this.parseValue(this.section.getString(this.configNode, defaultValue)); + this(section, name, defaultValue, defaultValue, help); } public StringConfigProperty(ConfigurationSection section, String name, String defaultValue, String configNode, String help) { @@ -29,6 +25,7 @@ public class StringConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; + this.value = defaultValue; this.parseValue(this.section.getString(this.configNode, defaultValue)); } From d40ae35505e6d2c1c17f414b264bf665bdf55931 Mon Sep 17 00:00:00 2001 From: "main()" Date: Sat, 10 Dec 2011 21:04:34 +0100 Subject: [PATCH 23/24] The config was awesome, but now it's REALLY AWESOME. Java generics might be weak, but they can avoid permanent casting, resulting in better code :D --- .../onarandombox/MultiverseCore/MVWorld.java | 99 ++++++++++--------- .../MultiverseCore/api/MultiverseWorld.java | 13 +++ .../commands/ModifySetCommand.java | 2 +- .../MultiverseCore/test/TestWorldStuff.java | 2 +- 4 files changed, 70 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 4f334795..c72df15e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -109,7 +109,7 @@ public class MVWorld implements MultiverseWorld { this.propertyList.put("spawn", fac.getNewProperty("spawn", this.world.getSpawnLocation(), "There is no help available for this variable. Go bug Rigby90 about it.")); this.propertyList.put("autoload", fac.getNewProperty("autoload", true, "Set this to false ONLY if you don't want this world to load itself on server restart.")); this.propertyList.put("bedrespawn", fac.getNewProperty("bedrespawn", true, "If a player dies in this world, shoudld they go to their bed?")); - ((LocationConfigProperty) this.getKnownProperty("spawn")).setValue(this.readSpawnFromConfig(this.getCBWorld())); + this.getKnownProperty("spawn", Location.class).setValue(this.readSpawnFromConfig(this.getCBWorld())); // Set aliases @@ -144,28 +144,28 @@ public class MVWorld implements MultiverseWorld { public void changeActiveEffects() { // Disable any current weather - if (!(Boolean) this.getKnownProperty("weather").getValue()) { + if (!this.getKnownProperty("weather", Boolean.class).getValue()) { this.getCBWorld().setStorm(false); this.getCBWorld().setThundering(false); } // Set the spawn location - Location spawnLocation = ((LocationConfigProperty) this.getKnownProperty("spawn")).getValue(); + Location spawnLocation = this.getKnownProperty("spawn", Location.class).getValue(); this.getCBWorld().setSpawnLocation(spawnLocation.getBlockX(), spawnLocation.getBlockY(), spawnLocation.getBlockZ()); // Syncronize all Mob settings this.syncMobs(); // Ensure the memory setting is correct - this.world.setKeepSpawnInMemory(((BooleanConfigProperty) this.getKnownProperty("memory")).getValue()); + this.world.setKeepSpawnInMemory(this.getKnownProperty("memory", Boolean.class).getValue()); // Set the PVP mode - this.world.setPVP(((BooleanConfigProperty) this.getKnownProperty("pvp")).getValue()); + this.world.setPVP(this.getKnownProperty("pvp", Boolean.class).getValue()); // Ensure the scale is above 0 - if (((DoubleConfigProperty) this.getKnownProperty("scale")).getValue() <= 0) { + if (this.getKnownProperty("scale", Double.class).getValue() <= 0) { // Disallow negative or 0 scalings. - ((DoubleConfigProperty) this.getKnownProperty("scale")).setValue(1.0); + this.getKnownProperty("scale", Double.class).setValue(1.0); this.plugin.log(Level.WARNING, "Someone tried to set a scale <= 0, defaulting to 1."); } @@ -173,13 +173,13 @@ public class MVWorld implements MultiverseWorld { // TODO: Move this to a per world gamemode if (MultiverseCore.EnforceGameModes) { for (Player p : this.plugin.getServer().getWorld(this.getName()).getPlayers()) { - this.plugin.log(Level.FINER, "Setting " + p.getName() + "'s GameMode to " + this.getKnownProperty("mode").getValue().toString()); + this.plugin.log(Level.FINER, "Setting " + p.getName() + "'s GameMode to " + this.getKnownProperty("mode", GameMode.class).getValue().toString()); this.plugin.getPlayerListener().handleGameMode(p, this); } } // Set the difficulty - this.getCBWorld().setDifficulty(((DifficultyConfigProperty) this.getKnownProperty("diff")).getValue()); + this.getCBWorld().setDifficulty(this.getKnownProperty("diff", Difficulty.class).getValue()); } private double getDefaultScale(Environment environment) { @@ -216,8 +216,8 @@ public class MVWorld implements MultiverseWorld { } public String getColoredWorldString() { - EnglishChatColor worldColor = ((ColorConfigProperty) this.getKnownProperty("color")).getValue(); - String alias = ((StringConfigProperty) this.getKnownProperty("alias")).getValue(); + EnglishChatColor worldColor = this.getKnownProperty("color", EnglishChatColor.class).getValue(); + String alias = this.getKnownProperty("alias", String.class).getValue(); if (worldColor == null) { this.setKnownProperty("color", "WHITE", null); return alias + ChatColor.WHITE; @@ -310,12 +310,12 @@ public class MVWorld implements MultiverseWorld { private void syncMobs() { if (this.getAnimalList().isEmpty()) { - this.world.setSpawnFlags(this.world.getAllowMonsters(), ((BooleanConfigProperty) this.getKnownProperty("animals")).getValue()); + this.world.setSpawnFlags(this.world.getAllowMonsters(), this.getKnownProperty("animals", Boolean.class).getValue()); } else { this.world.setSpawnFlags(this.world.getAllowMonsters(), true); } if (this.getMonsterList().isEmpty()) { - this.world.setSpawnFlags(((BooleanConfigProperty) this.getKnownProperty("monsters")).getValue(), this.world.getAllowAnimals()); + this.world.setSpawnFlags(this.getKnownProperty("monsters", Boolean.class).getValue(), this.world.getAllowAnimals()); } else { this.world.setSpawnFlags(true, this.world.getAllowAnimals()); } @@ -324,7 +324,7 @@ public class MVWorld implements MultiverseWorld { @Override public void setKeepSpawnInMemory(boolean value) { - ((BooleanConfigProperty) this.getKnownProperty("memory")).setValue(value); + this.getKnownProperty("memory", Boolean.class).setValue(value); saveConfig(); } @@ -345,14 +345,20 @@ public class MVWorld implements MultiverseWorld { @Override public String getPropertyValue(String name) throws PropertyDoesNotExistException { if (this.propertyList.containsKey(name)) { - return this.getKnownProperty(name).toString(); + return this.getKnownProperty(name, Object.class).toString(); } throw new PropertyDoesNotExistException(name); } @Override - public MVConfigProperty getProperty(String name) throws PropertyDoesNotExistException { - MVConfigProperty p = this.getKnownProperty(name); + @Deprecated + public MVConfigProperty getProperty(String property) throws PropertyDoesNotExistException { + return getProperty(property, Object.class); + } + + @Override + public MVConfigProperty getProperty(String name, Class expected) throws PropertyDoesNotExistException { + MVConfigProperty p = this.getKnownProperty(name, expected); if (p == null) { throw new PropertyDoesNotExistException(name); } @@ -363,14 +369,19 @@ public class MVWorld implements MultiverseWorld { * This method should only be used from inside this class when it is KNOWN that the property exists. * * @param name The known name of a property + * @param expected The Type of the expected value * @return The property object. */ - private MVConfigProperty getKnownProperty(String name) { - if (this.propertyList.containsKey(name)) { - return this.propertyList.get(name); - } else if (this.propertyAliases.containsKey(name)) { - // If the property was defined in the alias table, make sure to grab the actual name - return this.propertyList.get(this.propertyAliases.get(name)); + @SuppressWarnings("unchecked") + private MVConfigProperty getKnownProperty(String name, Class expected) { + try { + if (this.propertyList.containsKey(name)) { + return (MVConfigProperty) this.propertyList.get(name); + } else if (this.propertyAliases.containsKey(name)) { + // If the property was defined in the alias table, make sure to grab the actual name + return (MVConfigProperty) this.propertyList.get(this.propertyAliases.get(name)); + } + } catch (ClassCastException e) { } return null; } @@ -386,7 +397,7 @@ public class MVWorld implements MultiverseWorld { private boolean setKnownProperty(String name, String value, CommandSender sender) { MVConfigProperty property; if (this.propertyList.containsKey(name)) { - property = this.getKnownProperty(name); + property = this.getKnownProperty(name, Object.class); } else if (this.propertyAliases.containsKey(name)) { return this.setKnownProperty(this.propertyAliases.get(name), value, sender); } else { @@ -441,7 +452,7 @@ public class MVWorld implements MultiverseWorld { @Override public String getAlias() { - String alias = ((StringConfigProperty) this.getKnownProperty("alias")).getValue(); + String alias = this.getKnownProperty("alias", String.class).getValue(); if (alias == null || alias.length() == 0) { return this.name; } @@ -456,7 +467,7 @@ public class MVWorld implements MultiverseWorld { @Override public boolean canAnimalsSpawn() { - return ((BooleanConfigProperty) this.getKnownProperty("animals")).getValue(); + return this.getKnownProperty("animals", Boolean.class).getValue(); } @Override @@ -471,7 +482,7 @@ public class MVWorld implements MultiverseWorld { @Override public boolean canMonstersSpawn() { - return ((BooleanConfigProperty) this.getKnownProperty("monsters")).getValue(); + return this.getKnownProperty("monsters", Boolean.class).getValue(); } @Override @@ -486,7 +497,7 @@ public class MVWorld implements MultiverseWorld { @Override public boolean isPVPEnabled() { - return ((BooleanConfigProperty) this.getKnownProperty("pvp")).getValue(); + return this.getKnownProperty("pvp", Boolean.class).getValue(); } @Override @@ -496,7 +507,7 @@ public class MVWorld implements MultiverseWorld { @Override public boolean isHidden() { - return ((BooleanConfigProperty) this.getKnownProperty("hidden")).getValue(); + return this.getKnownProperty("hidden", Boolean.class).getValue(); } @Override @@ -510,7 +521,7 @@ public class MVWorld implements MultiverseWorld { @Override public double getScaling() { - return ((DoubleConfigProperty) this.getKnownProperty("scale")).getValue(); + return this.getKnownProperty("scale", Double.class).getValue(); } @Override @@ -529,7 +540,7 @@ public class MVWorld implements MultiverseWorld { @Override public ChatColor getColor() { - return ((ColorConfigProperty) this.getKnownProperty("color")).getValue().getColor(); + return this.getKnownProperty("color", EnglishChatColor.class).getValue().getColor(); } public boolean clearList(String property) { @@ -550,7 +561,7 @@ public class MVWorld implements MultiverseWorld { @Override public World getRespawnToWorld() { - return (this.plugin.getServer().getWorld(((StringConfigProperty) this.getKnownProperty("respawn")).getValue())); + return (this.plugin.getServer().getWorld(this.getKnownProperty("respawn", String.class).getValue())); } @Override @@ -565,7 +576,7 @@ public class MVWorld implements MultiverseWorld { @Override public int getCurrency() { - return ((IntegerConfigProperty) this.getKnownProperty("curr")).getValue(); + return this.getKnownProperty("curr", Integer.class).getValue(); } @Override @@ -575,7 +586,7 @@ public class MVWorld implements MultiverseWorld { @Override public double getPrice() { - return ((DoubleConfigProperty) this.getKnownProperty("price")).getValue(); + return this.getKnownProperty("price", Double.class).getValue(); } @Override @@ -606,7 +617,7 @@ public class MVWorld implements MultiverseWorld { @Override public GameMode getGameMode() { - return ((GameModeConfigProperty) this.getKnownProperty("mode")).getValue(); + return this.getKnownProperty("mode", GameMode.class).getValue(); } @Override @@ -616,12 +627,12 @@ public class MVWorld implements MultiverseWorld { @Override public boolean isWeatherEnabled() { - return ((BooleanConfigProperty) this.getKnownProperty("weather")).getValue(); + return this.getKnownProperty("weather", Boolean.class).getValue(); } @Override public boolean isKeepingSpawnInMemory() { - return ((BooleanConfigProperty) this.getKnownProperty("memory")).getValue(); + return this.getKnownProperty("memory", Boolean.class).getValue(); } @Override @@ -631,13 +642,13 @@ public class MVWorld implements MultiverseWorld { @Override public boolean getHunger() { - return ((BooleanConfigProperty) this.getKnownProperty("hunger")).getValue(); + return this.getKnownProperty("hunger", Boolean.class).getValue(); } @Override public void setSpawnLocation(Location l) { this.getCBWorld().setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - ((LocationConfigProperty) this.getKnownProperty("spawn")).setValue(l); + this.getKnownProperty("spawn", Location.class).setValue(l); this.saveConfig(); } @@ -690,7 +701,7 @@ public class MVWorld implements MultiverseWorld { @Override public Location getSpawnLocation() { - return ((LocationConfigProperty) this.getKnownProperty("spawn")).getValue(); + return this.getKnownProperty("spawn", Location.class).getValue(); } @Override @@ -705,7 +716,7 @@ public class MVWorld implements MultiverseWorld { @Override public boolean getAutoHeal() { - return ((BooleanConfigProperty) this.getKnownProperty("autoheal")).getValue(); + return this.getKnownProperty("autoheal", Boolean.class).getValue(); } @Override @@ -720,7 +731,7 @@ public class MVWorld implements MultiverseWorld { @Override public boolean getAdjustSpawn() { - return ((BooleanConfigProperty) this.getKnownProperty("adjustspawn")).getValue(); + return this.getKnownProperty("adjustspawn", Boolean.class).getValue(); } @Override @@ -730,7 +741,7 @@ public class MVWorld implements MultiverseWorld { @Override public boolean getAutoLoad() { - return ((BooleanConfigProperty) this.getKnownProperty("autoload")).getValue(); + return this.getKnownProperty("autoload", Boolean.class).getValue(); } @Override @@ -740,7 +751,7 @@ public class MVWorld implements MultiverseWorld { @Override public boolean getBedRespawn() { - return ((BooleanConfigProperty) this.getKnownProperty("bedrespawn")).getValue(); + return this.getKnownProperty("bedrespawn", Boolean.class).getValue(); } @Override diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index 89c54b51..fb7d1a7c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -48,7 +48,9 @@ public interface MultiverseWorld { * @param property The name of a world property to get. * @return A valid MVWorldProperty. * @throws PropertyDoesNotExistException Thrown if the property was not found in the world. + * @deprecated Use {@link #getProperty(String, Class)} instead */ + @Deprecated public MVConfigProperty getProperty(String property) throws PropertyDoesNotExistException; /** @@ -61,6 +63,17 @@ public interface MultiverseWorld { */ public String getPropertyValue(String property) throws PropertyDoesNotExistException; + /** + * Gets the actual MVConfigProperty from this world. + * It will throw a PropertyDoesNotExistException if the property is not found. + * + * @param property The name of a world property to get. + * @param expected The type of the expected property. Use Object.class if this doesn't matter for you. + * @return A valid MVWorldProperty. + * @throws PropertyDoesNotExistException Thrown if the property was not found in the world. + */ + public MVConfigProperty getProperty(String property, Class expected) throws PropertyDoesNotExistException; + /** * Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java index 45203998..7ffc5cc0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java @@ -107,7 +107,7 @@ public class ModifySetCommand extends MultiverseCommand { if (world.setProperty(property, value, sender)) { sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value); } else { - sender.sendMessage(world.getProperty(property).getHelp()); + sender.sendMessage(world.getProperty(property, Object.class).getHelp()); } } catch (PropertyDoesNotExistException e) { sender.sendMessage(ChatColor.RED + "Sorry, You can't set: '" + ChatColor.GRAY + property + ChatColor.RED + "'"); diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java index 4e389f24..832c7dbe 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java @@ -199,7 +199,7 @@ public class TestWorldStuff { // Now fail one. plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "mode", "fish", "world" }); try { - verify(mockCommandSender).sendMessage(mainWorld.getProperty("mode").getHelp()); + verify(mockCommandSender).sendMessage(mainWorld.getProperty("mode", Object.class).getHelp()); } catch (PropertyDoesNotExistException e) { fail("Mode property did not exist."); } From ea6b02085029e1b34edf747a6d8c1fc3284dbe67 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 10 Dec 2011 14:15:18 -0700 Subject: [PATCH 24/24] Add test for Failure to select a valid command --- .../com/onarandombox/MultiverseCore/test/TestWorldStuff.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java index 4e389f24..48419a24 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java @@ -204,6 +204,9 @@ public class TestWorldStuff { fail("Mode property did not exist."); } + plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "blah", "fish", "world" }); + verify(mockCommandSender).sendMessage(ChatColor.RED + "Sorry, You can't set: '"+ChatColor.GRAY+ "blah" + ChatColor.RED + "'"); + } private void createInitialWorlds(Plugin plugin, Command command) {