From 7d1c47c2fced6ddc33e970d41195600b5bd44bc5 Mon Sep 17 00:00:00 2001 From: Jeremy Wood Date: Tue, 13 Nov 2012 17:30:35 -0500 Subject: [PATCH] Shifted world properties to its own class WorldProperties so we can now only initialize an MVWorld if there is a 'more solid' world reference. Let's hope this works! Should fix #947 --- .../onarandombox/MultiverseCore/MVWorld.java | 728 ++++++------------ .../MultiverseCore/MultiverseCore.java | 13 +- .../MultiverseCore/WorldProperties.java | 616 +++++++++++++++ .../MultiverseCore/api/MVPlugin.java | 4 +- .../MultiverseCore/utils/WorldManager.java | 45 +- .../{test => }/TestDebugMode.java | 21 +- .../{test => }/TestEntitySpawnRules.java | 26 +- .../{test => }/TestModifyCommand.java | 13 +- .../{test => }/TestWorldProperties.java | 9 +- .../{test => }/TestWorldPurger.java | 18 +- .../{test => }/TestWorldStuff.java | 13 +- .../{test => }/utils/MVTestLogFormatter.java | 2 +- .../{test => }/utils/MockWorldFactory.java | 20 +- .../{test => }/utils/TestInstanceCreator.java | 4 +- .../MultiverseCore/{test => }/utils/Util.java | 2 +- .../{test => }/utils/WorldCreatorMatcher.java | 2 +- 16 files changed, 937 insertions(+), 599 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/WorldProperties.java rename src/test/java/com/onarandombox/MultiverseCore/{test => }/TestDebugMode.java (94%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/TestEntitySpawnRules.java (96%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/TestModifyCommand.java (89%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/TestWorldProperties.java (98%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/TestWorldPurger.java (95%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/TestWorldStuff.java (97%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/utils/MVTestLogFormatter.java (96%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/utils/MockWorldFactory.java (99%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/utils/TestInstanceCreator.java (98%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/utils/Util.java (97%) rename src/test/java/com/onarandombox/MultiverseCore/{test => }/utils/WorldCreatorMatcher.java (97%) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 0f266271..36694d94 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -11,21 +11,13 @@ import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.api.BlockSafety; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.SafeTTeleporter; -import com.onarandombox.MultiverseCore.configuration.EntryFee; import com.onarandombox.MultiverseCore.configuration.SpawnLocation; -import com.onarandombox.MultiverseCore.configuration.SpawnSettings; import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator; import com.onarandombox.MultiverseCore.enums.AllowedPortalType; import com.onarandombox.MultiverseCore.enums.EnglishChatColor; -import com.onarandombox.MultiverseCore.enums.EnglishChatStyle; import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException; import me.main__.util.SerializationConfig.ChangeDeniedException; -import me.main__.util.SerializationConfig.IllegalPropertyValueException; import me.main__.util.SerializationConfig.NoSuchPropertyException; -import me.main__.util.SerializationConfig.Property; -import me.main__.util.SerializationConfig.SerializationConfig; -import me.main__.util.SerializationConfig.Serializor; -import me.main__.util.SerializationConfig.ValidateAllWith; import me.main__.util.SerializationConfig.VirtualProperty; import org.bukkit.ChatColor; import org.bukkit.Difficulty; @@ -42,55 +34,167 @@ import org.bukkit.permissions.PermissionDefault; import org.bukkit.util.Vector; import org.json.simple.JSONObject; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * The implementation of a Multiverse handled world. */ -@SerializableAs("MVWorld") -@ValidateAllWith(WorldPropertyValidator.class) -public class MVWorld extends SerializationConfig implements MultiverseWorld { +public class MVWorld implements MultiverseWorld { private static final int SPAWN_LOCATION_SEARCH_TOLERANCE = 16; private static final int SPAWN_LOCATION_SEARCH_RADIUS = 16; - private static final Map PROPERTY_ALIASES; + private final MultiverseCore plugin; // Hold the Plugin Instance. + private final String name; // The Worlds Name, EG its folder name. + private final UUID worldUID; + final WorldProperties props; - static { - PROPERTY_ALIASES = new HashMap(); - PROPERTY_ALIASES.put("curr", "currency"); - PROPERTY_ALIASES.put("scaling", "scale"); - PROPERTY_ALIASES.put("aliascolor", "color"); - PROPERTY_ALIASES.put("heal", "autoHeal"); - PROPERTY_ALIASES.put("storm", "allowWeather"); - PROPERTY_ALIASES.put("weather", "allowWeather"); - PROPERTY_ALIASES.put("spawnmemory", "keepSpawnInMemory"); - PROPERTY_ALIASES.put("memory", "keepSpawnInMemory"); - PROPERTY_ALIASES.put("mode", "gameMode"); - PROPERTY_ALIASES.put("diff", "difficulty"); - PROPERTY_ALIASES.put("spawnlocation", "spawn"); - PROPERTY_ALIASES.put("limit", "playerLimit"); - PROPERTY_ALIASES.put("animals", "spawning.animals.spawn"); - PROPERTY_ALIASES.put("monsters", "spawning.monsters.spawn"); - PROPERTY_ALIASES.put("animalsrate", "spawning.animals.spawnrate"); - PROPERTY_ALIASES.put("monstersrate", "spawning.monsters.spawnrate"); + public MVWorld(MultiverseCore plugin, World world, WorldProperties properties) { + this(plugin, world, properties, true); } + /* * We have to use setCBWorld(), setPlugin() and initPerms() to prepare this object for use. */ - public MVWorld(Map values) { - super(values); + public MVWorld(MultiverseCore plugin, World world, WorldProperties properties, boolean fixSpawn) { + this.plugin = plugin; + this.name = world.getName(); + this.worldUID = world.getUID(); + this.props = properties; + + setupProperties(); + // Setup spawn separately so we can use the validator with the world spawn value.. + final SpawnLocationPropertyValidator spawnValidator = new SpawnLocationPropertyValidator(); + final Location worldSpawnLocation = readSpawnFromWorld(world); + this.props.setValidator("spawn", spawnValidator); + if (this.props.spawnLocation instanceof NullLocation) { + this.props.spawnLocation = new SpawnLocation(worldSpawnLocation); + } else { + if (plugin.getBlockSafety().playerCanSpawnHereSafely(this.props.spawnLocation)) { + this.props.spawnLocation = new SpawnLocation(worldSpawnLocation); + } + } + + this.props.environment = world.getEnvironment(); + this.props.seed = world.getSeed(); + + this.initPerms(); + + this.props.flushChanges(); + + if (!fixSpawn) { + props.setAdjustSpawn(false); + } + + validateProperties(); } - private MultiverseCore plugin; // Hold the Plugin Instance. + private void setupProperties() { + this.props.setMVWorld(this); + this.props.pvp = new VirtualProperty() { + @Override + public void set(Boolean newValue) { + final World world = getCBWorld(); + if (world != null) { + world.setPVP(newValue); + } + } - private String name; // The Worlds Name, EG its folder name. + @Override + public Boolean get() { + final World world = getCBWorld(); + return world != null ? world.getPVP() : null; + } + }; + + this.props.difficulty = new VirtualProperty() { + @Override + public void set(Difficulty newValue) { + final World world = getCBWorld(); + if (world != null) { + world.setDifficulty(newValue); + } + } + + @Override + public Difficulty get() { + final World world = getCBWorld(); + return world != null ? world.getDifficulty() : null; + } + }; + + this.props.keepSpawnInMemory = new VirtualProperty() { + @Override + public void set(Boolean newValue) { + final World world = getCBWorld(); + if (world != null) { + world.setKeepSpawnInMemory(newValue); + } + } + + @Override + public Boolean get() { + final World world = getCBWorld(); + return world != null ? world.getKeepSpawnInMemory() : null; + } + }; + + this.props.spawn = new VirtualProperty() { + @Override + public void set(Location newValue) { + if (getCBWorld() != null) + getCBWorld().setSpawnLocation(newValue.getBlockX(), newValue.getBlockY(), newValue.getBlockZ()); + + props.spawnLocation = new SpawnLocation(newValue); + } + + @Override + public Location get() { + props.spawnLocation.setWorld(getCBWorld()); + // basically, everybody should accept our "SpawnLocation", right? + // so just returning it should be fine + return props.spawnLocation; + } + }; + + this.props.time = new VirtualProperty() { + @Override + public void set(Long newValue) { + final World world = getCBWorld(); + if (world != null) { + world.setTime(newValue); + } + } + + @Override + public Long get() { + final World world = getCBWorld(); + return world != null ? world.getTime() : null; + } + }; + + this.props.setValidator("scale", new ScalePropertyValidator()); + this.props.setValidator("respawnWorld", new RespawnWorldPropertyValidator()); + this.props.setValidator("allowWeather", new AllowWeatherPropertyValidator()); + this.props.setValidator("spawning", new SpawningPropertyValidator()); + this.props.setValidator("gameMode", new GameModePropertyValidator()); + + //this.props.validate(); + } + + private void validateProperties() { + setPVPMode(isPVPEnabled()); + setDifficulty(getDifficulty()); + setKeepSpawnInMemory(isKeepingSpawnInMemory()); + setScaling(getScaling()); + setRespawnToWorld(this.props.getRespawnToWorld()); + setAllowAnimalSpawn(canAnimalsSpawn()); + setAllowMonsterSpawn(canMonstersSpawn()); + setGameMode(getGameMode()); + } /** * Validates the scale-property. @@ -114,92 +218,13 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { @Override public String validateChange(String property, String newValue, String oldValue, MVWorld object) throws ChangeDeniedException { - if (!plugin.getMVWorldManager().isMVWorld(newValue)) + if (!newValue.isEmpty() && !plugin.getMVWorldManager().isMVWorld(newValue)) throw new ChangeDeniedException(); return super.validateChange(property, newValue, oldValue, object); } } - /** - * Serializor for the time-property. - */ - private static final class TimePropertySerializor implements Serializor { - // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck - private static final String TIME_REGEX = "(\\d\\d?):?(\\d\\d)(a|p)?m?"; - private static final Map TIME_ALIASES; - static { - Map staticTimes = new HashMap(); - staticTimes.put("morning", "8:00"); - staticTimes.put("day", "12:00"); - staticTimes.put("noon", "12:00"); - staticTimes.put("midnight", "0:00"); - staticTimes.put("night", "20:00"); - // now set TIME_ALIASES to a "frozen" map - TIME_ALIASES = Collections.unmodifiableMap(staticTimes); - } - - @Override - public String serialize(Long from) { - // I'm tired, so they get time in 24 hour for now. - // Someone else can add 12 hr format if they want :P - - int hours = (int) ((from / 1000 + 8) % 24); - int minutes = (int) (60 * (from % 1000) / 1000); - - return String.format("%d:%02d", hours, minutes); - } - - @Override - public Long deserialize(String serialized, Class wanted) throws IllegalPropertyValueException { - if (TIME_ALIASES.containsKey(serialized.toLowerCase())) { - serialized = TIME_ALIASES.get(serialized.toLowerCase()); - } - // Regex that extracts a time in the following formats: - // 11:11pm, 11:11, 23:11, 1111, 1111p, and the aliases at the top of this file. - Pattern pattern = Pattern.compile(TIME_REGEX, Pattern.CASE_INSENSITIVE); - Matcher matcher = pattern.matcher(serialized); - matcher.find(); - int hour = 0; - double minute = 0; - int count = matcher.groupCount(); - if (count >= 2) { - hour = Integer.parseInt(matcher.group(1)); - minute = Integer.parseInt(matcher.group(2)); - } - // If there were 4 matches (all, hour, min, am/pm) - if (count == 4) { - // We want 24 hour time for calcs, but if they - // added a p[m], turn it into a 24 hr one. - if (matcher.group(3).equals("p")) { - hour += 12; - } - } - // Translate 24th hour to 0th hour. - if (hour == 24) { - hour = 0; - } - // Clamp the hour - if (hour > 23 || hour < 0) { - throw new IllegalPropertyValueException("Illegal hour!"); - } - // Clamp the minute - if (minute > 59 || minute < 0) { - throw new IllegalPropertyValueException("Illegal minute!"); - } - // 60 seconds in a minute, time needs to be in hrs * 1000, per - // the bukkit docs. - double totaltime = (hour + (minute / 60.0)) * 1000; - // Somehow there's an 8 hour offset... - totaltime -= 8000; - if (totaltime < 0) { - totaltime = 24000 + totaltime; - } - - return (long) totaltime; - } - // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck - } /** * Used to apply the allowWeather-property. @@ -239,11 +264,11 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { } final World world = getCBWorld(); if (world != null) { - if (MVWorld.this.spawning.getAnimalSettings().getSpawnRate() != -1) { - world.setTicksPerAnimalSpawns(MVWorld.this.spawning.getAnimalSettings().getSpawnRate()); + if (MVWorld.this.props.getAnimalSpawnRate() != -1) { + world.setTicksPerAnimalSpawns(MVWorld.this.props.getAnimalSpawnRate()); } - if (MVWorld.this.spawning.getMonsterSettings().getSpawnRate() != -1) { - world.setTicksPerMonsterSpawns(MVWorld.this.spawning.getMonsterSettings().getSpawnRate()); + if (MVWorld.this.props.getMonsterSpawnRate() != -1) { + world.setTicksPerMonsterSpawns(MVWorld.this.props.getMonsterSpawnRate()); } world.setSpawnFlags(allowMonsters, allowAnimals); } @@ -252,53 +277,6 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { } } - /** - * Serializor for the difficulty-property. - */ - private static final class DifficultyPropertySerializor implements Serializor { - @Override - public String serialize(Difficulty from) { - return from.toString(); - } - - @Override - public Difficulty deserialize(String serialized, Class wanted) throws IllegalPropertyValueException { - try { - return Difficulty.getByValue(Integer.parseInt(serialized)); - } catch (Exception e) { - } - try { - return Difficulty.valueOf(serialized.toUpperCase()); - } catch (Exception e) { - } - throw new IllegalPropertyValueException(); - } - } - - /** - * Serializor for the gameMode-property. - */ - private static final class GameModePropertySerializor implements Serializor { - @Override - public String serialize(GameMode from) { - return from.toString(); - } - - @Override - public GameMode deserialize(String serialized, Class wanted) throws IllegalPropertyValueException { - try { - return GameMode.getByValue(Integer.parseInt(serialized)); - } catch (NumberFormatException nfe) { - } - try { - return GameMode.valueOf(serialized.toUpperCase()); - } catch (Exception e) { - } - throw new IllegalPropertyValueException(); - } - } - - /** * Used to apply the gameMode-property. */ @@ -324,7 +302,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { MVWorld object) throws ChangeDeniedException { if (newValue == null) throw new ChangeDeniedException(); - if (adjustSpawn) { + if (props.getAdjustSpawn()) { BlockSafety bs = plugin.getBlockSafety(); // verify that the location is safe if (!bs.playerCanSpawnHereSafely(newValue)) { @@ -345,190 +323,11 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { } } - /** - * Serializor for the color-property. - */ - private static final class EnumPropertySerializor> implements Serializor { - @Override - public String serialize(T from) { - return from.toString(); - } - - @Override - public T deserialize(String serialized, Class wanted) throws IllegalPropertyValueException { - try { - return Enum.valueOf(wanted, serialized.toUpperCase()); - } catch (IllegalArgumentException e) { - throw new IllegalPropertyValueException(e); - } - } - } - - // -------------------------------------------------------------- - // Begin properties - @Property(description = "Sorry, 'hidden' must either be: true or false.") - private volatile boolean hidden; - @Property(description = "Alias must be a valid string.") - private volatile String alias; - @Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.") - private volatile EnglishChatColor color; - @Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'style' must be a valid style-name.") - private volatile EnglishChatStyle style; - @Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true) - private volatile VirtualProperty pvp = new VirtualProperty() { - @Override - public void set(Boolean newValue) { - final World world = getCBWorld(); - if (world != null) { - world.setPVP(newValue); - } - } - - @Override - public Boolean get() { - final World world = getCBWorld(); - return world != null ? world.getPVP() : null; - } - }; - @Property(validator = ScalePropertyValidator.class, description = "Scale must be a positive double value. ex: 2.3") - private volatile double scale; - @Property(validator = RespawnWorldPropertyValidator.class, description = "You must set this to the NAME not alias of a world.") - private volatile String respawnWorld; - @Property(validator = AllowWeatherPropertyValidator.class, description = "Sorry, this must either be: true or false.") - private volatile boolean allowWeather; - @Property(serializor = DifficultyPropertySerializor.class, virtualType = Difficulty.class, persistVirtual = true, - description = "Difficulty must be set as one of the following: peaceful easy normal hard") - private volatile VirtualProperty difficulty = new VirtualProperty() { - @Override - public void set(Difficulty newValue) { - final World world = getCBWorld(); - if (world != null) { - world.setDifficulty(newValue); - } - } - - @Override - public Difficulty get() { - final World world = getCBWorld(); - return world != null ? world.getDifficulty() : null; - } - }; - @Property(validator = SpawningPropertyValidator.class, description = "Sorry, 'animals' must either be: true or false.") - private volatile SpawnSettings spawning; - @Property - private volatile EntryFee entryfee; - @Property(description = "Sorry, 'hunger' must either be: true or false.") - private volatile boolean hunger; - @Property(description = "Sorry, 'autoheal' must either be: true or false.") - private volatile boolean autoHeal; - @Property(description = "Sorry, 'adjustspawn' must either be: true or false.") - private volatile boolean adjustSpawn; - @Property(serializor = EnumPropertySerializor.class, description = "Allow portal forming must be NONE, ALL, NETHER or END.") - private volatile AllowedPortalType portalForm; - @Property(serializor = GameModePropertySerializor.class, validator = GameModePropertyValidator.class, - description = "GameMode must be set as one of the following: survival creative") - private volatile GameMode gameMode; - @Property(description = "Sorry, this must either be: true or false.", virtualType = Boolean.class, persistVirtual = true) - private volatile VirtualProperty keepSpawnInMemory = new VirtualProperty() { - @Override - public void set(Boolean newValue) { - final World world = getCBWorld(); - if (world != null) { - world.setKeepSpawnInMemory(newValue); - } - } - - @Override - public Boolean get() { - final World world = getCBWorld(); - return world != null ? world.getKeepSpawnInMemory() : null; - } - }; - @Property - private volatile SpawnLocation spawnLocation; - @Property(validator = SpawnLocationPropertyValidator.class, virtualType = Location.class, - description = "There is no help available for this variable. Go bug Rigby90 about it.") - private volatile VirtualProperty spawn = new VirtualProperty() { - @Override - public void set(Location newValue) { - if (getCBWorld() != null) - getCBWorld().setSpawnLocation(newValue.getBlockX(), newValue.getBlockY(), newValue.getBlockZ()); - - spawnLocation = new SpawnLocation(newValue); - } - - @Override - public Location get() { - spawnLocation.setWorld(getCBWorld()); - // basically, everybody should accept our "SpawnLocation", right? - // so just returning it should be fine - return spawnLocation; - } - }; - @Property(description = "Set this to false ONLY if you don't want this world to load itself on server restart.") - private volatile boolean autoLoad; - @Property(description = "If a player dies in this world, shoudld they go to their bed?") - private volatile boolean bedRespawn; - @Property - private volatile List worldBlacklist; - @Property(serializor = TimePropertySerializor.class, virtualType = Long.class, - description = "Set the time to whatever you want! (Will NOT freeze time)") - private volatile VirtualProperty time = new VirtualProperty() { - @Override - public void set(Long newValue) { - final World world = getCBWorld(); - if (world != null) { - world.setTime(newValue); - } - } - - @Override - public Long get() { - final World world = getCBWorld(); - return world != null ? world.getTime() : null; - } - }; - @Property - private volatile Environment environment; - @Property - private volatile long seed; - @Property - private volatile String generator; - @Property - private volatile int playerLimit; - // End of properties - // -------------------------------------------------------------- - private Permission permission; private Permission exempt; private Permission ignoreperm; private Permission limitbypassperm; - public MVWorld(boolean fixSpawn) { - super(); - if (!fixSpawn) { - this.adjustSpawn = false; - } - } - - /** - * This initializes the {@code plugin} and {@code name} fields. - * @param plugin The plugin. - * @param name The world's name. - */ - void setPluginAndWorld(MultiverseCore plugin, String name) { - this.plugin = plugin; - this.name = name; - } - - /** - * {@inheritDoc} - */ - @Override - public void copyValues(SerializationConfig other) { - super.copyValues(other); - } - /** * Null-location. */ @@ -573,33 +372,12 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { }; } - /** - * Sets the CB-World. - *

- * This is used to set some values after deserialization. - * @param cbWorld The new world. - * @param thePlugin The reference to the plugin. - */ - public void init(World cbWorld, MultiverseCore thePlugin) { - this.plugin = thePlugin; - - this.environment = cbWorld.getEnvironment(); - this.seed = cbWorld.getSeed(); - this.name = cbWorld.getName(); - if (this.spawnLocation instanceof NullLocation) - this.spawnLocation = new SpawnLocation(readSpawnFromWorld(cbWorld)); - - this.initPerms(); - - this.flushPendingVPropChanges(); - } - /** * This prepares the MVWorld for unloading. */ public void tearDown() { try { - this.buildVPropChanges(); + this.props.tearDown(); } catch (IllegalStateException e) { // do nothing } @@ -678,49 +456,6 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { return location; } - /** - * {@inheritDoc} - */ - @Override - protected void setDefaults() { - this.hidden = false; - this.alias = new String(); - this.color = EnglishChatColor.WHITE; - this.style = EnglishChatStyle.NORMAL; - this.scale = getDefaultScale(environment); - this.respawnWorld = new String(); - this.allowWeather = true; - this.spawning = new SpawnSettings(); - this.entryfee = new EntryFee(); - this.hunger = true; - this.autoHeal = true; - this.adjustSpawn = true; - this.portalForm = AllowedPortalType.ALL; - this.gameMode = GameMode.SURVIVAL; - this.spawnLocation = (getCBWorld() != null) ? new SpawnLocation(getCBWorld().getSpawnLocation()) : new NullLocation(); - this.autoLoad = true; - this.bedRespawn = true; - this.worldBlacklist = new ArrayList(); - this.generator = null; - this.playerLimit = -1; - } - - /** - * getAliases(). - * @return The alias-map. - * @see SerializationConfig - */ - protected static Map getAliases() { - return PROPERTY_ALIASES; - } - - private static double getDefaultScale(Environment environment) { - if (environment == Environment.NETHER) { - return 8.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck - } - return 1.0; - } - private void addToUpperLists(Permission perm) { Permission all = this.plugin.getServer().getPluginManager().getPermission("multiverse.*"); Permission allWorlds = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*"); @@ -747,6 +482,14 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allWorlds); } + public void copyValues(MVWorld other) { + props.copyValues(other.props); + } + + public void copyValues(WorldProperties other) { + props.copyValues(other); + } + /** * {@inheritDoc} */ @@ -767,18 +510,18 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public String getColoredWorldString() { - if (alias.length() == 0) { - alias = this.getName(); + if (props.getAlias().length() == 0) { + props.setAlias(this.getName()); } - if ((color == null) || (color.getColor() == null)) { - this.setPropertyValueUnchecked("color", EnglishChatColor.WHITE); + if ((props.getColor() == null) || (props.getColor().getColor() == null)) { + this.props.setColor(EnglishChatColor.WHITE); } - StringBuilder nameBuilder = new StringBuilder().append(color.getColor()); - if (style.getColor() != null) - nameBuilder.append(style.getColor()); - nameBuilder.append(alias).append(ChatColor.WHITE).toString(); + StringBuilder nameBuilder = new StringBuilder().append(props.getColor().getColor()); + if (props.getStyle().getColor() != null) + nameBuilder.append(props.getStyle().getColor()); + nameBuilder.append(props.getAlias()).append(ChatColor.WHITE).toString(); return nameBuilder.toString(); } @@ -845,11 +588,11 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { @Deprecated private List getOldAndEvilList(String property) { if (property.equalsIgnoreCase("worldblacklist")) - return this.worldBlacklist; + return this.props.getWorldBlacklist(); else if (property.equalsIgnoreCase("animals")) - return this.spawning.getAnimalSettings().getExceptions(); + return this.props.getAnimalList(); else if (property.equalsIgnoreCase("monsters")) - return this.spawning.getMonsterSettings().getExceptions(); + return this.props.getMonsterList(); return null; } @@ -882,7 +625,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { @Override public String getPropertyValue(String property) throws PropertyDoesNotExistException { try { - return this.getProperty(property, true); + return this.props.getProperty(property, true); } catch (NoSuchPropertyException e) { throw new PropertyDoesNotExistException(property, e); } @@ -894,7 +637,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { @Override public boolean setPropertyValue(String property, String value) throws PropertyDoesNotExistException { try { - return this.setProperty(property, value, true); + return this.props.setProperty(property, value, true); } catch (NoSuchPropertyException e) { throw new PropertyDoesNotExistException(property, e); } @@ -906,7 +649,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { @Override public String getPropertyHelp(String property) throws PropertyDoesNotExistException { try { - return this.getPropertyDescription(property, true); + return this.props.getPropertyDescription(property, true); } catch (NoSuchPropertyException e) { throw new PropertyDoesNotExistException(property, e); } @@ -927,7 +670,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public Environment getEnvironment() { - return this.environment; + return this.props.getEnvironment(); } /** @@ -935,7 +678,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setEnvironment(Environment environment) { - this.setPropertyValueUnchecked("environment", environment); + this.props.setEnvironment(environment); } /** @@ -943,7 +686,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public long getSeed() { - return this.seed; + return this.props.getSeed(); } /** @@ -951,7 +694,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setSeed(long seed) { - this.setPropertyValueUnchecked("seed", seed); + this.props.setSeed(seed); } /** @@ -959,7 +702,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public String getGenerator() { - return this.generator; + return this.props.getGenerator(); } /** @@ -967,7 +710,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setGenerator(String generator) { - this.setPropertyValueUnchecked("generator", generator); + this.props.setGenerator(generator); } /** @@ -975,7 +718,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public int getPlayerLimit() { - return this.playerLimit; + return this.props.getPlayerLimit(); } /** @@ -983,7 +726,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setPlayerLimit(int limit) { - this.setPropertyValueUnchecked("playerLimit", limit); + this.props.setPlayerLimit(limit); } /** @@ -1008,10 +751,10 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public String getAlias() { - if (this.alias == null || this.alias.length() == 0) { + if (this.props.getAlias() == null || this.props.getAlias().length() == 0) { return this.name; } - return this.alias; + return this.props.getAlias(); } /** @@ -1019,7 +762,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setAlias(String alias) { - this.setPropertyValueUnchecked("alias", alias); + this.props.setAlias(alias); } /** @@ -1027,7 +770,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean canAnimalsSpawn() { - return this.spawning.getAnimalSettings().doSpawn(); + return this.props.canAnimalsSpawn(); } /** @@ -1035,7 +778,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setAllowAnimalSpawn(boolean animals) { - this.setPropertyValueUnchecked("spawning.animals.spawn", animals); + this.props.setAllowAnimalSpawn(animals); } /** @@ -1044,7 +787,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { @Override public List getAnimalList() { // These don't fire events at the moment. Should they? - return this.spawning.getAnimalSettings().getExceptions(); + return this.props.getAnimalList(); } /** @@ -1052,7 +795,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean canMonstersSpawn() { - return this.spawning.getMonsterSettings().doSpawn(); + return this.props.canMonstersSpawn(); } /** @@ -1060,7 +803,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setAllowMonsterSpawn(boolean monsters) { - this.setPropertyValueUnchecked("spawning.monsters.spawn", monsters); + this.props.setAllowMonsterSpawn(monsters); } /** @@ -1069,7 +812,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { @Override public List getMonsterList() { // These don't fire events at the moment. Should they? - return this.spawning.getMonsterSettings().getExceptions(); + return this.props.getMonsterList(); } /** @@ -1077,7 +820,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean isPVPEnabled() { - return this.pvp.get(); + return this.props.isPVPEnabled(); } /** @@ -1085,7 +828,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setPVPMode(boolean pvp) { - this.setPropertyValueUnchecked("pvp", pvp); + this.props.setPVPMode(pvp); } /** @@ -1093,7 +836,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean isHidden() { - return this.hidden; + return this.props.isHidden(); } /** @@ -1101,7 +844,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setHidden(boolean hidden) { - this.setPropertyValueUnchecked("hidden", hidden); + this.props.setHidden(hidden); } /** @@ -1109,7 +852,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public List getWorldBlacklist() { - return this.worldBlacklist; + return this.props.getWorldBlacklist(); } /** @@ -1117,7 +860,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public double getScaling() { - return this.scale; + return this.props.getScaling(); } /** @@ -1125,7 +868,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean setScaling(double scaling) { - return this.setPropertyValueUnchecked("scale", scaling); + return this.props.setScaling(scaling); } /** @@ -1133,7 +876,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean setColor(String aliasColor) { - return this.setPropertyUnchecked("color", aliasColor); + return props.setColor(aliasColor); } /** @@ -1152,7 +895,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public ChatColor getColor() { - return this.color.getColor(); + return this.props.getColor().getColor(); } /** @@ -1171,7 +914,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public World getRespawnToWorld() { - return this.plugin.getServer().getWorld(respawnWorld); + return this.plugin.getServer().getWorld(props.getRespawnToWorld()); } /** @@ -1180,7 +923,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { @Override public boolean setRespawnToWorld(String respawnToWorld) { if (!this.plugin.getMVWorldManager().isMVWorld(respawnToWorld)) return false; - return this.setPropertyValueUnchecked("respawnWorld", respawnToWorld); + return this.props.setRespawnToWorld(respawnToWorld); } /** @@ -1196,7 +939,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public int getCurrency() { - return this.entryfee.getCurrency(); + return this.props.getCurrency(); } /** @@ -1204,7 +947,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setCurrency(int currency) { - this.setPropertyValueUnchecked("entryfee.currency", currency); + this.props.setCurrency(currency); } /** @@ -1212,7 +955,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public double getPrice() { - return this.entryfee.getAmount(); + return this.props.getPrice(); } /** @@ -1220,7 +963,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setPrice(double price) { - this.setPropertyValueUnchecked("entryfee.amount", price); + this.props.setPrice(price); } /** @@ -1236,12 +979,12 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean setGameMode(String mode) { - return this.setPropertyUnchecked("gameMode", mode); + return this.props.setGameMode(mode); } @Override public boolean setGameMode(GameMode mode) { - return this.setPropertyValueUnchecked("gameMode", mode); + return this.props.setGameMode(mode); } /** @@ -1249,7 +992,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public GameMode getGameMode() { - return this.gameMode; + return this.props.getGameMode(); } /** @@ -1257,7 +1000,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setEnableWeather(boolean weather) { - this.setPropertyValueUnchecked("allowWeather", weather); + this.props.setEnableWeather(weather); } /** @@ -1265,7 +1008,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean isWeatherEnabled() { - return this.allowWeather; + return this.props.isWeatherEnabled(); } /** @@ -1273,7 +1016,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean isKeepingSpawnInMemory() { - return this.keepSpawnInMemory.get(); + return this.props.isKeepingSpawnInMemory(); } /** @@ -1281,7 +1024,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setKeepSpawnInMemory(boolean value) { - this.setPropertyValueUnchecked("keepSpawnInMemory", value); + this.props.setKeepSpawnInMemory(value); } /** @@ -1289,7 +1032,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean getHunger() { - return this.hunger; + return this.props.getHunger(); } /** @@ -1297,7 +1040,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setHunger(boolean hunger) { - this.setPropertyValueUnchecked("hunger", hunger); + this.props.setHunger(hunger); } /** @@ -1305,7 +1048,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public Location getSpawnLocation() { - return this.spawn.get(); + return this.props.getSpawnLocation(); } /** @@ -1313,7 +1056,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setSpawnLocation(Location l) { - this.setPropertyValueUnchecked("spawn", l); + this.props.setSpawnLocation(l); } /** @@ -1321,7 +1064,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public Difficulty getDifficulty() { - return this.difficulty.get(); + return this.props.getDifficulty(); } /** @@ -1332,12 +1075,12 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { @Override @Deprecated public boolean setDifficulty(String difficulty) { - return this.setPropertyUnchecked("difficulty", difficulty); + return this.props.setDifficulty(difficulty); } @Override public boolean setDifficulty(Difficulty difficulty) { - return this.setPropertyValueUnchecked("difficulty", difficulty); + return this.props.setDifficulty(difficulty); } /** @@ -1345,7 +1088,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean getAutoHeal() { - return this.autoHeal; + return this.props.getAutoHeal(); } /** @@ -1353,7 +1096,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setAutoHeal(boolean heal) { - this.setPropertyValueUnchecked("autoHeal", heal); + this.props.setAutoHeal(heal); } /** @@ -1361,7 +1104,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setAdjustSpawn(boolean adjust) { - this.setPropertyValueUnchecked("adjustSpawn", adjust); + this.props.setAdjustSpawn(adjust); } /** @@ -1369,7 +1112,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean getAdjustSpawn() { - return this.adjustSpawn; + return this.props.getAdjustSpawn(); } /** @@ -1377,7 +1120,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setAutoLoad(boolean load) { - this.setPropertyValueUnchecked("autoLoad", load); + this.props.setAutoLoad(load); } /** @@ -1385,7 +1128,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean getAutoLoad() { - return this.autoLoad; + return this.props.getAutoLoad(); } /** @@ -1393,7 +1136,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void setBedRespawn(boolean respawn) { - this.setPropertyValueUnchecked("bedRespawn", respawn); + this.props.setBedRespawn(respawn); } /** @@ -1401,7 +1144,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean getBedRespawn() { - return this.bedRespawn; + return this.props.getBedRespawn(); } /** @@ -1409,14 +1152,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public String getAllPropertyNames() { - ChatColor myColor = ChatColor.AQUA; - StringBuilder result = new StringBuilder(); - Map serialized = this.serialize(); - for (String key : serialized.keySet()) { - result.append(myColor).append(key).append(' '); - myColor = (myColor == ChatColor.AQUA) ? ChatColor.GOLD : ChatColor.AQUA; - } - return result.toString(); + return this.props.getAllPropertyNames(); } /** @@ -1424,7 +1160,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public String getTime() { - return this.getPropertyUnchecked("time"); + return this.props.getTime(); } /** @@ -1432,7 +1168,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean setTime(String timeAsString) { - return this.setPropertyUnchecked("time", timeAsString); + return this.props.setTime(timeAsString); } /** @@ -1440,7 +1176,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public AllowedPortalType getAllowedPortals() { - return portalForm; + return props.getAllowedPortals(); } /** @@ -1448,7 +1184,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public void allowPortalMaking(AllowedPortalType portalType) { - this.setPropertyValueUnchecked("portalForm", portalType); + this.props.allowPortalMaking(portalType); } /** @@ -1456,7 +1192,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public ChatColor getStyle() { - return style.getColor(); + return this.props.getStyle().getColor(); } /** @@ -1464,7 +1200,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld { */ @Override public boolean setStyle(String style) { - return this.setPropertyUnchecked("style", style); + return this.props.setStyle(style); } @Override diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index ba00af6e..6ab02def 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -61,7 +61,6 @@ import com.onarandombox.MultiverseCore.destination.ExactDestination; import com.onarandombox.MultiverseCore.destination.PlayerDestination; import com.onarandombox.MultiverseCore.destination.WorldDestination; import com.onarandombox.MultiverseCore.event.MVVersionEvent; -import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException; import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener; import com.onarandombox.MultiverseCore.listeners.MVChatListener; import com.onarandombox.MultiverseCore.listeners.MVEntityListener; @@ -80,6 +79,7 @@ import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter; import com.onarandombox.MultiverseCore.utils.VaultHandler; import com.onarandombox.MultiverseCore.utils.WorldManager; import com.pneumaticraft.commandhandler.CommandHandler; +import me.main__.util.SerializationConfig.NoSuchPropertyException; import me.main__.util.SerializationConfig.SerializationConfig; import org.bukkit.ChatColor; import org.bukkit.Difficulty; @@ -222,7 +222,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { // Register our config SerializationConfig.registerAll(MultiverseCoreConfiguration.class); // Register our world - SerializationConfig.registerAll(MVWorld.class); + SerializationConfig.registerAll(WorldProperties.class); // Create our DataFolder getDataFolder().mkdirs(); // Setup our Debug Log @@ -567,14 +567,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { boolean wasChanged = false; Map newValues = new LinkedHashMap(values.size()); for (Map.Entry entry : values.entrySet()) { - if (entry.getValue() instanceof MVWorld) { + if (entry.getValue() instanceof WorldProperties) { // fine newValues.put(entry.getKey(), entry.getValue()); } else if (entry.getValue() instanceof ConfigurationSection) { this.log(Level.FINE, "Migrating: " + entry.getKey()); // we have to migrate this - MVWorld world = new MVWorld(Collections.EMPTY_MAP); - world.setPluginAndWorld(this, entry.getKey()); + WorldProperties world = new WorldProperties(Collections.EMPTY_MAP); ConfigurationSection section = (ConfigurationSection) entry.getValue(); // migrate animals and monsters @@ -669,7 +668,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { if (section.isString("portalform")) { try { world.setPropertyValue("portalform", section.getString("portalform")); - } catch (PropertyDoesNotExistException e) { + } catch (NoSuchPropertyException e) { throw new RuntimeException("Who forgot to update the migrator?", e); } } @@ -678,7 +677,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { if (section.isString("environment")) { try { world.setPropertyValue("environment", section.getString("environment")); - } catch (PropertyDoesNotExistException e) { + } catch (NoSuchPropertyException e) { throw new RuntimeException("Who forgot to update the migrator?", e); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/WorldProperties.java b/src/main/java/com/onarandombox/MultiverseCore/WorldProperties.java new file mode 100644 index 00000000..b88858c4 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/WorldProperties.java @@ -0,0 +1,616 @@ +package com.onarandombox.MultiverseCore; + +import com.onarandombox.MultiverseCore.MVWorld.NullLocation; +import com.onarandombox.MultiverseCore.configuration.EntryFee; +import com.onarandombox.MultiverseCore.configuration.SpawnLocation; +import com.onarandombox.MultiverseCore.configuration.SpawnSettings; +import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator; +import com.onarandombox.MultiverseCore.enums.AllowedPortalType; +import com.onarandombox.MultiverseCore.enums.EnglishChatColor; +import com.onarandombox.MultiverseCore.enums.EnglishChatStyle; +import me.main__.util.SerializationConfig.IllegalPropertyValueException; +import me.main__.util.SerializationConfig.Property; +import me.main__.util.SerializationConfig.SerializationConfig; +import me.main__.util.SerializationConfig.Serializor; +import me.main__.util.SerializationConfig.Validator; +import me.main__.util.SerializationConfig.VirtualProperty; +import org.bukkit.ChatColor; +import org.bukkit.Difficulty; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.World.Environment; +import org.bukkit.configuration.serialization.SerializableAs; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@SerializableAs("MVWorld") +public class WorldProperties extends SerializationConfig { + + private static final Map PROPERTY_ALIASES; + + static { + PROPERTY_ALIASES = new HashMap(); + PROPERTY_ALIASES.put("curr", "currency"); + PROPERTY_ALIASES.put("scaling", "scale"); + PROPERTY_ALIASES.put("aliascolor", "color"); + PROPERTY_ALIASES.put("heal", "autoHeal"); + PROPERTY_ALIASES.put("storm", "allowWeather"); + PROPERTY_ALIASES.put("weather", "allowWeather"); + PROPERTY_ALIASES.put("spawnmemory", "keepSpawnInMemory"); + PROPERTY_ALIASES.put("memory", "keepSpawnInMemory"); + PROPERTY_ALIASES.put("mode", "gameMode"); + PROPERTY_ALIASES.put("diff", "difficulty"); + PROPERTY_ALIASES.put("spawnlocation", "spawn"); + PROPERTY_ALIASES.put("limit", "playerLimit"); + PROPERTY_ALIASES.put("animals", "spawning.animals.spawn"); + PROPERTY_ALIASES.put("monsters", "spawning.monsters.spawn"); + PROPERTY_ALIASES.put("animalsrate", "spawning.animals.spawnrate"); + PROPERTY_ALIASES.put("monstersrate", "spawning.monsters.spawnrate"); + } + + public WorldProperties(Map values) { + super(values); + } + + public WorldProperties() { + super(); + } + + public WorldProperties(boolean fixSpawn) { + super(); + if (!fixSpawn) { + this.adjustSpawn = false; + } + } + + void setMVWorld(MVWorld world) { + registerObjectUsing(world); + registerGlobalValidator(new WorldPropertyValidator()); + } + + /** + * Serializor for the color-property. + */ + private static final class EnumPropertySerializor> implements Serializor { + @Override + public String serialize(T from) { + return from.toString(); + } + + @Override + public T deserialize(String serialized, Class wanted) throws IllegalPropertyValueException { + try { + return Enum.valueOf(wanted, serialized.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new IllegalPropertyValueException(e); + } + } + } + + /** + * Serializor for the difficulty-property. + */ + private static final class DifficultyPropertySerializor implements Serializor { + @Override + public String serialize(Difficulty from) { + return from.toString(); + } + + @Override + public Difficulty deserialize(String serialized, Class wanted) throws IllegalPropertyValueException { + try { + return Difficulty.getByValue(Integer.parseInt(serialized)); + } catch (Exception e) { + } + try { + return Difficulty.valueOf(serialized.toUpperCase()); + } catch (Exception e) { + } + throw new IllegalPropertyValueException(); + } + } + + /** + * Serializor for the gameMode-property. + */ + private static final class GameModePropertySerializor implements Serializor { + @Override + public String serialize(GameMode from) { + return from.toString(); + } + + @Override + public GameMode deserialize(String serialized, Class wanted) throws IllegalPropertyValueException { + try { + return GameMode.getByValue(Integer.parseInt(serialized)); + } catch (NumberFormatException nfe) { + } + try { + return GameMode.valueOf(serialized.toUpperCase()); + } catch (Exception e) { + } + throw new IllegalPropertyValueException(); + } + } + + /** + * Serializor for the time-property. + */ + private static final class TimePropertySerializor implements Serializor { + // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck + private static final String TIME_REGEX = "(\\d\\d?):?(\\d\\d)(a|p)?m?"; + private static final Map TIME_ALIASES; + static { + Map staticTimes = new HashMap(); + staticTimes.put("morning", "8:00"); + staticTimes.put("day", "12:00"); + staticTimes.put("noon", "12:00"); + staticTimes.put("midnight", "0:00"); + staticTimes.put("night", "20:00"); + + // now set TIME_ALIASES to a "frozen" map + TIME_ALIASES = Collections.unmodifiableMap(staticTimes); + } + + @Override + public String serialize(Long from) { + // I'm tired, so they get time in 24 hour for now. + // Someone else can add 12 hr format if they want :P + + int hours = (int) ((from / 1000 + 8) % 24); + int minutes = (int) (60 * (from % 1000) / 1000); + + return String.format("%d:%02d", hours, minutes); + } + + @Override + public Long deserialize(String serialized, Class wanted) throws IllegalPropertyValueException { + if (TIME_ALIASES.containsKey(serialized.toLowerCase())) { + serialized = TIME_ALIASES.get(serialized.toLowerCase()); + } + // Regex that extracts a time in the following formats: + // 11:11pm, 11:11, 23:11, 1111, 1111p, and the aliases at the top of this file. + Pattern pattern = Pattern.compile(TIME_REGEX, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(serialized); + matcher.find(); + int hour = 0; + double minute = 0; + int count = matcher.groupCount(); + if (count >= 2) { + hour = Integer.parseInt(matcher.group(1)); + minute = Integer.parseInt(matcher.group(2)); + } + // If there were 4 matches (all, hour, min, am/pm) + if (count == 4) { + // We want 24 hour time for calcs, but if they + // added a p[m], turn it into a 24 hr one. + if (matcher.group(3).equals("p")) { + hour += 12; + } + } + // Translate 24th hour to 0th hour. + if (hour == 24) { + hour = 0; + } + // Clamp the hour + if (hour > 23 || hour < 0) { + throw new IllegalPropertyValueException("Illegal hour!"); + } + // Clamp the minute + if (minute > 59 || minute < 0) { + throw new IllegalPropertyValueException("Illegal minute!"); + } + // 60 seconds in a minute, time needs to be in hrs * 1000, per + // the bukkit docs. + double totaltime = (hour + (minute / 60.0)) * 1000; + // Somehow there's an 8 hour offset... + totaltime -= 8000; + if (totaltime < 0) { + totaltime = 24000 + totaltime; + } + + return (long) totaltime; + } + // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck + } + + // -------------------------------------------------------------- + // Begin properties + @Property(description = "Sorry, 'hidden' must either be: true or false.") + private volatile boolean hidden; + @Property(description = "Alias must be a valid string.") + private volatile String alias; + @Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.") + private volatile EnglishChatColor color; + @Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'style' must be a valid style-name.") + private volatile EnglishChatStyle style; + @Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true) + volatile VirtualProperty pvp; + @Property(description = "Scale must be a positive double value. ex: 2.3") + private volatile double scale; + @Property(description = "You must set this to the NAME not alias of a world.") + private volatile String respawnWorld; + @Property(description = "Sorry, this must either be: true or false.") + private volatile boolean allowWeather; + @Property(serializor = DifficultyPropertySerializor.class, virtualType = Difficulty.class, persistVirtual = true, + description = "Difficulty must be set as one of the following: peaceful easy normal hard") + volatile VirtualProperty difficulty; + @Property(description = "Sorry, 'animals' must either be: true or false.") + private volatile SpawnSettings spawning; + @Property + private volatile EntryFee entryfee; + @Property(description = "Sorry, 'hunger' must either be: true or false.") + private volatile boolean hunger; + @Property(description = "Sorry, 'autoheal' must either be: true or false.") + private volatile boolean autoHeal; + @Property(description = "Sorry, 'adjustspawn' must either be: true or false.") + private volatile boolean adjustSpawn; + @Property(serializor = EnumPropertySerializor.class, description = "Allow portal forming must be NONE, ALL, NETHER or END.") + private volatile AllowedPortalType portalForm; + @Property(serializor = GameModePropertySerializor.class, description = "GameMode must be set as one of the following: survival creative") + private volatile GameMode gameMode; + @Property(description = "Sorry, this must either be: true or false.", virtualType = Boolean.class, persistVirtual = true) + volatile VirtualProperty keepSpawnInMemory; + @Property + volatile SpawnLocation spawnLocation; + @Property(virtualType = Location.class, + description = "There is no help available for this variable. Go bug Rigby90 about it.") + volatile VirtualProperty spawn; + @Property(description = "Set this to false ONLY if you don't want this world to load itself on server restart.") + private volatile boolean autoLoad; + @Property(description = "If a player dies in this world, shoudld they go to their bed?") + private volatile boolean bedRespawn; + @Property + private volatile List worldBlacklist; + @Property(serializor = TimePropertySerializor.class, virtualType = Long.class, + description = "Set the time to whatever you want! (Will NOT freeze time)") + volatile VirtualProperty time; + @Property + volatile Environment environment; + @Property + volatile long seed; + @Property + private volatile String generator; + @Property + private volatile int playerLimit; + // End of properties + // -------------------------------------------------------------- + + void setValidator(String fieldName, Validator validator) { + registerValidator(fieldName, validator); //To change body of overridden methods use File | Settings | File Templates. + } + + /** + * {@inheritDoc} + */ + @Override + public void copyValues(SerializationConfig other) { + super.copyValues(other); + } + + /** + * This prepares the MVWorld for unloading. + */ + public void tearDown() { + try { + this.buildVPropChanges(); + } catch (IllegalStateException e) { + // do nothing + } + } + + /** + * {@inheritDoc} + */ + @Override + protected void setDefaults() { + this.hidden = false; + this.alias = new String(); + this.color = EnglishChatColor.WHITE; + this.style = EnglishChatStyle.NORMAL; + this.scale = getDefaultScale(environment); + this.respawnWorld = new String(); + this.allowWeather = true; + this.spawning = new SpawnSettings(); + this.entryfee = new EntryFee(); + this.hunger = true; + this.autoHeal = true; + this.adjustSpawn = true; + this.portalForm = AllowedPortalType.ALL; + this.gameMode = GameMode.SURVIVAL; + this.spawnLocation = new NullLocation(); + this.autoLoad = true; + this.bedRespawn = true; + this.worldBlacklist = new ArrayList(); + this.generator = null; + this.playerLimit = -1; + } + + private static double getDefaultScale(Environment environment) { + if (environment == Environment.NETHER) { + return 8.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck + } + return 1.0; + } + + /** + * getAliases(). + * @return The alias-map. + * @see SerializationConfig + */ + protected static Map getAliases() { + return PROPERTY_ALIASES; + } + + void flushChanges() { + this.flushPendingVPropChanges(); + } + + String getAlias() { + return this.alias; + } + + public void setAlias(String alias) { + this.setPropertyValueUnchecked("alias", alias); + } + + public Environment getEnvironment() { + return this.environment; + } + + public void setEnvironment(Environment environment) { + this.setPropertyValueUnchecked("environment", environment); + } + + public long getSeed() { + return this.seed; + } + + public void setSeed(long seed) { + this.setPropertyValueUnchecked("seed", seed); + } + + public String getGenerator() { + return this.generator; + } + + public void setGenerator(String generator) { + this.setPropertyValueUnchecked("generator", generator); + } + + public int getPlayerLimit() { + return this.playerLimit; + } + + public void setPlayerLimit(int limit) { + this.setPropertyValueUnchecked("playerLimit", limit); + } + + public boolean canAnimalsSpawn() { + return this.spawning.getAnimalSettings().doSpawn(); + } + + public void setAllowAnimalSpawn(boolean animals) { + this.setPropertyValueUnchecked("spawning.animals.spawn", animals); + } + + public List getAnimalList() { + // These don't fire events at the moment. Should they? + return this.spawning.getAnimalSettings().getExceptions(); + } + + public boolean canMonstersSpawn() { + return this.spawning.getMonsterSettings().doSpawn(); + } + + public void setAllowMonsterSpawn(boolean monsters) { + this.setPropertyValueUnchecked("spawning.monsters.spawn", monsters); + } + + public int getAnimalSpawnRate() { + return this.spawning.getAnimalSettings().getSpawnRate(); + } + + public int getMonsterSpawnRate() { + return this.spawning.getMonsterSettings().getSpawnRate(); + } + + public List getMonsterList() { + // These don't fire events at the moment. Should they? + return this.spawning.getMonsterSettings().getExceptions(); + } + + public boolean isPVPEnabled() { + return this.pvp.get(); + } + + public void setPVPMode(boolean pvp) { + this.setPropertyValueUnchecked("pvp", pvp); + } + + public boolean isHidden() { + return this.hidden; + } + + public void setHidden(boolean hidden) { + this.setPropertyValueUnchecked("hidden", hidden); + } + + public List getWorldBlacklist() { + return this.worldBlacklist; + } + + public double getScaling() { + return this.scale; + } + + public boolean setScaling(double scaling) { + return this.setPropertyValueUnchecked("scale", scaling); + } + + public boolean setColor(String aliasColor) { + return this.setPropertyUnchecked("color", aliasColor); + } + + public boolean setColor(EnglishChatColor color) { + return this.setPropertyValueUnchecked("color", color); + } + + public EnglishChatColor getColor() { + return this.color; + } + + public String getRespawnToWorld() { + return this.respawnWorld; + } + + public boolean setRespawnToWorld(String respawnToWorld) { + return this.setPropertyValueUnchecked("respawnWorld", respawnToWorld); + } + + public int getCurrency() { + return this.entryfee.getCurrency(); + } + + public void setCurrency(int currency) { + this.setPropertyValueUnchecked("entryfee.currency", currency); + } + + public double getPrice() { + return this.entryfee.getAmount(); + } + + public void setPrice(double price) { + this.setPropertyValueUnchecked("entryfee.amount", price); + } + + public boolean setGameMode(String mode) { + return this.setPropertyUnchecked("gameMode", mode); + } + + public boolean setGameMode(GameMode mode) { + return this.setPropertyValueUnchecked("gameMode", mode); + } + + public GameMode getGameMode() { + return this.gameMode; + } + + public void setEnableWeather(boolean weather) { + this.setPropertyValueUnchecked("allowWeather", weather); + } + + public boolean isWeatherEnabled() { + return this.allowWeather; + } + + public boolean isKeepingSpawnInMemory() { + return this.keepSpawnInMemory.get(); + } + + public void setKeepSpawnInMemory(boolean value) { + this.setPropertyValueUnchecked("keepSpawnInMemory", value); + } + + public boolean getHunger() { + return this.hunger; + } + + public void setHunger(boolean hunger) { + this.setPropertyValueUnchecked("hunger", hunger); + } + + public Location getSpawnLocation() { + return this.spawn.get(); + } + + public void setSpawnLocation(Location l) { + this.setPropertyValueUnchecked("spawn", l); + } + + public Difficulty getDifficulty() { + return this.difficulty.get(); + } + + @Deprecated + public boolean setDifficulty(String difficulty) { + return this.setPropertyUnchecked("difficulty", difficulty); + } + + public boolean setDifficulty(Difficulty difficulty) { + return this.setPropertyValueUnchecked("difficulty", difficulty); + } + + public boolean getAutoHeal() { + return this.autoHeal; + } + + public void setAutoHeal(boolean heal) { + this.setPropertyValueUnchecked("autoHeal", heal); + } + + public void setAdjustSpawn(boolean adjust) { + this.setPropertyValueUnchecked("adjustSpawn", adjust); + } + + public boolean getAdjustSpawn() { + return this.adjustSpawn; + } + + public void setAutoLoad(boolean load) { + this.setPropertyValueUnchecked("autoLoad", load); + } + + public boolean getAutoLoad() { + return this.autoLoad; + } + + public void setBedRespawn(boolean respawn) { + this.setPropertyValueUnchecked("bedRespawn", respawn); + } + + public boolean getBedRespawn() { + return this.bedRespawn; + } + + public String getAllPropertyNames() { + ChatColor myColor = ChatColor.AQUA; + StringBuilder result = new StringBuilder(); + Map serialized = this.serialize(); + for (String key : serialized.keySet()) { + result.append(myColor).append(key).append(' '); + myColor = (myColor == ChatColor.AQUA) ? ChatColor.GOLD : ChatColor.AQUA; + } + return result.toString(); + } + + public String getTime() { + return this.getPropertyUnchecked("time"); + } + + public boolean setTime(String timeAsString) { + return this.setPropertyUnchecked("time", timeAsString); + } + + public AllowedPortalType getAllowedPortals() { + return portalForm; + } + + public void allowPortalMaking(AllowedPortalType portalType) { + this.setPropertyValueUnchecked("portalForm", portalType); + } + + public EnglishChatStyle getStyle() { + return style; + } + + public boolean setStyle(String style) { + return this.setPropertyUnchecked("style", style); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVPlugin.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVPlugin.java index a8fce38c..e70cd35d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVPlugin.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVPlugin.java @@ -30,14 +30,14 @@ public interface MVPlugin extends LoggablePlugin { /** * Gets the reference to MultiverseCore. * - * @return A valid {@link MultiverseCore}. + * @return A valid {@link com.onarandombox.MultiverseCore}. */ MultiverseCore getCore(); /** * Sets the reference to MultiverseCore. * - * @param core A valid {@link MultiverseCore}. + * @param core A valid {@link com.onarandombox.MultiverseCore}. */ void setCore(MultiverseCore core); diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index 7ecaa115..9ff5babd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.utils; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.WorldProperties; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.SafeTTeleporter; @@ -52,14 +53,14 @@ public class WorldManager implements MVWorldManager { private final MultiverseCore plugin; private final WorldPurger worldPurger; private final Map worlds; - private Map worldsFromTheConfig; + private Map worldsFromTheConfig; private FileConfiguration configWorlds = null; private Map defaultGens; private String firstSpawn; public WorldManager(MultiverseCore core) { this.plugin = core; - this.worldsFromTheConfig = new HashMap(); + this.worldsFromTheConfig = new HashMap(); this.worlds = new ConcurrentHashMap(); this.worldPurger = new SimpleWorldPurger(plugin); } @@ -207,8 +208,10 @@ public class WorldManager implements MVWorldManager { } // Important: doLoad() needs the MVWorld-object in worldsFromTheConfig - if (!worldsFromTheConfig.containsKey(name)) - worldsFromTheConfig.put(name, new MVWorld(useSpawnAdjust)); + if (!worldsFromTheConfig.containsKey(name)) { + WorldProperties props = new WorldProperties(useSpawnAdjust); + worldsFromTheConfig.put(name, props); + } StringBuilder builder = new StringBuilder(); builder.append("Loading World & Settings - '").append(name).append("'"); @@ -362,7 +365,7 @@ public class WorldManager implements MVWorldManager { if (!worldsFromTheConfig.containsKey(name)) throw new IllegalArgumentException("That world doesn't exist!"); - MVWorld world = worldsFromTheConfig.get(name); + WorldProperties world = worldsFromTheConfig.get(name); WorldCreator creator = WorldCreator.name(name); creator.environment(world.getEnvironment()).seed(world.getSeed()); @@ -385,7 +388,7 @@ public class WorldManager implements MVWorldManager { return false; } - MVWorld mvworld = worldsFromTheConfig.get(worldName); + WorldProperties mvworld = worldsFromTheConfig.get(worldName); World cbworld; try { cbworld = creator.createWorld(); @@ -394,9 +397,9 @@ public class WorldManager implements MVWorldManager { brokenWorld(worldName); return false; } - mvworld.init(cbworld, plugin); - this.worldPurger.purgeWorld(mvworld); - this.worlds.put(worldName, mvworld); + MVWorld world = new MVWorld(plugin, cbworld, mvworld); + this.worldPurger.purgeWorld(world); + this.worlds.put(worldName, world); return true; } @@ -636,7 +639,7 @@ public class WorldManager implements MVWorldManager { this.worlds.clear(); } - for (Map.Entry entry : worldsFromTheConfig.entrySet()) { + for (Map.Entry entry : worldsFromTheConfig.entrySet()) { if (worlds.containsKey(entry.getKey())) { continue; } @@ -696,31 +699,23 @@ public class WorldManager implements MVWorldManager { // load world-objects Stack worldKeys = new Stack(); worldKeys.addAll(this.configWorlds.getConfigurationSection("worlds").getKeys(false)); - Map newWorldsFromTheConfig = new HashMap(); + Map newWorldsFromTheConfig = new HashMap(); while (!worldKeys.isEmpty()) { String key = worldKeys.pop(); String path = "worlds" + SEPARATOR + key; Object obj = this.configWorlds.get(path); - if ((obj != null) && (obj instanceof MVWorld)) { + if ((obj != null) && (obj instanceof WorldProperties)) { String worldName = key.replaceAll(String.valueOf(SEPARATOR), "."); - MVWorld mvWorld = null; + WorldProperties props = (WorldProperties) obj; if (this.worldsFromTheConfig.containsKey(worldName)) { // Object-Recycling :D // TODO Why is is checking worldsFromTheConfig and then getting from worlds? So confused... (DTM) - mvWorld = (MVWorld) this.worlds.get(worldName); + MVWorld mvWorld = (MVWorld) this.worlds.get(worldName); if (mvWorld != null) { - mvWorld.copyValues((MVWorld) obj); + mvWorld.copyValues((WorldProperties) obj); } } - if (mvWorld == null) { - // we have to use a new one - World cbworld = this.plugin.getServer().getWorld(worldName); - mvWorld = (MVWorld) obj; - if (cbworld != null) { - mvWorld.init(cbworld, this.plugin); - } - } - newWorldsFromTheConfig.put(worldName, mvWorld); + newWorldsFromTheConfig.put(worldName, props); } else if (this.configWorlds.isConfigurationSection(path)) { ConfigurationSection section = this.configWorlds.getConfigurationSection(path); Set subkeys = section.getKeys(false); @@ -742,7 +737,7 @@ public class WorldManager implements MVWorldManager { try { this.configWorlds.options().pathSeparator(SEPARATOR); this.configWorlds.set("worlds", null); - for (Map.Entry entry : worldsFromTheConfig.entrySet()) { + for (Map.Entry entry : worldsFromTheConfig.entrySet()) { this.configWorlds.set("worlds" + SEPARATOR + entry.getKey(), entry.getValue()); } this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml")); diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestDebugMode.java b/src/test/java/com/onarandombox/MultiverseCore/TestDebugMode.java similarity index 94% rename from src/test/java/com/onarandombox/MultiverseCore/test/TestDebugMode.java rename to src/test/java/com/onarandombox/MultiverseCore/TestDebugMode.java index 10f82651..3e446dc6 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestDebugMode.java +++ b/src/test/java/com/onarandombox/MultiverseCore/TestDebugMode.java @@ -5,17 +5,11 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.File; +package com.onarandombox.MultiverseCore; +import com.onarandombox.MultiverseCore.api.Core; +import com.onarandombox.MultiverseCore.utils.TestInstanceCreator; import junit.framework.Assert; - import org.bukkit.Server; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -28,9 +22,12 @@ import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.Core; -import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; +import java.io.File; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; @RunWith(PowerMockRunner.class) @PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class }) diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestEntitySpawnRules.java b/src/test/java/com/onarandombox/MultiverseCore/TestEntitySpawnRules.java similarity index 96% rename from src/test/java/com/onarandombox/MultiverseCore/test/TestEntitySpawnRules.java rename to src/test/java/com/onarandombox/MultiverseCore/TestEntitySpawnRules.java index de2745c7..001b10a8 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestEntitySpawnRules.java +++ b/src/test/java/com/onarandombox/MultiverseCore/TestEntitySpawnRules.java @@ -1,13 +1,9 @@ -package com.onarandombox.MultiverseCore.test; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +package com.onarandombox.MultiverseCore; +import com.onarandombox.MultiverseCore.api.MVWorldManager; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.listeners.MVEntityListener; +import com.onarandombox.MultiverseCore.utils.TestInstanceCreator; import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -24,11 +20,13 @@ import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.listeners.MVEntityListener; -import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; @RunWith(PowerMockRunner.class) @PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class }) diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestModifyCommand.java b/src/test/java/com/onarandombox/MultiverseCore/TestModifyCommand.java similarity index 89% rename from src/test/java/com/onarandombox/MultiverseCore/test/TestModifyCommand.java rename to src/test/java/com/onarandombox/MultiverseCore/TestModifyCommand.java index 6eff3363..aaa869b7 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestModifyCommand.java +++ b/src/test/java/com/onarandombox/MultiverseCore/TestModifyCommand.java @@ -1,8 +1,7 @@ -package com.onarandombox.MultiverseCore.test; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +package com.onarandombox.MultiverseCore; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.utils.TestInstanceCreator; import org.bukkit.Server; import org.bukkit.World.Environment; import org.bukkit.command.Command; @@ -15,9 +14,9 @@ import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; @RunWith(PowerMockRunner.class) diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldProperties.java b/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java similarity index 98% rename from src/test/java/com/onarandombox/MultiverseCore/test/TestWorldProperties.java rename to src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java index ca75a04b..ffb2c007 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldProperties.java +++ b/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java @@ -5,15 +5,13 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore; -import com.onarandombox.MultiverseCore.MVWorld; -import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.configuration.SpawnLocation; import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener; -import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; +import com.onarandombox.MultiverseCore.utils.TestInstanceCreator; import com.onarandombox.MultiverseCore.utils.WorldManager; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -300,7 +298,8 @@ public class TestWorldProperties { assertTrue(core.saveMVConfigs()); // change a value here FileConfiguration config = YamlConfiguration.loadConfiguration(new File(core.getDataFolder(), "worlds.yml")); - MVWorld worldObj = (MVWorld) config.get("worlds.world"); + WorldProperties worldObj = (WorldProperties) config.get("worlds.world"); + System.out.println(worldObj.setColor("GREEN")); assertTrue(worldObj.setColor("GREEN")); config.set("worlds.world", worldObj); config.save(new File(core.getDataFolder(), "worlds.yml")); diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldPurger.java b/src/test/java/com/onarandombox/MultiverseCore/TestWorldPurger.java similarity index 95% rename from src/test/java/com/onarandombox/MultiverseCore/test/TestWorldPurger.java rename to src/test/java/com/onarandombox/MultiverseCore/TestWorldPurger.java index f4e0104e..ad2cd376 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldPurger.java +++ b/src/test/java/com/onarandombox/MultiverseCore/TestWorldPurger.java @@ -1,10 +1,8 @@ -package com.onarandombox.MultiverseCore.test; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -import java.util.Arrays; +package com.onarandombox.MultiverseCore; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.api.WorldPurger; +import com.onarandombox.MultiverseCore.utils.TestInstanceCreator; import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -18,10 +16,10 @@ import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.api.WorldPurger; -import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; +import java.util.Arrays; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; @RunWith(PowerMockRunner.class) @PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class }) diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java b/src/test/java/com/onarandombox/MultiverseCore/TestWorldStuff.java similarity index 97% rename from src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java rename to src/test/java/com/onarandombox/MultiverseCore/TestWorldStuff.java index e8baa2d8..d93f4782 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java +++ b/src/test/java/com/onarandombox/MultiverseCore/TestWorldStuff.java @@ -5,15 +5,18 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore; -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.TestInstanceCreator; +import com.onarandombox.MultiverseCore.utils.WorldCreatorMatcher; import com.onarandombox.MultiverseCore.utils.WorldManager; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Server; +import org.bukkit.WorldCreator; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MVTestLogFormatter.java b/src/test/java/com/onarandombox/MultiverseCore/utils/MVTestLogFormatter.java similarity index 96% rename from src/test/java/com/onarandombox/MultiverseCore/test/utils/MVTestLogFormatter.java rename to src/test/java/com/onarandombox/MultiverseCore/utils/MVTestLogFormatter.java index a26c235e..8828275d 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MVTestLogFormatter.java +++ b/src/test/java/com/onarandombox/MultiverseCore/utils/MVTestLogFormatter.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test.utils; +package com.onarandombox.MultiverseCore.utils; import java.io.PrintWriter; import java.io.StringWriter; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java b/src/test/java/com/onarandombox/MultiverseCore/utils/MockWorldFactory.java similarity index 99% rename from src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java rename to src/test/java/com/onarandombox/MultiverseCore/utils/MockWorldFactory.java index 72daf003..41e34614 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java +++ b/src/test/java/com/onarandombox/MultiverseCore/utils/MockWorldFactory.java @@ -5,16 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test.utils; - -import static org.mockito.Mockito.*; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; +package com.onarandombox.MultiverseCore.utils; import org.bukkit.Difficulty; import org.bukkit.Location; @@ -26,6 +17,15 @@ import org.bukkit.generator.ChunkGenerator; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; + +import static org.mockito.Mockito.*; + public class MockWorldFactory { private static final Map createdWorlds = new HashMap(); diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java b/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java similarity index 98% rename from src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java rename to src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java index 3b3a6b7b..a125d298 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test.utils; +package com.onarandombox.MultiverseCore.utils; import buscript.Buscript; import com.onarandombox.MultiverseCore.MultiverseCore; @@ -13,8 +13,6 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.listeners.MVEntityListener; import com.onarandombox.MultiverseCore.listeners.MVPlayerListener; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; -import com.onarandombox.MultiverseCore.utils.FileUtils; -import com.onarandombox.MultiverseCore.utils.WorldManager; import junit.framework.Assert; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/Util.java b/src/test/java/com/onarandombox/MultiverseCore/utils/Util.java similarity index 97% rename from src/test/java/com/onarandombox/MultiverseCore/test/utils/Util.java rename to src/test/java/com/onarandombox/MultiverseCore/utils/Util.java index badd95ea..dd00e021 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/Util.java +++ b/src/test/java/com/onarandombox/MultiverseCore/utils/Util.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test.utils; +package com.onarandombox.MultiverseCore.utils; import java.util.logging.ConsoleHandler; import java.util.logging.Handler; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java b/src/test/java/com/onarandombox/MultiverseCore/utils/WorldCreatorMatcher.java similarity index 97% rename from src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java rename to src/test/java/com/onarandombox/MultiverseCore/utils/WorldCreatorMatcher.java index 529906fd..50d3682b 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java +++ b/src/test/java/com/onarandombox/MultiverseCore/utils/WorldCreatorMatcher.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test.utils; +package com.onarandombox.MultiverseCore.utils; import org.bukkit.WorldCreator; import org.mockito.ArgumentMatcher;