From abb58b0563637dfa2ea8589c447d219b14de2d49 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Fri, 2 Dec 2011 18:19:26 -0700 Subject: [PATCH] Pull changes from master. --- pom.xml | 50 ++++-- .../onarandombox/MultiverseCore/MVWorld.java | 127 ++++++++------- .../MultiverseCore/MultiverseCore.java | 42 +++-- .../onarandombox/MultiverseCore/api/Core.java | 2 +- .../MultiverseCore/api/MVDestination.java | 26 +-- .../MultiverseCore/api/MVWorldManager.java | 4 +- .../MultiverseCore/api/MultiverseWorld.java | 25 ++- .../commands/CreateCommand.java | 3 +- .../commands/ImportCommand.java | 2 +- .../MultiverseCore/commands/ListCommand.java | 18 ++- .../commands/ModifyClearCommand.java | 1 - .../commands/ModifySetCommand.java | 3 +- .../MultiverseCore/commands/WhoCommand.java | 3 +- .../configuration/BooleanConfigProperty.java | 7 +- .../configuration/ColorConfigProperty.java | 7 +- .../DifficultyConfigProperty.java | 7 +- .../configuration/DoubleConfigProperty.java | 7 +- .../configuration/GameModeConfigProperty.java | 7 +- .../configuration/IntegerConfigProperty.java | 7 +- .../configuration/LocationConfigProperty.java | 28 ++-- .../configuration/MVConfigMigrator.java | 1 + .../configuration/StringConfigProperty.java | 7 +- .../MultiverseCore/event/MVTeleportEvent.java | 4 +- .../event/MVWorldPropertyChangeEvent.java | 4 +- .../listeners/MVEntityListener.java | 3 - .../listeners/MVPlayerListener.java | 3 - .../localization/MultiverseMessage.java | 10 +- .../localization/SimpleMessageProvider.java | 1 - .../MultiverseCore/utils/AnchorManager.java | 4 +- .../MultiverseCore/utils/BlockSafety.java | 14 +- .../utils/LocationManipulation.java | 153 +++++++++--------- .../MultiverseCore/utils/MVPermissions.java | 15 +- .../MultiverseCore/utils/MVPlayerSession.java | 2 - .../MultiverseCore/utils/PermissionTools.java | 2 +- .../MultiverseCore/utils/UpdateChecker.java | 7 +- .../utils/webpaste/PastebinPasteService.java | 1 - src/main/resources/localization/en.yml | 18 ++- .../MultiverseCore/test/TestLocalization.java | 7 + .../MultiverseCore/test/TestWorldStuff.java | 94 ++++++++--- .../MultiverseCore/test/utils/MockBlock.java | 6 +- .../test/utils/TestCommandSender.java | 21 +-- .../test/utils/TestInstanceCreator.java | 4 +- .../test/utils/WorldCreatorMatcher.java | 4 +- 43 files changed, 429 insertions(+), 332 deletions(-) diff --git a/pom.xml b/pom.xml index a3748cc0..4ff0ac85 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ - OnARandomBox - http://repo.onarandombox.com/artifactory/repo + pneumaticsystem + http://pneumaticsystem.com:25578/nexus/content/groups/public @@ -31,9 +31,25 @@ jenkins - http://ci.onarandombox.com + http://pneumaticsystem.com:25579 + + + + jenkins + + + env.BUILD_NUMBER + + + + ${env.BUILD_NUMBER} + + + + clean package @@ -109,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 + + + @@ -187,10 +223,9 @@ - org.junit + junit junit 4.8.2 - test org.powermock @@ -219,11 +254,6 @@ 3.0 test - - junit - junit - 4.8.1 - diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 8df6bc31..c72df15e 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 @@ -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; @@ -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; @@ -308,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()); } @@ -322,30 +324,41 @@ 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(); } // 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 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); } @@ -356,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; } @@ -377,9 +395,9 @@ 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); + property = this.getKnownProperty(name, Object.class); } else if (this.propertyAliases.containsKey(name)) { return this.setKnownProperty(this.propertyAliases.get(name), value, sender); } else { @@ -434,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; } @@ -449,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 @@ -464,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 @@ -479,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 @@ -489,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 @@ -503,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 @@ -522,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) { @@ -543,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 @@ -558,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 @@ -568,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 @@ -599,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 @@ -609,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 @@ -624,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(); } @@ -654,6 +672,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... @@ -682,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 @@ -697,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 @@ -712,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 @@ -722,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 @@ -732,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/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index d2bffb83..f583f416 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -19,7 +19,9 @@ import com.onarandombox.MultiverseCore.listeners.MVEntityListener; import com.onarandombox.MultiverseCore.listeners.MVPlayerListener; import com.onarandombox.MultiverseCore.listeners.MVPluginListener; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; -import com.onarandombox.MultiverseCore.localization.*; +import com.onarandombox.MultiverseCore.localization.MessageProvider; +import com.onarandombox.MultiverseCore.localization.MessageProviding; +import com.onarandombox.MultiverseCore.localization.SimpleMessageProvider; import com.onarandombox.MultiverseCore.utils.*; import com.pneumaticraft.commandhandler.CommandHandler; import org.bukkit.ChatColor; @@ -36,7 +38,8 @@ import org.bukkit.event.Event.Priority; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import java.io.*; +import java.io.File; +import java.io.IOException; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -55,11 +58,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag /** * 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)) { + if (teleportQueue.containsKey(playerName)) { String teleportee = teleportQueue.get(playerName); teleportQueue.remove(playerName); return teleportee; @@ -201,7 +205,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag this.log(Level.SEVERE, "Your configs were not loaded. Very little will function in Multiverse."); } this.anchorManager.loadAnchors(); - this.messageProvider.setLocale(new Locale(multiverseConfig.getString("locale", "en"))); + try { + this.messageProvider.setLocale(new Locale(multiverseConfig.getString("locale", "en"))); + } catch (IllegalArgumentException e) { + this.log(Level.SEVERE, e.getMessage()); + this.getServer().getPluginManager().disablePlugin(this); + } } private boolean validateAllpay() { @@ -218,6 +227,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag return false; } } catch (Throwable t) { + //TODO: Deal with this. It's bad. } log.info(tag + " - Version " + this.getDescription().getVersion() + " was NOT ENABLED!!!"); log.info(tag + " A plugin that has loaded before " + this.getDescription().getName() + " has an incompatible version of AllPay!"); @@ -240,6 +250,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag return false; } } catch (Throwable t) { + //TODO: Deal with this. It's bad. } log.info(tag + " - Version " + this.getDescription().getVersion() + " was NOT ENABLED!!!"); log.info(tag + " A plugin that has loaded before " + this.getDescription().getName() + " has an incompatible version of CommandHandler (an internal library)!"); @@ -374,9 +385,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag } /** - * Grab and return the Teleport class. + * Grab and return the {@link SafeTTeleporter}. * - * @return + * @return The {@link SafeTTeleporter}. */ public SafeTTeleporter getTeleporter() { return new SafeTTeleporter(this); @@ -409,8 +420,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag * 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); @@ -436,8 +447,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag * 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); @@ -447,7 +458,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag /** * Parse the Authors Array into a readable String with ',' and 'and'. * - * @return + * @return The readable authors-{@link String} */ private String getAuthors() { String authors = ""; @@ -480,9 +491,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag /** * 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 @@ -517,7 +525,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag /** * 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/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 e4915aff..fb7d1a7c 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 { @@ -48,8 +48,10 @@ 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 */ - public MVConfigProperty getProperty(String property) throws PropertyDoesNotExistException; + @Deprecated + public MVConfigProperty getProperty(String property) throws PropertyDoesNotExistException; /** * Gets the string representation of a property. @@ -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}. * @@ -97,7 +110,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 +140,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 +485,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 +502,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/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index 0283eb27..9b990d3b 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; @@ -47,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); 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; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java index 657b2c09..ee58368d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java @@ -9,7 +9,8 @@ package com.onarandombox.MultiverseCore.commands; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.pneumaticraft.commandhandler.Command; +import com.onarandombox.MultiverseCore.localization.MessageProvider; +import com.onarandombox.MultiverseCore.localization.MultiverseMessage; import org.bukkit.ChatColor; import org.bukkit.World.Environment; import org.bukkit.command.CommandSender; @@ -21,15 +22,18 @@ import java.util.List; public class ListCommand extends PaginatedCoreCommand { + private MessageProvider provider; + public ListCommand(MultiverseCore plugin) { super(plugin); - this.setName("World Listing"); + provider = plugin.getMessageProvider(); + this.setName(provider.getMessage(MultiverseMessage.LIST_NAME)); this.setCommandUsage("/mv list"); this.setArgRange(0, 2); this.addKey("mvlist"); this.addKey("mvl"); this.addKey("mv list"); - this.setPermission("multiverse.core.list.worlds", "Displays a listing of all worlds that you can enter.", PermissionDefault.OP); + this.setPermission("multiverse.core.list.worlds", provider.getMessage(MultiverseMessage.LIST_DESC), PermissionDefault.OP); this.setItemsPerPage(8); } @@ -62,7 +66,7 @@ public class ListCommand extends PaginatedCoreCommand { } for (String name : this.plugin.getMVWorldManager().getUnloadedWorlds()) { if (p == null || this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + name, true)) { - worldList.add(ChatColor.GRAY + name + " - UNLOADED"); + worldList.add(ChatColor.GRAY + name + " - " + provider.getMessage(MultiverseMessage.GENERIC_UNLOADED)); } } return worldList; @@ -87,7 +91,7 @@ public class ListCommand extends PaginatedCoreCommand { @Override public void runCommand(CommandSender sender, List args) { - sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse World List ]===="); + sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ " + this.provider.getMessage(MultiverseMessage.LIST_TITLE) + " ]===="); Player p = null; if (sender instanceof Player) { p = (Player) sender; @@ -100,7 +104,7 @@ public class ListCommand extends PaginatedCoreCommand { if (filterObject.getFilter().length() > 0) { availableWorlds = this.getFilteredItems(availableWorlds, filterObject.getFilter()); if (availableWorlds.size() == 0) { - sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No worlds matched your filter: " + ChatColor.AQUA + filterObject.getFilter()); + sender.sendMessage(ChatColor.RED + provider.getMessage(MultiverseMessage.GENERIC_SORRY) + " " + ChatColor.WHITE + provider.getMessage(MultiverseMessage.LIST_NO_MATCH) + " " + ChatColor.AQUA + filterObject.getFilter()); return; } } @@ -118,7 +122,7 @@ public class ListCommand extends PaginatedCoreCommand { filterObject.setPage(totalPages); } - sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages); + sender.sendMessage(ChatColor.AQUA + " " + provider.getMessage(MultiverseMessage.GENERIC_PAGE) + " " + filterObject.getPage() + " " + provider.getMessage(MultiverseMessage.GENERIC_OF) + " " + totalPages); this.showPage(filterObject.getPage(), sender, availableWorlds); } 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..7ffc5cc0 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; @@ -108,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/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java index 82a66fb3..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; @@ -92,7 +91,7 @@ public class WhoCommand extends MultiverseCommand { result = "Empty"; } else { for (Player player : players) { - result += player.getDisplayName() + " "; + result += player.getDisplayName() + " " + ChatColor.WHITE; } } 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 49ace4a0..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(this.configNode, defaultValue)); + this(section, name, defaultValue, name, help); } public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode, String help) { @@ -31,7 +27,8 @@ public class LocationConfigProperty implements MVConfigProperty { this.configNode = configNode; this.section = section; this.help = help; - this.setValue(this.getLocationFromConfig(this.configNode, defaultValue)); + this.value = defaultValue; + this.setValue(this.getLocationFromConfig(defaultValue)); } @Override @@ -46,7 +43,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); } @@ -77,17 +74,18 @@ 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; } - 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/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(); 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)); } 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/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/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/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/localization/MultiverseMessage.java b/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java index 0a3ea57e..dc97c136 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java +++ b/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java @@ -4,7 +4,15 @@ package com.onarandombox.MultiverseCore.localization; * An enum containing all messages/strings used by Multiverse. */ public enum MultiverseMessage { - TEST_STRING("a test-string from the enum"); + TEST_STRING("a test-string from the enum"), + LIST_NAME("World Listing"), + LIST_TITLE("Multiverse World List"), + LIST_DESC("Displays a listing of all worlds that you can enter."), + LIST_NO_MATCH("No worlds matched your filter:"), + GENERIC_SORRY("Sorry..."), + GENERIC_OF("of"), + GENERIC_PAGE("Page"), + GENERIC_UNLOADED("UNLOADED"); private final String def; diff --git a/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java b/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java index c4a1dece..bc35bedc 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java +++ b/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java @@ -143,7 +143,6 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider { public void setLocale(Locale locale) { if (locale == null) throw new IllegalArgumentException("Can't set locale to null!"); - try { maybeLoadLocale(locale); } catch (LocalizationLoadingException e) { 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/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 0b380ef9..fb44f105 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,51 +36,80 @@ 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[3]); + } + return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch); + } catch (NumberFormatException e) { + return null; + } } /** * 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 = ""; @@ -97,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 = ""; @@ -116,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; @@ -146,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) { @@ -164,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()); @@ -177,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) { @@ -209,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(); @@ -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; - } - } } 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/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/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); 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 { diff --git a/src/main/resources/localization/en.yml b/src/main/resources/localization/en.yml index ab9b410f..892c1e65 100644 --- a/src/main/resources/localization/en.yml +++ b/src/main/resources/localization/en.yml @@ -1 +1,17 @@ -TEST_STRING: a test-string from the resource \ No newline at end of file +TEST_STRING: a test-string from the resource + +# Generic Strings +GENERIC_SORRY: Sorry... +GENERIC_PAGE: Page +GENERIC_OF: of +GENERIC_UNLOADED: UNLOADED + +# Commands + +# List Command +LIST_NAME: World Listing +LIST_DESC: Displays a listing of all worlds that you can enter. + +LIST_TITLE: Multiverse World List +LIST_NO_MATCH: No worlds matched your filter: + diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestLocalization.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestLocalization.java index a4b46c1a..f2b7c7a7 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestLocalization.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestLocalization.java @@ -1,3 +1,10 @@ +/****************************************************************************** + * Multiverse 2 Copyright (c) the Multiverse Team 2011. * + * Multiverse 2 is licensed under the BSD License. * + * For more information please check the README.md file included * + * with this project. * + ******************************************************************************/ + package com.onarandombox.MultiverseCore.test; import static org.junit.Assert.*; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java index 31536bba..5076d8f5 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,18 +28,18 @@ 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 }) public class TestWorldStuff { - TestInstanceCreator creator; - Server mockServer; - CommandSender mockCommandSender; + private TestInstanceCreator creator; + private Server mockServer; + private CommandSender mockCommandSender; @Before public void setUp() throws Exception { @@ -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,56 @@ 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", Object.class).getHelp()); + } catch (PropertyDoesNotExistException e) { + 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) { + 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/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 341b7045..c7089599 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; @@ -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 @@ -89,11 +87,10 @@ 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 - * * @return Value of the permission */ @Override @@ -103,11 +100,10 @@ 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 - * * @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 @@ -183,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 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 3463ebb7..f936c19c 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java @@ -46,6 +46,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 { @@ -81,7 +82,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(); @@ -90,6 +91,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() { 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!!!");