From 6e4de79bfb1f702c3cdaae816736b6fd9add4700 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 8 Oct 2011 11:57:50 -0600 Subject: [PATCH] Add WorldManager API, API is now level 2 --- .../MultiverseCore/MultiverseCore.java | 7 +- .../onarandombox/MultiverseCore/api/Core.java | 23 ++++-- .../MultiverseCore/api/MVWorldManager.java | 81 +++++++++++++++++++ .../MultiverseCore/utils/WorldManager.java | 42 ++-------- 4 files changed, 107 insertions(+), 46 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 3e69abb1..f7c69bae 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -44,10 +44,7 @@ import java.util.logging.Level; import java.util.logging.Logger; public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { - - public static boolean outdatedPluginFound = false; - private static int Protocol = 1; - + private final static int Protocol = 2; @Override public String dumpVersionInfo(String buffer) { @@ -564,7 +561,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { @Deprecated public com.onarandombox.utils.DestinationFactory getDestinationFactory() { - return new com.onarandombox.utils.DestinationFactory (this); + return new com.onarandombox.utils.DestinationFactory(this); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java index 6de23f19..384ccd85 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java @@ -8,10 +8,8 @@ package com.onarandombox.MultiverseCore.api; import com.fernferret.allpay.GenericBank; -import com.onarandombox.MultiverseCore.utils.MVMessaging; -import com.onarandombox.MultiverseCore.utils.MVPermissions; -import com.onarandombox.MultiverseCore.utils.MVPlayerSession; -import com.onarandombox.MultiverseCore.utils.SafeTTeleporter; +import com.onarandombox.MultiverseCore.destination.DestinationFactory; +import com.onarandombox.MultiverseCore.utils.*; import com.pneumaticraft.commandhandler.CommandHandler; import org.bukkit.entity.Player; import org.bukkit.util.config.Configuration; @@ -19,7 +17,7 @@ import org.bukkit.util.config.Configuration; /** * Multiverse 2 Core API *

- * This api contains a bunch of useful things you can get out of Multiverse in general! + * This API contains a bunch of useful things you can get out of Multiverse in general! */ public interface Core { /** @@ -84,4 +82,19 @@ public interface Core { * @return A non-null {@link CommandHandler}. */ public CommandHandler getCommandHandler(); + + /** + * Gets the factory class responsible for loading many different destinations + * on demand. + * + * @return A valid {@link DestinationFactory}. + */ + public DestinationFactory getDestFactory(); + + /** + * Gets the primary class responsible for managing Multiverse Worlds. + * + * @return {@link WorldManager}. + */ + public WorldManager getMVWorldManager(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java new file mode 100644 index 00000000..f1f2e77b --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java @@ -0,0 +1,81 @@ +/****************************************************************************** + * Multiverse 2 Copyright (c) the Multiverse Team 2011. * + * Multiverse 2 is licensed under the BSD License. * + * For more information please check the README.md file included * + * with this project. * + ******************************************************************************/ + +package com.onarandombox.MultiverseCore.api; + +import com.onarandombox.MultiverseCore.MVWorld; +import org.bukkit.World.Environment; +import org.bukkit.generator.ChunkGenerator; + +import java.util.Collection; + +/** + * Multiverse 2 World Manager API + *

+ * This API contains all of the world managing functions that your heart desires! + */ +public interface MVWorldManager { + /** + * Add a new World to the Multiverse Setup. + * + * @param name World Name + * @param env Environment Type + * @param seedString The seed in the form of a string. If the seed is a Long, + * it will be interpreted as such. + * @param generator The Custom generator plugin to use. + * + * @return True if the world is added, false if not. + */ + public boolean addWorld(String name, Environment env, String seedString, String generator); + + /** + * Remove the world from the Multiverse list, from the config and deletes the folder + * + * @param name The name of the world to remove + * + * @return True if success, false if failure. + */ + public Boolean deleteWorld(String name); + + /** + * Unload a world from Multiverse + * + * @param name Name of the world to unload + * @param safely Perform this safely. Set to True to save world files before unloading. + * + * @return True if the world was unloaded, false if not. + */ + public boolean unloadWorld(String name, boolean safely); + + /** + * Test if a given chunk generator is valid. + * + * @param generator The generator name. + * @param generatorID The generator id. + * @param worldName The worldName to use as the default. + * + * @return A {@link ChunkGenerator} or null + */ + public ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName); + + /** + * Returns a list of all the worlds Multiverse knows about. + * + * @return A list of {@link MVWorld}. + */ + public Collection getMVWorlds(); + + + /** + * Returns a {@link MVWorld} if it exists, and null if it does not. This will search name AND alias. + * + * @param name The name or alias of the world to get. + * + * @return A {@link MVWorld} or null. + */ + public MVWorld getMVWorld(String name); +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index f31150d1..0ac6af83 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.List; import java.util.logging.Level; +import com.onarandombox.MultiverseCore.api.MVWorldManager; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.entity.Player; @@ -29,7 +30,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; * * @author fernferret, Rigby90 */ -public class WorldManager { +public class WorldManager implements MVWorldManager { private MultiverseCore plugin; private PurgeWorlds worldPurger; private HashMap worlds; @@ -42,18 +43,7 @@ public class WorldManager { this.worldPurger = new PurgeWorlds(this.plugin); } - /** - * Add a new World to the Multiverse Setup. - *

- * Isn't there a prettier way to do this??!!?!?! - * - * @param name World Name - * @param env Environment Type - * @param seedString The seed in the form of a string. If the seed is a Long, it will be interpreted as such. - * @param generator The Custom generator plugin to use. - * - * @return True if the world is added, false if not. - */ + public boolean addWorld(String name, Environment env, String seedString, String generator) { plugin.log(Level.FINE, "Adding world with: " + name + ", " + env.toString() + ", " + seedString + ", " + generator); Long seed = null; @@ -126,15 +116,8 @@ public class WorldManager { return plugin != null && plugin.isEnabled(); } - /** - * Test if a given chunk generator is valid. - * - * @param generator The generator name. - * @param generatorID The generator id. - * @param worldName The worldName to use as the default. - * @return A {@link ChunkGenerator} or null - */ - private ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName) { + + public ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName) { if (generator == null) { return null; } @@ -189,12 +172,6 @@ public class WorldManager { return false; } - /** - * Remove the world from the Multiverse list, from the config and deletes the folder - * - * @param name The name of the world to remove - * @return True if success, false if failure. - */ public Boolean deleteWorld(String name) { if (this.plugin.getServer().getWorld(name) != null) { @@ -245,14 +222,7 @@ public class WorldManager { } } - /** - * Unload a world from Multiverse - * - * @param name Name of the world to unload - * @param safely Perform this safely. Set to True to save world files before unloading. - * @return True if the world was unloaded, false if not. - */ - private boolean unloadWorld(String name, boolean safely) { + public boolean unloadWorld(String name, boolean safely) { this.removePlayersFromWorld(name); return this.plugin.getServer().unloadWorld(name, safely); }