From dc0121509a942040ef76a9d6b7177164a0c0b6f1 Mon Sep 17 00:00:00 2001 From: "main()" Date: Thu, 12 Jan 2012 19:01:10 +0100 Subject: [PATCH 01/13] Fixed shouldWeKillThisCreature() in MVEntityListener. --- .../MultiverseCore/listeners/MVEntityListener.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java index f01b8949..f393bbde 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java @@ -124,7 +124,7 @@ public class MVEntityListener extends EntityListener { } else if (creatureList.isEmpty()) { // 2. There are no exceptions and animals are NOT allowed. Kill it. return true; - } else if (creatureList.contains(creature) && allowCreatureSpawning) { + } else if (creatureList.contains(creature.toUpperCase()) && allowCreatureSpawning) { // 3. There ARE exceptions and animals ARE allowed. Kill it. return true; } else if (!creatureList.contains(creature.toUpperCase()) && allowCreatureSpawning) { @@ -136,9 +136,10 @@ public class MVEntityListener extends EntityListener { } else if (!creatureList.contains(creature.toUpperCase()) && !allowCreatureSpawning) { // 6. Animals are NOT allowed to spawn, and this creature is not in the save list... KILL IT return true; + } else { + // This code should NEVER execute. I just left the verbose conditions in right now. + throw new UnsupportedOperationException(); } - // This code should NEVER execute. I just left the verbose conditions in right now. - return false; } } From 04366dd50eb1d5022d52f20b8090aca562776e0b Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Fri, 13 Jan 2012 17:48:15 -0700 Subject: [PATCH 02/13] Fix Properties not loading properly Closes #397 This also fixes Active Properties not saving properly --- .../com/onarandombox/MultiverseCore/MVWorld.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 22272601..a91775d7 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -204,6 +204,15 @@ public class MVWorld implements MultiverseWorld { } catch (IllegalArgumentException e) { this.plugin.log(Level.FINER, "Permissions nodes were already added for " + this.name); } + + // Sync all active settings. + this.setActualPVP(); + this.verifyScaleSetProperly(); + this.setActualKeepSpawnInMemory(); + this.setActualDifficulty(); + this.setActualGameMode(); + this.setActualSpawn(); + this.syncMobs(); } /** @@ -549,8 +558,12 @@ public class MVWorld implements MultiverseWorld { Method method = this.getClass().getMethod(property.getMethod()); Object returnVal = method.invoke(this); if (returnVal instanceof Boolean) { + if ((Boolean) returnVal) { + this.saveConfig(); + } return (Boolean) returnVal; } else { + this.saveConfig(); return true; } } catch (NoSuchMethodException e) { From b2457f38b194ca3f74a364eb7cb0e1f8b0258dc7 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Fri, 13 Jan 2012 18:48:16 -0700 Subject: [PATCH 03/13] Bump version to 2.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bce86ba9..88058d8c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.onarandombox.multiversecore Multiverse-Core - 2.2 + 2.3 Multiverse-Core World Management Plugin From 7f93eedbac09f0631f9f7b0b6704474b6670b275 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 14 Jan 2012 13:57:31 -0700 Subject: [PATCH 04/13] Spout fixed mentioned issue! Commit it was fixed in: https://github.com/SpoutDev/SpoutPlugin/commit/1157e6b6422ae156dd692f38e895ae0c5c5570a2 Build it was fixed in: http://ci.spout.org/job/SpoutPlugin/681/ --- .../com/onarandombox/MultiverseCore/MultiverseCore.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 72d6ecd3..59bcd135 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -718,15 +718,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { public void setSpout() { this.spoutInterface = new SpoutInterface(); this.commandHandler.registerCommand(new SpoutCommand(this)); - if (FirstSpawnOverride) { - this.log(Level.WARNING, "Disabling MV's 'firstspawnoverride', since spout doesn't handle new players well yet."); - this.log(Level.WARNING, "This means *new players* may not spawn where you've set your \"mvspawn\" AND"); - this.log(Level.WARNING, "the config value 'firstspawnworld' will have NO effect!!!"); - this.log(Level.WARNING, "Talk to the Spout devs to get this fixed!"); - this.log(Level.WARNING, " --FernFerret"); - FirstSpawnOverride = false; - this.multiverseConfig.set("firstspawnoverride", false); - } } /** From 0f3fd89228458716f2a72a1a8b8e4080b542baca Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 15 Jan 2012 13:15:01 -0700 Subject: [PATCH 05/13] Add new WorldTypes to Multiverse This closed #394 --- pom.xml | 2 +- .../onarandombox/MultiverseCore/MVWorld.java | 13 ++++ .../MultiverseCore/MultiverseCore.java | 28 --------- .../MultiverseCore/api/MVWorldManager.java | 7 ++- .../MultiverseCore/api/MultiverseWorld.java | 15 ++++- .../commands/CreateCommand.java | 19 +++++- .../commands/EnvironmentCommand.java | 63 ++++++++++++++++++- .../commands/ImportCommand.java | 19 +++++- .../MultiverseCore/utils/WorldManager.java | 50 ++++++++------- .../test/utils/MockWorldFactory.java | 12 ++-- .../test/utils/TestInstanceCreator.java | 2 +- 11 files changed, 161 insertions(+), 69 deletions(-) diff --git a/pom.xml b/pom.xml index 88058d8c..146295f7 100644 --- a/pom.xml +++ b/pom.xml @@ -162,7 +162,7 @@ org.bukkit bukkit - 1.0.0-R1-SNAPSHOT + 1.1-R1-SNAPSHOT jar compile diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index a91775d7..74c2fad0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -23,6 +23,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.World.Environment; +import org.bukkit.WorldType; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -68,6 +69,7 @@ public class MVWorld implements MultiverseWorld { private Permission ignoreperm; private static final Map TIME_ALIASES; + private WorldType type; static { Map staticTimes = new HashMap(); @@ -90,6 +92,7 @@ public class MVWorld implements MultiverseWorld { this.name = world.getName(); this.seed = seed; this.environment = world.getEnvironment(); + this.type = world.getWorldType(); // Initialize our lists this.initLists(); @@ -107,6 +110,8 @@ public class MVWorld implements MultiverseWorld { } worldSection.set("environment", this.environment.toString()); + worldSection.set("type", this.type.toString()); + // Start NEW config awesomeness. ConfigPropertyFactory fac = new ConfigPropertyFactory(this.worldSection); this.propertyList = new HashMap>(); @@ -1145,6 +1150,14 @@ public class MVWorld implements MultiverseWorld { return String.format("%d:%02d", hours, minutes); } + /** + * {@inheritDoc} + */ + @Override + public WorldType getWorldType() { + return this.type; + } + /** * Used by the active time-property to set the "actual" property. * @return True if the property was successfully set. diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 59bcd135..60b44ecb 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -38,7 +38,6 @@ import com.onarandombox.MultiverseCore.utils.WorldManager; import com.pneumaticraft.commandhandler.CommandHandler; import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.World.Environment; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.configuration.Configuration; @@ -582,33 +581,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { return MultiverseCore.LOG_TAG; } - // TODO This code should get moved somewhere more appropriate, but for now, it's here. - // TODO oh, and it should be static. - /** - * Converts a {@link String} into an {@link Environment}. - * - * @param env The environment as {@link String} - * @return The environment as {@link Environment} - */ - 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 - if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER")) - env = "NETHER"; - - if (env.equalsIgnoreCase("END") || env.equalsIgnoreCase("THEEND") || env.equalsIgnoreCase("STARWARS")) - env = "THE_END"; - - if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD")) - env = "NORMAL"; - - try { - // If the value wasn't found, maybe it's new, try checking the enum directly. - return Environment.valueOf(env); - } catch (IllegalArgumentException e) { - return null; - } - } - /** * Shows a message that the given world is not a MultiverseWorld. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java index 75cc9da7..40300ef0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java @@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.api; import com.onarandombox.MultiverseCore.utils.PurgeWorlds; import org.bukkit.World; import org.bukkit.World.Environment; +import org.bukkit.WorldType; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.generator.ChunkGenerator; @@ -32,10 +33,11 @@ public interface MVWorldManager { * @param seedString The seed in the form of a string. * If the seed is a Long, * it will be interpreted as such. + * @param type The Type of the world to be made. * @param generator The Custom generator plugin to use. * @return True if the world is added, false if not. */ - boolean addWorld(String name, Environment env, String seedString, String generator); + boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator); /** * Add a new World to the Multiverse Setup. @@ -45,11 +47,12 @@ public interface MVWorldManager { * @param seedString The seed in the form of a string. * If the seed is a Long, * it will be interpreted as such. + * @param type The Type of the world to be made. * @param generator The Custom generator plugin to use. * @param useSpawnAdjust If true, multiverse will search for a safe spawn. If not, It will not modify the level.dat. * @return True if the world is added, false if not. */ - boolean addWorld(String name, Environment env, String seedString, String generator, boolean useSpawnAdjust); + boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator, boolean useSpawnAdjust); /** * Remove the world from the Multiverse list, from the diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index 7d878328..1b2cca3f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -15,6 +15,7 @@ import org.bukkit.Difficulty; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.WorldType; import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; @@ -22,8 +23,6 @@ import java.util.List; /** * The API for a Multiverse Handled World. - *

- * Currently INCOMPLETE */ public interface MultiverseWorld { @@ -536,7 +535,7 @@ public interface MultiverseWorld { /** * Sets the current time in a world. - * + *

* This method will take the following formats: * 11:37am * 4:30p @@ -552,4 +551,14 @@ public interface MultiverseWorld { * @return The time as a short string: 12:34pm */ String getTime(); + + /** + * Gets the type of this world. As of 1.1-R1 this will be: + * FLAT or NORMAL + *

+ * This is *not* the generator. + * + * @return The Type of this world. + */ + WorldType getWorldType(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index e6613c17..4479b753 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -12,6 +12,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.pneumaticraft.commandhandler.CommandHandler; import org.bukkit.ChatColor; import org.bukkit.World.Environment; +import org.bukkit.WorldType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.permissions.PermissionDefault; @@ -28,7 +29,7 @@ public class CreateCommand extends MultiverseCommand { public CreateCommand(MultiverseCore plugin) { super(plugin); this.setName("Create World"); - this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] [-n]"); + this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] -t [WORLDTYPE] [-n]"); this.setArgRange(2, 7); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.addKey("mvcreate"); this.addKey("mvc"); @@ -49,6 +50,7 @@ public class CreateCommand extends MultiverseCommand { String env = args.get(1); String seed = CommandHandler.getFlag("-s", args); String generator = CommandHandler.getFlag("-g", args); + String typeString = CommandHandler.getFlag("-t", args); boolean useSpawnAdjust = true; for (String s : args) { if (s.equalsIgnoreCase("-n")) { @@ -61,16 +63,27 @@ public class CreateCommand extends MultiverseCommand { return; } - Environment environment = this.plugin.getEnvFromString(env); + Environment environment = EnvironmentCommand.getEnvFromString(env); if (environment == null) { sender.sendMessage(ChatColor.RED + "That is not a valid environment."); EnvironmentCommand.showEnvironments(sender); return; } + // If they didn't specify a type, default to NORMAL + if (typeString == null) { + typeString = "NORMAL"; + } + WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString); + if (type == null) { + sender.sendMessage(ChatColor.RED + "That is not a valid World Type."); + EnvironmentCommand.showWorldTypes(sender); + return; + } + Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'..."); - if (this.worldManager.addWorld(worldName, environment, seed, generator, useSpawnAdjust)) { + if (this.worldManager.addWorld(worldName, environment, seed, type, generator, useSpawnAdjust)) { Command.broadcastCommandMessage(sender, "Complete!"); } else { Command.broadcastCommandMessage(sender, "FAILED."); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java index 5612340c..4531b39e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java @@ -9,6 +9,8 @@ package com.onarandombox.MultiverseCore.commands; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.WorldType; import org.bukkit.command.CommandSender; import org.bukkit.permissions.PermissionDefault; @@ -26,10 +28,11 @@ public class EnvironmentCommand extends MultiverseCommand { this.setArgRange(0, 0); this.addKey("mvenv"); this.addKey("mv env"); + this.addKey("mv type"); this.addKey("mv environment"); this.addKey("mv environments"); this.addCommandExample("/mv env"); - this.setPermission("multiverse.core.list.environments", "Lists valid known environments.", PermissionDefault.OP); + this.setPermission("multiverse.core.list.environments", "Lists valid known environments/world types.", PermissionDefault.OP); } /** @@ -43,9 +46,67 @@ public class EnvironmentCommand extends MultiverseCommand { sender.sendMessage(ChatColor.RED + "NETHER"); sender.sendMessage(ChatColor.AQUA + "END"); } + /** + * Shows all valid known world types to a {@link CommandSender}. + * + * @param sender The {@link CommandSender}. + */ + public static void showWorldTypes(CommandSender sender) { + sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:"); + sender.sendMessage(String.format("%sNORMAL %sor %sFLAT", + ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA)); + } @Override public void runCommand(CommandSender sender, List args) { EnvironmentCommand.showEnvironments(sender); + EnvironmentCommand.showWorldTypes(sender); + } + + /** + * Converts a {@link String} into a {@link WorldType}. + * + * @param type The WorldType as a {@link String} + * @return The WorldType as a {@link WorldType} + */ + public static WorldType getWorldTypeFromString(String type) { + // Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way + if (type.equalsIgnoreCase("normal")) + type = "NORMAL"; + if (type.equalsIgnoreCase("flat")) + type = "FLAT"; + try { + // Now that we've converted a potentially unfriendly value + // to a friendly one, get it from the ENUM! + return WorldType.valueOf(type); + } catch (IllegalArgumentException e) { + return null; + } + } + + /** + * Converts a {@link String} into an {@link org.bukkit.World.Environment}. + * + * @param env The environment as {@link String} + * @return The environment as {@link org.bukkit.World.Environment} + */ + public static World.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 + if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER")) + env = "NETHER"; + + if (env.equalsIgnoreCase("END") || env.equalsIgnoreCase("THEEND") || env.equalsIgnoreCase("STARWARS")) + env = "THE_END"; + + if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD")) + env = "NORMAL"; + + try { + // Now that we've converted a potentially unfriendly value + // to a friendly one, get it from the ENUM! + return World.Environment.valueOf(env); + } catch (IllegalArgumentException e) { + return null; + } } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java index 4c197a0c..a3adcdfe 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java @@ -13,6 +13,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.pneumaticraft.commandhandler.CommandHandler; import org.bukkit.ChatColor; import org.bukkit.World.Environment; +import org.bukkit.WorldType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.permissions.PermissionDefault; @@ -126,6 +127,7 @@ public class ImportCommand extends MultiverseCommand { File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName); String generator = CommandHandler.getFlag("-g", args); + String typeString = CommandHandler.getFlag("-t", args); boolean useSpawnAdjust = true; for (String s : args) { if (s.equalsIgnoreCase("-n")) { @@ -134,16 +136,27 @@ public class ImportCommand extends MultiverseCommand { } String env = args.get(1); - Environment environment = this.plugin.getEnvFromString(env); + Environment environment = EnvironmentCommand.getEnvFromString(env); if (environment == null) { sender.sendMessage(ChatColor.RED + "That is not a valid environment."); EnvironmentCommand.showEnvironments(sender); return; } + // If they didn't specify a type, default to NORMAL + if (typeString == null) { + typeString = "NORMAL"; + } + WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString); + if (type == null) { + sender.sendMessage(ChatColor.RED + "That is not a valid World Type."); + EnvironmentCommand.showWorldTypes(sender); + return; + } + if (worldFile.exists() && env != null) { - Command.broadcastCommandMessage(sender, "Starting import of world '" + worldName + "'..."); - if (this.worldManager.addWorld(worldName, environment, null, generator, useSpawnAdjust)) + Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName)); + if (this.worldManager.addWorld(worldName, environment, null, type, generator, useSpawnAdjust)) Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!"); else Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!"); diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index 71390cd8..b8bc41fb 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -11,10 +11,12 @@ 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.commands.EnvironmentCommand; import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldCreator; +import org.bukkit.WorldType; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -80,16 +82,16 @@ public class WorldManager implements MVWorldManager { * {@inheritDoc} */ @Override - public boolean addWorld(String name, Environment env, String seedString, String generator) { - return this.addWorld(name, env, seedString, generator, true); + public boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator) { + return this.addWorld(name, env, seedString, type, generator, true); } /** * {@inheritDoc} */ @Override - public boolean addWorld(String name, Environment env, String seedString, String generator, boolean useSpawnAdjust) { - plugin.log(Level.FINE, "Adding world with: " + name + ", " + env.toString() + ", " + seedString + ", " + generator); + public boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator, boolean useSpawnAdjust) { + plugin.log(Level.FINE, "Adding world with: " + name + ", " + env.toString() + ", " + seedString + ", " + type.toString() + ", " + generator); Long seed = null; WorldCreator c = new WorldCreator(name); if (seedString != null && seedString.length() > 0) { @@ -101,27 +103,26 @@ public class WorldManager implements MVWorldManager { c.seed(seed); } - // TODO: Use the fancy kind with the commandSender if (generator != null && generator.length() != 0) { c.generator(generator); } c.environment(env); + c.type(type); - World world = null; + World world; + StringBuilder builder = new StringBuilder(); + builder.append("Loading World & Settings - '").append(name).append("'"); + builder.append(" - Env: ").append(env); + builder.append(" - Type: ").append(type); if (seed != null) { - if (generator != null) { - this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed + " & Custom Generator: " + generator); - } else { - this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed); - } - } else { - if (generator != null) { - this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " & Custom Generator: " + generator); - } else { - this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env); - } + builder.append(" & seed: ").append(seed); } + if (generator != null) { + builder.append(" & generator: ").append(generator); + } + this.plugin.log(Level.INFO, builder.toString()); + try { world = c.createWorld(); } catch (Exception e) { @@ -275,10 +276,12 @@ public class WorldManager implements MVWorldManager { if ((worldKeys != null) && (worldKeys.contains(name))) { // Grab the initial values from the config file. String environment = this.configWorlds.getString("worlds." + name + ".environment", "NORMAL"); // Grab the Environment as a String. + String type = this.configWorlds.getString("worlds." + name + ".type", "NORMAL"); String seedString = this.configWorlds.getString("worlds." + name + ".seed", ""); String generatorString = this.configWorlds.getString("worlds." + name + ".generator"); - addWorld(name, this.plugin.getEnvFromString(environment), seedString, generatorString); + addWorld(name, EnvironmentCommand.getEnvFromString(environment), seedString, + EnvironmentCommand.getWorldTypeFromString(type), generatorString); if (this.unloadedWorlds.contains(name)) { this.unloadedWorlds.remove(name); } @@ -464,9 +467,9 @@ public class WorldManager implements MVWorldManager { String name = w.getName(); if (!worldStrings.contains(name)) { if (this.defaultGens.containsKey(name)) { - this.addWorld(name, w.getEnvironment(), w.getSeed() + "", this.defaultGens.get(name)); + this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(), this.defaultGens.get(name)); } else { - this.addWorld(name, w.getEnvironment(), w.getSeed() + "", null); + this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(), null); } } @@ -537,7 +540,8 @@ public class WorldManager implements MVWorldManager { continue; } // Grab the initial values from the config file. - String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String. + String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); + String type = this.configWorlds.getString("worlds." + worldKey + ".type", "NORMAL"); String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", null); if (seedString == null) { seedString = this.configWorlds.getLong("worlds." + worldKey + ".seed") + ""; @@ -548,7 +552,9 @@ public class WorldManager implements MVWorldManager { this.plugin.log(Level.WARNING, "Found SKYLANDS world. Not importing automatically, as it won't work atm :("); continue; } - addWorld(worldKey, this.plugin.getEnvFromString(environment), seedString, generatorString); + // TODO: UNCOMMENT BEFORE RELEASE + addWorld(worldKey, EnvironmentCommand.getEnvFromString(environment), seedString, + EnvironmentCommand.getWorldTypeFromString(type), generatorString); // Increment the world count count++; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java index 1df477ae..1528e073 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java @@ -19,6 +19,7 @@ import java.util.Map; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.WorldType; import org.bukkit.generator.ChunkGenerator; import org.mockito.ArgumentMatcher; import org.mockito.Matchers; @@ -81,10 +82,11 @@ public class MockWorldFactory { createdWorlds.put(world.getName(), world); } - private static World basics(String world, World.Environment env) { + private static World basics(String world, World.Environment env, WorldType type) { World mockWorld = mock(World.class); when(mockWorld.getName()).thenReturn(world); when(mockWorld.getEnvironment()).thenReturn(env); + when(mockWorld.getWorldType()).thenReturn(type); when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 0, 0)); when(mockWorld.getWorldFolder()).thenAnswer(new Answer() { public File answer(InvocationOnMock invocation) throws Throwable { @@ -101,15 +103,15 @@ public class MockWorldFactory { return mockWorld; } - public static World makeNewMockWorld(String world, World.Environment env) { - World w = basics(world, env); + public static World makeNewMockWorld(String world, World.Environment env, WorldType type) { + World w = basics(world, env, type); registerWorld(w); return w; } - public static World makeNewMockWorld(String world, World.Environment env, long seed, + public static World makeNewMockWorld(String world, World.Environment env, WorldType type, long seed, ChunkGenerator generator) { - World mockWorld = basics(world, env); + World mockWorld = basics(world, env, type); when(mockWorld.getGenerator()).thenReturn(generator); when(mockWorld.getSeed()).thenReturn(seed); registerWorld(mockWorld); 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 ce6471ef..195eaff4 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java @@ -122,7 +122,7 @@ public class TestInstanceCreator { } catch (Exception e) { return null; } - return MockWorldFactory.makeNewMockWorld(arg.name(), arg.environment()); + return MockWorldFactory.makeNewMockWorld(arg.name(), arg.environment(), arg.type()); } }); From c22acd6dd19c914575d24cea11c1276296558566 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 15 Jan 2012 13:29:35 -0700 Subject: [PATCH 06/13] Fix arg range errors, add examples of WorldType. --- .../onarandombox/MultiverseCore/commands/CreateCommand.java | 3 ++- .../onarandombox/MultiverseCore/commands/ImportCommand.java | 5 +++-- .../onarandombox/MultiverseCore/commands/InfoCommand.java | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index 4479b753..ffc3533d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -30,7 +30,7 @@ public class CreateCommand extends MultiverseCommand { super(plugin); this.setName("Create World"); this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] -t [WORLDTYPE] [-n]"); - this.setArgRange(2, 7); // SUPPRESS CHECKSTYLE: MagicNumberCheck + this.setArgRange(2, 9); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.addKey("mvcreate"); this.addKey("mvc"); this.addKey("mv create"); @@ -38,6 +38,7 @@ public class CreateCommand extends MultiverseCommand { this.addCommandExample("/mv create " + ChatColor.GOLD + "world" + ChatColor.GREEN + " normal"); this.addCommandExample("/mv create " + ChatColor.GOLD + "lavaland" + ChatColor.RED + " nether"); this.addCommandExample("/mv create " + ChatColor.GOLD + "starwars" + ChatColor.AQUA + " end"); + this.addCommandExample("/mv create " + ChatColor.GOLD + "flatroom" + ChatColor.GREEN + " normal" + ChatColor.AQUA + " -t flat"); this.addCommandExample("/mv create " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -s gargamel"); this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon"); this.worldManager = this.plugin.getMVWorldManager(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java index a3adcdfe..bbb1edbc 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java @@ -33,12 +33,13 @@ public class ImportCommand extends MultiverseCommand { public ImportCommand(MultiverseCore plugin) { super(plugin); this.setName("Import World"); - this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n]"); - this.setArgRange(1, 3); + this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n] -t [TYPE]"); + this.setArgRange(2, 5); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.addKey("mvimport"); this.addKey("mvim"); this.addKey("mv import"); this.addCommandExample("/mv import " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal"); + this.addCommandExample("/mv import " + ChatColor.GOLD + "flatroom" + ChatColor.GREEN + " normal" + ChatColor.AQUA + " -t flat"); this.addCommandExample("/mv import " + ChatColor.GOLD + "hell_world" + ChatColor.GREEN + " nether"); this.addCommandExample("/mv import " + ChatColor.GOLD + "CleanRoom" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " CleanRoomGenerator"); this.setPermission("multiverse.core.import", "Imports a new world of the specified type.", PermissionDefault.OP); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java index 39fb5821..dffbd882 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java @@ -110,6 +110,7 @@ public class InfoCommand extends MultiverseCommand { message.add(new FancyMessage("World Name: ", world.getName(), colors)); message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors)); message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors)); + message.add(new FancyMessage("World Type: ", world.getWorldType().toString(), colors)); //message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors)); Location spawn = world.getSpawnLocation(); message.add(new FancyMessage("Spawn Location: ", LocationManipulation.strCoords(spawn), colors)); From 9313ff82ae0e539806c21e197f5d6c60ba2e4d86 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 15 Jan 2012 14:17:51 -0700 Subject: [PATCH 07/13] Bump protocol to 11, since we changed the api classes --- .../java/com/onarandombox/MultiverseCore/MultiverseCore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 60b44ecb..64f9e747 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -64,7 +64,7 @@ import java.util.logging.Logger; * The implementation of the Multiverse-{@link Core}. */ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { - private static final int PROTOCOL = 10; + private static final int PROTOCOL = 11; // Global Multiverse config variable, states whether or not // Multiverse should stop other plugins from teleporting players // to worlds. From 7b8f73f0af7c0743ffd6c9c8fd7ab5268a7c65d9 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Mon, 16 Jan 2012 19:45:29 -0700 Subject: [PATCH 08/13] Bump Allpay version. This adds EconXP support. --- lib/allpay | 2 +- pom.xml | 9 ++++++++- .../com/onarandombox/MultiverseCore/MultiverseCore.java | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/allpay b/lib/allpay index 18c55a90..7abba1f0 160000 --- a/lib/allpay +++ b/lib/allpay @@ -1 +1 @@ -Subproject commit 18c55a9070a5e64b2cb0737940290643f324fa7d +Subproject commit 7abba1f0040862e9fabdafb3d44c6cf0b914cc7c diff --git a/pom.xml b/pom.xml index 146295f7..47364a2d 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ - ${project.basedir}/lib/allpay/src + ${project.basedir}/lib/allpay/src/main/java ${project.basedir}/lib/commandhandler/src ${project.basedir}/lib/commandhandler/lib/ShellParser/src @@ -229,6 +229,13 @@ jar compile + + ca.agnate + EconXP + 1.0.0 + jar + compile + diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 64f9e747..e10965ae 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -171,7 +171,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { private int pluginCount; private DestinationFactory destFactory; private SpoutInterface spoutInterface = null; - private static final double ALLPAY_VERSION = 3; + private static final double ALLPAY_VERSION = 5; private static final double CH_VERSION = 4; private MVMessaging messaging; From 21571bf54bf96599391a2f389a93f4df6d5eb453 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 22 Jan 2012 14:20:45 -0700 Subject: [PATCH 09/13] Made MockBlock compatible with latest 1.1 builds --- .../MultiverseCore/test/utils/MockBlock.java | 252 ++++++------------ 1 file changed, 88 insertions(+), 164 deletions(-) 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 b5d12199..57e6a331 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java @@ -12,6 +12,9 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.*; +import org.bukkit.inventory.ItemStack; + +import java.util.Collection; /** * Multiverse 2 @@ -27,35 +30,31 @@ public class MockBlock implements Block{ } /** - * Gets the metadata for this block - * - * @return block specific metadata + * {@inheritDoc} */ @Override public byte getData() { return 0; } - /** @deprecated use {@link #getRelative(org.bukkit.block.BlockFace face)} */ + /** + * {@inheritDoc} + */ @Override public Block getFace(BlockFace face) { return null; } - /** @deprecated use {@link #getRelative(org.bukkit.block.BlockFace face, int distance)} */ + /** + * {@inheritDoc} + */ @Override public Block getFace(BlockFace face, int distance) { return null; } /** - * Gets the block at the given offsets - * - * @param modX X-coordinate offset - * @param modY Y-coordinate offset - * @param modZ Z-coordinate offset - * - * @return Block at the given offsets + * {@inheritDoc} */ @Override public Block getRelative(int modX, int modY, int modZ) { @@ -63,15 +62,7 @@ public class MockBlock implements Block{ } /** - * Gets the block at the given face
- *
- * This method is equal to getRelative(face, 1) - * - * @param face Face of this block to return - * - * @return Block at the given face - * - * @see #getRelative(org.bukkit.block.BlockFace, int) + * {@inheritDoc} */ @Override public Block getRelative(BlockFace face) { @@ -79,20 +70,7 @@ public class MockBlock implements Block{ } /** - * Gets the block at the given distance of the given face
- *
- * For example, the following method places water at 100,102,100; two blocks - * above 100,100,100. - *

-     * Block block = world.getBlockAt(100,100,100);
-     * Block shower = block.getFace(BlockFace.UP, 2);
-     * shower.setType(Material.WATER);
-     * 
- * - * @param face Face of this block to return - * @param distance Distance to get the block at - * - * @return Block at the given face + * {@inheritDoc} */ @Override public Block getRelative(BlockFace face, int distance) { @@ -100,9 +78,7 @@ public class MockBlock implements Block{ } /** - * Gets the type of this block - * - * @return block type + * {@inheritDoc} */ @Override public Material getType() { @@ -110,29 +86,33 @@ public class MockBlock implements Block{ } /** - * Gets the type-id of this block - * - * @return block type-id + * {@inheritDoc} */ @Override public int getTypeId() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } /** - * Gets the light level between 0-15 - * - * @return light level + * {@inheritDoc} */ @Override public byte getLightLevel() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; + } + + @Override + public byte getLightFromSky() { + return 0; + } + + @Override + public byte getLightFromBlocks() { + return 0; } /** - * Gets the world which contains this Block - * - * @return World containing this block + * {@inheritDoc} */ @Override public World getWorld() { @@ -140,9 +120,7 @@ public class MockBlock implements Block{ } /** - * Gets the x-coordinate of this block - * - * @return x-coordinate + * {@inheritDoc} */ @Override public int getX() { @@ -150,9 +128,7 @@ public class MockBlock implements Block{ } /** - * Gets the y-coordinate of this block - * - * @return y-coordinate + * {@inheritDoc} */ @Override public int getY() { @@ -160,9 +136,7 @@ public class MockBlock implements Block{ } /** - * Gets the z-coordinate of this block - * - * @return z-coordinate + * {@inheritDoc} */ @Override public int getZ() { @@ -170,9 +144,7 @@ public class MockBlock implements Block{ } /** - * Gets the Location of the block - * - * @return Location of block + * {@inheritDoc} */ @Override public Location getLocation() { @@ -180,34 +152,26 @@ public class MockBlock implements Block{ } /** - * Gets the chunk which contains this block - * - * @return Containing Chunk + * {@inheritDoc} */ @Override public Chunk getChunk() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } /** - * Sets the metadata for this block - * - * @param data New block specific metadata + * {@inheritDoc} */ @Override public void setData(byte data) { - //To change body of implemented methods use File | Settings | File Templates. } @Override public void setData(byte data, boolean applyPhyiscs) { - //To change body of implemented methods use File | Settings | File Templates. } /** - * Sets the type of this block - * - * @param type Material to change this block to + * {@inheritDoc} */ @Override public void setType(Material type) { @@ -215,145 +179,97 @@ public class MockBlock implements Block{ } /** - * Sets the type-id of this block - * - * @param type Type-Id to change this block to - * - * @return whether the block was changed + * {@inheritDoc} */ @Override public boolean setTypeId(int type) { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } @Override public boolean setTypeId(int type, boolean applyPhysics) { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } @Override public boolean setTypeIdAndData(int type, byte data, boolean applyPhyiscs) { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } /** - * Gets the face relation of this block compared to the given block
- *
- * For example: - *
-     * Block current = world.getBlockAt(100, 100, 100);
-     * Block target = world.getBlockAt(100, 101, 100);
-     *
-     * current.getFace(target) == BlockFace.Up;
-     * 
- *
- * If the given block is not connected to this block, null may be returned - * - * @param block Block to compare against this block - * - * @return BlockFace of this block which has the requested block, or null + * {@inheritDoc} */ @Override public BlockFace getFace(Block block) { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } /** - * 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. - * - * @return BlockState with the current state of this block. + * {@inheritDoc} */ @Override public BlockState getState() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } /** - * Returns the biome that this block resides in - * - * @return Biome type containing this block + * {@inheritDoc} */ @Override public Biome getBiome() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } /** - * Returns true if the block is being powered by Redstone. - * - * @return True if the block is powered. + * {@inheritDoc} */ @Override public boolean isBlockPowered() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } /** - * Returns true if the block is being indirectly powered by Redstone. - * - * @return True if the block is indirectly powered. + * {@inheritDoc} */ @Override public boolean isBlockIndirectlyPowered() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } /** - * Returns true if the block face is being powered by Redstone. - * - * @param face The block face - * - * @return True if the block face is powered. + * {@inheritDoc} */ @Override public boolean isBlockFacePowered(BlockFace face) { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } /** - * Returns true if the block face is being indirectly powered by Redstone. - * - * @param face The block face - * - * @return True if the block face is indirectly powered. + * {@inheritDoc} */ @Override public boolean isBlockFaceIndirectlyPowered(BlockFace face) { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } /** - * Returns the redstone power being provided to this block face - * - * @param face the face of the block to query or BlockFace.SELF for the block itself - * - * @return The power level. + * {@inheritDoc} */ @Override public int getBlockPower(BlockFace face) { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } /** - * Returns the redstone power being provided to this block - * - * @return The power level. + * {@inheritDoc} */ @Override public int getBlockPower() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } /** - * 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 + * {@inheritDoc} */ @Override public boolean isEmpty() { @@ -361,46 +277,54 @@ 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}. - * - * @return true if this block is liquid + * {@inheritDoc} */ @Override public boolean isLiquid() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return false; } /** - * Gets the temperature of the biome of this block - * - * @return Temperature of this block + * {@inheritDoc} */ @Override public double getTemperature() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } /** - * Gets the humidity of the biome of this block - * - * @return Humidity of this block + * {@inheritDoc} */ @Override public double getHumidity() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return 0; } /** - * Returns the reaction of the block when moved by a piston - * - * @return reaction + * {@inheritDoc} */ @Override public PistonMoveReaction getPistonMoveReaction() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; + } + + @Override + public boolean breakNaturally() { + return false; + } + + @Override + public boolean breakNaturally(ItemStack itemStack) { + return false; + } + + @Override + public Collection getDrops() { + return null; + } + + @Override + public Collection getDrops(ItemStack itemStack) { + return null; } } From bf76b77cf6c2f991d2be9c9b3b5624256bc87cb2 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 22 Jan 2012 14:21:18 -0700 Subject: [PATCH 10/13] Add New api methods, Write location format better Closes #411 --- .../com/onarandombox/MultiverseCore/MVWorld.java | 8 ++++++++ .../onarandombox/MultiverseCore/MultiverseCore.java | 2 +- .../MultiverseCore/api/MultiverseWorld.java | 12 ++++++++++++ .../MultiverseCore/utils/LocationManipulation.java | 6 +++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 74c2fad0..0a264726 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -628,6 +628,14 @@ public class MVWorld implements MultiverseWorld { return this.name; } + /** + * {@inheritDoc} + */ + @Override + public String getPermissibleName() { + return this.name.toLowerCase(); + } + /** * {@inheritDoc} */ diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index e10965ae..164dcf06 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -64,7 +64,7 @@ import java.util.logging.Logger; * The implementation of the Multiverse-{@link Core}. */ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { - private static final int PROTOCOL = 11; + private static final int PROTOCOL = 12; // Global Multiverse config variable, states whether or not // Multiverse should stop other plugins from teleporting players // to worlds. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index 1b2cca3f..fb473ce8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -145,6 +145,18 @@ public interface MultiverseWorld { */ String getName(); + /** + * Gets the lowercased name of the world. This method is required, since the permissables + * lowercase all permissions when recalculating. + *

+ * Note: This also means if a user has worlds named: world and WORLD, that they can both + * exist, and both be teleported to independently, but their permissions **cannot** be + * uniqueified at this time. See bug report #. + * + * @return The lowercased name of the world. + */ + String getPermissibleName(); + /** * Gets the alias of this world. *

diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java index 132ff259..0c605309 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java @@ -17,6 +17,7 @@ import org.bukkit.util.Vector; import java.text.DecimalFormat; import java.util.Collections; import java.util.HashMap; +import java.util.Locale; import java.util.Map; /** @@ -57,7 +58,10 @@ public class LocationManipulation { if (location == null) { return ""; } - return String.format("%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(), + // We set the locale to ENGLISH here so we always save with the format: + // world:1.2,5.4,3.6:1.8:21.3 + // Otherwise we blow up when parsing! + return String.format(Locale.ENGLISH, "%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); } From ecb97fd5c1b2d40cd67568a242d38de3fdf087b1 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 22 Jan 2012 21:44:43 -0700 Subject: [PATCH 11/13] Migrate to the new event system --- .../MultiverseCore/MultiverseCore.java | 30 +----- .../MultiverseCore/commands/HelpCommand.java | 2 - .../listeners/MVEntityListener.java | 28 ++++-- .../listeners/MVPlayerListener.java | 94 +++++++++++++++---- .../listeners/MVPluginListener.java | 16 ++-- .../listeners/MVPortalAdjustListener.java | 55 ----------- .../listeners/MVWeatherListener.java | 29 ++++-- .../listeners/MultiverseCoreListener.java | 51 ++++------ .../MultiverseCore/utils/PermissionTools.java | 4 +- 9 files changed, 148 insertions(+), 161 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalAdjustListener.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 164dcf06..ce0c5f73 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -25,7 +25,6 @@ import com.onarandombox.MultiverseCore.event.MVVersionEvent; import com.onarandombox.MultiverseCore.listeners.MVEntityListener; import com.onarandombox.MultiverseCore.listeners.MVPlayerListener; import com.onarandombox.MultiverseCore.listeners.MVPluginListener; -import com.onarandombox.MultiverseCore.listeners.MVPortalAdjustListener; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; import com.onarandombox.MultiverseCore.utils.AnchorManager; import com.onarandombox.MultiverseCore.utils.DebugLog; @@ -44,8 +43,6 @@ import org.bukkit.configuration.Configuration; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.Event.Priority; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -156,7 +153,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { // Setup the block/player/entity listener. private MVPlayerListener playerListener = new MVPlayerListener(this); - private MVPortalAdjustListener portalAdjustListener = new MVPortalAdjustListener(this); private MVEntityListener entityListener = new MVEntityListener(this); private MVPluginListener pluginListener = new MVPluginListener(this); @@ -319,28 +315,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { */ private void registerEvents() { PluginManager pm = getServer().getPluginManager(); - pm.registerEvent(Event.Type.PLAYER_TELEPORT, this.playerListener, Priority.Highest, this); // Cancel Teleports if needed. - pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Priority.Normal, this); // To create the Player Session - pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Priority.Normal, this); // To remove Player Sessions - pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight. - pm.registerEvent(Event.Type.PLAYER_LOGIN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight. - pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); // To prepend the world name - pm.registerEvent(Event.Type.PLAYER_PORTAL, this.playerListener, Priority.High, this); - // We want this high to have it go last, so it can cancel if needbe. - - pm.registerEvent(Event.Type.PLAYER_PORTAL, this.portalAdjustListener, Priority.Lowest, this); // To handle portal correction - pm.registerEvent(Event.Type.PLAYER_CHANGED_WORLD, this.playerListener, Priority.Monitor, this); // To switch gamemode - - pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow fake PVP - pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning. - pm.registerEvent(Event.Type.FOOD_LEVEL_CHANGE, this.entityListener, Priority.Normal, this); - - pm.registerEvent(Event.Type.PLUGIN_ENABLE, this.pluginListener, Priority.Monitor, this); - pm.registerEvent(Event.Type.PLUGIN_DISABLE, this.pluginListener, Priority.Monitor, this); - - pm.registerEvent(Event.Type.WEATHER_CHANGE, this.weatherListener, Priority.Normal, this); - pm.registerEvent(Event.Type.THUNDER_CHANGE, this.weatherListener, Priority.Normal, this); + pm.registerEvents(this.playerListener, this); + pm.registerEvents(this.entityListener, this); + pm.registerEvents(this.pluginListener, this); + pm.registerEvents(this.weatherListener, this); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java index 656345fd..90913026 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java @@ -5,8 +5,6 @@ * with this project. * ******************************************************************************/ -// TODO maybe remove this comment...? -// This file is no longer licensed under that silly CC license. I have blanked it out and will start implementaiton of my own in a few days. For now there is no help. package com.onarandombox.MultiverseCore.commands; import com.onarandombox.MultiverseCore.MultiverseCore; diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java index f393bbde..95ff0008 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java @@ -18,9 +18,10 @@ import org.bukkit.entity.Monster; import org.bukkit.entity.Player; import org.bukkit.entity.Slime; import org.bukkit.entity.Squid; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.FoodLevelChangeEvent; @@ -29,9 +30,9 @@ import java.util.List; import java.util.logging.Level; /** - * Multiverse's {@link EntityListener}. + * Multiverse's Entity {@link Listener}. */ -public class MVEntityListener extends EntityListener { +public class MVEntityListener implements Listener { private MultiverseCore plugin; private MVWorldManager worldManager; @@ -41,8 +42,12 @@ public class MVEntityListener extends EntityListener { this.worldManager = plugin.getMVWorldManager(); } - @Override - public void onFoodLevelChange(FoodLevelChangeEvent event) { + /** + * This method is called when an entity's food level goes higher or lower. + * @param event The Event that was fired. + */ + @EventHandler + public void foodLevelChange(FoodLevelChangeEvent event) { if (event.isCancelled()) { return; } @@ -58,9 +63,12 @@ public class MVEntityListener extends EntityListener { } } - - @Override - public void onEntityRegainHealth(EntityRegainHealthEvent event) { + /** + * This method is called when an entity's health goes up or down. + * @param event The Event that was fired. + */ + @EventHandler + public void entityRegainHealth(EntityRegainHealthEvent event) { if (event.isCancelled()) { return; } @@ -75,8 +83,8 @@ public class MVEntityListener extends EntityListener { * Handle Animal/Monster Spawn settings, seems like a more concrete method than using CraftBukkit. * @param event The event. */ - @Override - public void onCreatureSpawn(CreatureSpawnEvent event) { + @EventHandler + public void creatureSpawn(CreatureSpawnEvent event) { // Check to see if the Creature is spawned by a plugin, we don't want to prevent this behaviour. if (event.getSpawnReason() == SpawnReason.CUSTOM) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 810553b5..ad62c4d4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -12,14 +12,18 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.event.MVRespawnEvent; 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.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; @@ -28,9 +32,9 @@ import org.bukkit.event.player.PlayerTeleportEvent; import java.util.logging.Level; /** - * Multiverse's {@link PlayerListener}. + * Multiverse's {@link Listener} for players. */ -public class MVPlayerListener extends PlayerListener { +public class MVPlayerListener implements Listener { private MultiverseCore plugin; private MVWorldManager worldManager; private PermissionTools pt; @@ -41,9 +45,12 @@ public class MVPlayerListener extends PlayerListener { worldManager = plugin.getMVWorldManager(); pt = new PermissionTools(plugin); } - - @Override - public void onPlayerChat(PlayerChatEvent event) { + /** + * This method is called when a player wants to chat. + * @param event The Event that was fired. + */ + @EventHandler + public void playerChat(PlayerChatEvent event) { if (event.isCancelled()) { return; } @@ -66,8 +73,12 @@ public class MVPlayerListener extends PlayerListener { } } - @Override - public void onPlayerRespawn(PlayerRespawnEvent event) { + /** + * This method is called when a player respawns. + * @param event The Event that was fired. + */ + @EventHandler(priority = EventPriority.LOW) + public void playerRespawn(PlayerRespawnEvent event) { World world = event.getPlayer().getWorld(); MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName()); // If it's not a World MV manages we stop. @@ -108,8 +119,12 @@ public class MVPlayerListener extends PlayerListener { return w.getSpawnLocation(); } - @Override - public void onPlayerJoin(PlayerJoinEvent event) { + /** + * This method is called when a player joins the server. + * @param event The Event that was fired. + */ + @EventHandler + public void playerJoin(PlayerJoinEvent event) { Player p = event.getPlayer(); if (!p.hasPlayedBefore()) { this.plugin.log(Level.FINE, "Player joined first!"); @@ -125,19 +140,31 @@ public class MVPlayerListener extends PlayerListener { this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); } - @Override - public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { + /** + * This method is called when a player changes worlds. + * @param event The Event that was fired. + */ + @EventHandler(priority = EventPriority.MONITOR) + public void playerChangedWorld(PlayerChangedWorldEvent event) { // Permissions now determine whether or not to handle a gamemode. this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); } - @Override - public void onPlayerQuit(PlayerQuitEvent event) { + /** + * This method is called when a player quits the game. + * @param event The Event that was fired. + */ + @EventHandler + public void playerQuit(PlayerQuitEvent event) { this.plugin.removePlayerSession(event.getPlayer()); } - @Override - public void onPlayerTeleport(PlayerTeleportEvent event) { + /** + * This method is called when a player teleports anywhere. + * @param event The Event that was fired. + */ + @EventHandler(priority = EventPriority.HIGHEST) + public void playerTeleport(PlayerTeleportEvent event) { this.plugin.log(Level.FINEST, "Got teleport event for player '" + event.getPlayer().getName() + "' with cause '" + event.getCause() + "'"); if (event.isCancelled()) { @@ -183,8 +210,39 @@ public class MVPlayerListener extends PlayerListener { } } - @Override - public void onPlayerPortal(PlayerPortalEvent event) { + /** + * This method is called to adjust the portal location to the actual portal location (and not + * right outside of it. + * @param event The Event that was fired. + */ + @EventHandler(priority = EventPriority.LOWEST) + public void playerPortalCheck(PlayerPortalEvent event) { + this.plugin.log(Level.FINE, "CALLING CORE-ADJUST!!!"); + if (event.isCancelled() || event.getFrom() == null) { + return; + } + + // REMEMBER! getTo MAY be NULL HERE!!! + // If the player was actually outside of the portal, adjust the from location + if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.PORTAL) { + Location newloc = SafeTTeleporter.findPortalBlockNextTo(event.getFrom()); + // 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) { + event.setFrom(newloc); + } + } + // Wait for the adjust, then return! + if (event.getTo() == null) { + return; + } + } + /** + * This method is called when a player actually portals via a vanilla style portal. + * @param event The Event that was fired. + */ + @EventHandler(priority = EventPriority.HIGH) + public void playerPortal(PlayerPortalEvent event) { if (event.isCancelled() || (event.getFrom() == null)) { return; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPluginListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPluginListener.java index 84e34c84..567429e4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPluginListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPluginListener.java @@ -9,17 +9,19 @@ package com.onarandombox.MultiverseCore.listeners; import com.fernferret.allpay.AllPay; import com.onarandombox.MultiverseCore.MultiverseCore; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; -import org.bukkit.event.server.ServerListener; import java.util.Arrays; import java.util.logging.Level; /** - * Multiverse's {@link ServerListener}. + * Multiverse's Plugin {@link Listener}. */ -public class MVPluginListener extends ServerListener { +public class MVPluginListener implements Listener { private MultiverseCore plugin; @@ -31,8 +33,8 @@ public class MVPluginListener extends ServerListener { * Keep an eye out for Plugins which we can utilize. * @param event The event. */ - @Override - public void onPluginEnable(PluginEnableEvent event) { + @EventHandler(priority = EventPriority.MONITOR) + public void pluginEnable(PluginEnableEvent event) { // Let AllPay handle all econ plugin loadings, only go for econ plugins we support if (Arrays.asList(AllPay.validEconPlugins).contains(event.getPlugin().getDescription().getName())) { this.plugin.setBank(this.plugin.getBanker().loadEconPlugin()); @@ -48,8 +50,8 @@ public class MVPluginListener extends ServerListener { * We'll check if any of the plugins we rely on decide to Disable themselves. * @param event The event. */ - @Override - public void onPluginDisable(PluginDisableEvent event) { + @EventHandler(priority = EventPriority.MONITOR) + public void pluginDisable(PluginDisableEvent event) { // TODO: Disable econ when it disables. } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalAdjustListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalAdjustListener.java deleted file mode 100644 index 0dfc20b2..00000000 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalAdjustListener.java +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2012. * - * 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.listeners; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.utils.SafeTTeleporter; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.event.Event.Type; -import org.bukkit.event.player.PlayerListener; -import org.bukkit.event.player.PlayerPortalEvent; - -import java.util.logging.Level; - -/** - * Multiverse's second {@link PlayerListener}. - *

- * Used to double-monitor {@link Type#PLAYER_PORTAL}. - */ -public class MVPortalAdjustListener extends PlayerListener { - - private MultiverseCore plugin; - - public MVPortalAdjustListener(MultiverseCore core) { - this.plugin = core; - } - - @Override - public void onPlayerPortal(PlayerPortalEvent event) { - this.plugin.log(Level.FINE, "CALLING CORE-ADJUST!!!"); - if (event.isCancelled() || event.getFrom() == null) { - return; - } - - // REMEMBER! getTo MAY be NULL HERE!!! - // If the player was actually outside of the portal, adjust the from location - if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.PORTAL) { - Location newloc = SafeTTeleporter.findPortalBlockNextTo(event.getFrom()); - // 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) { - event.setFrom(newloc); - } - } - // Wait for the adjust, then return! - if (event.getTo() == null) { - return; - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWeatherListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWeatherListener.java index d6a0ad81..358803e1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWeatherListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWeatherListener.java @@ -9,22 +9,30 @@ package com.onarandombox.MultiverseCore.listeners; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.weather.ThunderChangeEvent; import org.bukkit.event.weather.WeatherChangeEvent; -import org.bukkit.event.weather.WeatherListener; /** - * Multiverse's {@link WeatherListener}. + * Multiverse's Weather {@link Listener}. */ -public class MVWeatherListener extends WeatherListener { +public class MVWeatherListener implements Listener { private MultiverseCore plugin; public MVWeatherListener(MultiverseCore plugin) { this.plugin = plugin; } - @Override - public void onWeatherChange(WeatherChangeEvent event) { + /** + * This method is called when the weather changes. + * @param event The Event that was fired. + */ + @EventHandler + public void weatherChange(WeatherChangeEvent event) { + if (event.isCancelled()) { + return; + } MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName()); if (world != null) { // If it's going to start raining and we have weather disabled @@ -32,8 +40,15 @@ public class MVWeatherListener extends WeatherListener { } } - @Override - public void onThunderChange(ThunderChangeEvent event) { + /** + * This method is called when a big storm is going to start. + * @param event The Event that was fired. + */ + @EventHandler + public void thunderChange(ThunderChangeEvent event) { + if (event.isCancelled()) { + return; + } MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName()); if (world != null) { // If it's going to start raining and we have weather disabled diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MultiverseCoreListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MultiverseCoreListener.java index e81e9539..fa1adf67 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MultiverseCoreListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MultiverseCoreListener.java @@ -7,9 +7,6 @@ package com.onarandombox.MultiverseCore.listeners; -import org.bukkit.event.CustomEventListener; -import org.bukkit.event.Event; - import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent; import com.onarandombox.MultiverseCore.event.MVPlayerTouchedPortalEvent; import com.onarandombox.MultiverseCore.event.MVRespawnEvent; @@ -17,80 +14,66 @@ import com.onarandombox.MultiverseCore.event.MVTeleportEvent; import com.onarandombox.MultiverseCore.event.MVVersionEvent; import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent; import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; /** * Subclasses of this listener can be used to conveniently listen to MultiverseCore-events. */ -public abstract class MultiverseCoreListener extends CustomEventListener { - /** - * {@inheritDoc} - */ - @Override - public final void onCustomEvent(Event event) { - if (event.getEventName().equals("MVConfigReload") && event instanceof MVConfigReloadEvent) { - onMVConfigReload((MVConfigReloadEvent) event); - } else if (event.getEventName().equals("MVPlayerTouchedPortalEvent") && event instanceof MVPlayerTouchedPortalEvent) { - onPlayerTouchedPortal((MVPlayerTouchedPortalEvent) event); - } else if (event.getEventName().equals("MVRespawn") && event instanceof MVRespawnEvent) { - onPlayerRespawn((MVRespawnEvent) event); - } else if (event.getEventName().equals("SafeTTeleporter") && event instanceof MVTeleportEvent) { - onPlayerTeleport((MVTeleportEvent) event); - } else if (event.getEventName().equals("MVVersionEvent") && event instanceof MVVersionEvent) { - onVersionRequest((MVVersionEvent) event); - } else if (event.getEventName().equals("MVWorldDeleteEvent") && event instanceof MVWorldDeleteEvent) { - onWorldDelete((MVWorldDeleteEvent) event); - } else if (event.getEventName().equals("MVWorldPropertyChange") && event instanceof MVWorldPropertyChangeEvent) { - onWorldPropertyChange((MVWorldPropertyChangeEvent) event); - } - } - +public abstract class MultiverseCoreListener implements Listener { /** * Called when a {@link MVWorldPropertyChangeEvent} is fired. * @param event The event. */ - public void onWorldPropertyChange(MVWorldPropertyChangeEvent event) { + @EventHandler + public void worldPropertyChange(MVWorldPropertyChangeEvent event) { } /** * Called when a {@link MVWorldDeleteEvent} is fired. * @param event The event. */ - public void onWorldDelete(MVWorldDeleteEvent event) { + @EventHandler + public void worldDelete(MVWorldDeleteEvent event) { } /** * Called when a {@link MVVersionEvent} is fired. * @param event The event. */ - public void onVersionRequest(MVVersionEvent event) { + @EventHandler + public void versionRequest(MVVersionEvent event) { } /** * Called when a {@link MVTeleportEvent} is fired. * @param event The event. */ - public void onPlayerTeleport(MVTeleportEvent event) { + @EventHandler + public void playerTeleport(MVTeleportEvent event) { } /** * Called when a {@link MVRespawnEvent} is fired. * @param event The event. */ - public void onPlayerRespawn(MVRespawnEvent event) { + @EventHandler + public void playerRespawn(MVRespawnEvent event) { } /** * Called when a {@link MVPlayerTouchedPortalEvent} is fired. * @param event The event. */ - public void onPlayerTouchedPortal(MVPlayerTouchedPortalEvent event) { + @EventHandler + public void playerTouchedPortal(MVPlayerTouchedPortalEvent event) { } /** * Called when a {@link MVConfigReloadEvent} is fired. * @param event The event. */ - public void onMVConfigReload(MVConfigReloadEvent event) { + @EventHandler + public void configReload(MVConfigReloadEvent event) { } - } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java index 5c5712c9..2be0c287 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java @@ -128,7 +128,7 @@ public class PermissionTools { // If the toWorld isn't controlled by MV, // We don't care. - if(toWorld == null) { + if (toWorld == null) { return true; } @@ -148,7 +148,7 @@ public class PermissionTools { if (!bank.hasEnough(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency(), errString)) { return false; } else if (pay) { - bank.pay(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()); + bank.give(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()); } } return true; From eebc5c6e62f60a23c609783f2afdb2fafb6873c4 Mon Sep 17 00:00:00 2001 From: "main()" Date: Mon, 23 Jan 2012 16:02:44 +0100 Subject: [PATCH 12/13] Mocking is better than implementing mock-classes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (déjà vu ... ;) ) --- .../test/utils/MockWorldFactory.java | 81 +++++++------------ 1 file changed, 27 insertions(+), 54 deletions(-) diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java index 1528e073..fd362c0d 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java @@ -7,8 +7,7 @@ package com.onarandombox.MultiverseCore.test.utils; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.io.File; import java.util.ArrayList; @@ -20,9 +19,8 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.WorldType; +import org.bukkit.block.Block; import org.bukkit.generator.ChunkGenerator; -import org.mockito.ArgumentMatcher; -import org.mockito.Matchers; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -33,51 +31,6 @@ public class MockWorldFactory { private MockWorldFactory() { } - private static class LocationMatcher extends ArgumentMatcher { - private Location l; - - public LocationMatcher(Location location) { - this.l = location; - } - - public boolean matches(Object creator) { - return creator.equals(l); - } - } - - private static class LocationMatcherAbove extends LocationMatcher { - - public LocationMatcherAbove(Location location) { - super(location); - } - - public boolean matches(Object creator) { - Util.log("Checking above..."); - if (super.l == null || creator == null) { - return false; - } - boolean equal = ((Location) creator).getBlockY() >= super.l.getBlockY(); - Util.log("Checking equals/\\..." + equal); - return equal; - } - } - - private static class LocationMatcherBelow extends LocationMatcher { - - public LocationMatcherBelow(Location location) { - super(location); - } - - public boolean matches(Object creator) { - if (super.l == null || creator == null) { - return false; - } - boolean equal = ((Location) creator).getBlockY() < super.l.getBlockY(); - Util.log("Checking equals\\/..." + equal); - return equal; - } - } - private static void registerWorld(World world) { createdWorlds.put(world.getName(), world); } @@ -95,11 +48,31 @@ public class MockWorldFactory { World thiss = (World) invocation.getMock(); return new File(TestInstanceCreator.serverDirectory, thiss.getName()); - }}); - LocationMatcherAbove matchWorldAbove = new LocationMatcherAbove(new Location(mockWorld, 0, 0, 0)); - LocationMatcherBelow matchWorldBelow = new LocationMatcherBelow(new Location(mockWorld, 0, 0, 0)); - when(mockWorld.getBlockAt(Matchers.argThat(matchWorldAbove))).thenReturn(new MockBlock(new Location(mockWorld, 0, 0, 0), Material.AIR)); - when(mockWorld.getBlockAt(Matchers.argThat(matchWorldBelow))).thenReturn(new MockBlock(new Location(mockWorld, 0, 0, 0), Material.STONE)); + } + }); + when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer() { + public Block answer(InvocationOnMock invocation) throws Throwable { + Location loc; + try { + loc = (Location) invocation.getArguments()[0]; + } catch (Exception e) { + return null; + } + + Block mockBlock = mock(Block.class); + Material blockType = Material.AIR; // TODO we might use other materials, too + + when(mockBlock.getType()).thenReturn(blockType); + when(mockBlock.getTypeId()).thenReturn(blockType.getId()); + when(mockBlock.getWorld()).thenReturn(loc.getWorld()); + when(mockBlock.getX()).thenReturn(loc.getBlockX()); + when(mockBlock.getY()).thenReturn(loc.getBlockY()); + when(mockBlock.getZ()).thenReturn(loc.getBlockZ()); + when(mockBlock.getLocation()).thenReturn(loc); + when(mockBlock.isEmpty()).thenReturn(blockType == Material.AIR); + return mockBlock; + } + }); return mockWorld; } From c7d35f13f42a4441a54981637e57cf8b9caa6fd2 Mon Sep 17 00:00:00 2001 From: "main()" Date: Mon, 23 Jan 2012 17:43:21 +0100 Subject: [PATCH 13/13] _Never_ System.out.println() exceptions! --- .../java/com/onarandombox/MultiverseCore/MVWorld.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 0a264726..a4c38521 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -571,14 +571,8 @@ public class MVWorld implements MultiverseWorld { this.saveConfig(); return true; } - } catch (NoSuchMethodException e) { - System.out.println(e); - return false; - } catch (IllegalAccessException e) { - System.out.println(e); - return false; - } catch (InvocationTargetException e) { - System.out.println(e); + } catch (Exception e) { + e.printStackTrace(); return false; } }