From 16eebc462bc570d08fe7c6cd2f2a83326d66a69e Mon Sep 17 00:00:00 2001 From: Jeremy Wood Date: Thu, 8 Nov 2012 17:24:55 -0500 Subject: [PATCH] Almost able to load a world. --- .../multiverse/core/AbstractWorldManager.java | 60 +++++++++++++++++++ .../multiverse/core/MultiverseException.java | 23 +++++++ .../core/WorldCreationException.java | 14 +++++ .../multiverse/core/api/WorldManager.java | 52 ++++++++-------- .../core/command/ImportCommand.java | 10 ++-- .../core/minecraft/WorldEnvironment.java | 4 +- .../multiverse/core/minecraft/WorldType.java | 6 +- .../multiverse/core/util/Language.java | 9 +++ .../multiverse/core/BukkitWorldManager.java | 50 ++++++++++++++++ .../multiverse/core/MultiverseCore.java | 6 ++ bukkit/src/main/resources/plugin.yml | 4 ++ 11 files changed, 203 insertions(+), 35 deletions(-) create mode 100644 base/src/main/java/com/onarandombox/multiverse/core/MultiverseException.java create mode 100644 base/src/main/java/com/onarandombox/multiverse/core/WorldCreationException.java create mode 100644 base/src/main/java/com/onarandombox/multiverse/core/util/Language.java create mode 100644 bukkit/src/main/java/com/onarandombox/multiverse/core/BukkitWorldManager.java create mode 100644 bukkit/src/main/resources/plugin.yml diff --git a/base/src/main/java/com/onarandombox/multiverse/core/AbstractWorldManager.java b/base/src/main/java/com/onarandombox/multiverse/core/AbstractWorldManager.java index b452199f..d451cc5a 100644 --- a/base/src/main/java/com/onarandombox/multiverse/core/AbstractWorldManager.java +++ b/base/src/main/java/com/onarandombox/multiverse/core/AbstractWorldManager.java @@ -1,7 +1,67 @@ package com.onarandombox.multiverse.core; +import com.dumptruckman.minecraft.pluginbase.locale.BundledMessage; +import com.onarandombox.multiverse.core.api.Core; +import com.onarandombox.multiverse.core.api.MultiverseWorld; import com.onarandombox.multiverse.core.api.WorldManager; +import com.onarandombox.multiverse.core.minecraft.WorldEnvironment; +import com.onarandombox.multiverse.core.minecraft.WorldType; +import com.onarandombox.multiverse.core.util.Language; + +import java.util.HashMap; +import java.util.Map; abstract class AbstractWorldManager implements WorldManager { + protected final Core core; + + private final Map worldMap; + + AbstractWorldManager(final Core core) { + this.core = core; + worldMap = new HashMap(); + } + + @Override + public boolean addWorld(String name, WorldEnvironment env, String seedString, WorldType type, Boolean generateStructures, String generator) throws WorldCreationException { + return this.addWorld(name, env, seedString, type, generateStructures, generator, true); + } + + @Override + public boolean addWorld(String name, + WorldEnvironment env, + String seedString, + WorldType type, + Boolean generateStructures, + String generator, + boolean useSpawnAdjust) throws WorldCreationException { + if (this.worldMap.containsKey(name)) { + throw new WorldCreationException(new BundledMessage(Language.WORLD_ALREADY_EXISTS, name)); + } + Long seed = null; + if (seedString != null && seedString.length() > 0) { + try { + seed = Long.parseLong(seedString); + } catch (NumberFormatException numberformatexception) { + seed = (long) seedString.hashCode(); + } + } + + // TODO: Use the fancy kind with the commandSender | dumptruckman has no idea what this means.. + if (generator != null && generator.length() == 0) { + generator = null; + } + + createWorld(name, env, seed, type, generateStructures, generator, true); + + return true; + } + + protected abstract MultiverseWorld createWorld(String name, + WorldEnvironment env, + Long seed, + WorldType type, + Boolean generateStructures, + String generator, + boolean useSpawnAdjust) throws WorldCreationException; } diff --git a/base/src/main/java/com/onarandombox/multiverse/core/MultiverseException.java b/base/src/main/java/com/onarandombox/multiverse/core/MultiverseException.java new file mode 100644 index 00000000..b72baa40 --- /dev/null +++ b/base/src/main/java/com/onarandombox/multiverse/core/MultiverseException.java @@ -0,0 +1,23 @@ +package com.onarandombox.multiverse.core; + +import com.dumptruckman.minecraft.pluginbase.locale.BundledMessage; + +public class MultiverseException extends Exception { + + private final BundledMessage languageMessage; + + + public MultiverseException(BundledMessage languageMessage) { + super(languageMessage.getMessage().getDefault().get(0)); + this.languageMessage = languageMessage; + } + + public MultiverseException(BundledMessage languageMessage, Throwable throwable) { + super(languageMessage.getMessage().getDefault().get(0), throwable); + this.languageMessage = languageMessage; + } + + public BundledMessage getBundledMessage() { + return this.languageMessage; + } +} diff --git a/base/src/main/java/com/onarandombox/multiverse/core/WorldCreationException.java b/base/src/main/java/com/onarandombox/multiverse/core/WorldCreationException.java new file mode 100644 index 00000000..ccc34fd0 --- /dev/null +++ b/base/src/main/java/com/onarandombox/multiverse/core/WorldCreationException.java @@ -0,0 +1,14 @@ +package com.onarandombox.multiverse.core; + +import com.dumptruckman.minecraft.pluginbase.locale.BundledMessage; + +public class WorldCreationException extends MultiverseException { + + public WorldCreationException(BundledMessage languageMessage) { + super(languageMessage); + } + + public WorldCreationException(BundledMessage languageMessage, Throwable throwable) { + super(languageMessage, throwable); + } +} diff --git a/base/src/main/java/com/onarandombox/multiverse/core/api/WorldManager.java b/base/src/main/java/com/onarandombox/multiverse/core/api/WorldManager.java index 784836ef..3e4c3436 100644 --- a/base/src/main/java/com/onarandombox/multiverse/core/api/WorldManager.java +++ b/base/src/main/java/com/onarandombox/multiverse/core/api/WorldManager.java @@ -1,12 +1,10 @@ package com.onarandombox.multiverse.core.api; +import com.onarandombox.multiverse.core.WorldCreationException; import com.onarandombox.multiverse.core.minecraft.Generator; import com.onarandombox.multiverse.core.minecraft.WorldEnvironment; import com.onarandombox.multiverse.core.minecraft.WorldType; -import java.util.Collection; -import java.util.List; - /** * Multiverse 2 World Manager API *

@@ -33,7 +31,7 @@ public interface WorldManager { String seedString, WorldType type, Boolean generateStructures, - String generator); + String generator) throws WorldCreationException; /** * Add a new World to the Multiverse Setup. @@ -55,7 +53,7 @@ public interface WorldManager { WorldType type, Boolean generateStructures, String generator, - boolean useSpawnAdjust); + boolean useSpawnAdjust) throws WorldCreationException; /** * Make a copy of a world. @@ -65,7 +63,7 @@ public interface WorldManager { * @param generator The Custom generator plugin to use. * @return True if the world is copied successfully, false if not. */ - boolean cloneWorld(String oldName, String newName, String generator); + //TODO boolean cloneWorld(String oldName, String newName, String generator); /** * Remove the world from the Multiverse list, from the @@ -74,7 +72,7 @@ public interface WorldManager { * @param name The name of the world to remove * @return True if success, false if failure. */ - boolean deleteWorld(String name); + //TODO boolean deleteWorld(String name); /** * Remove the world from the Multiverse list, from the @@ -85,7 +83,7 @@ public interface WorldManager { * config. If false, they'll stay and the world may come back. * @return True if success, false if failure. */ - boolean deleteWorld(String name, boolean removeConfig); + //TODO boolean deleteWorld(String name, boolean removeConfig); /** * @@ -96,7 +94,7 @@ public interface WorldManager { * only the contents of the world folder will be deleted * @return True if success, false if failure. */ - boolean deleteWorld(String name, boolean removeFromConfig, boolean deleteWorldFolder); + //TODO boolean deleteWorld(String name, boolean removeFromConfig, boolean deleteWorldFolder); /** * Unload a world from Multiverse. @@ -104,7 +102,7 @@ public interface WorldManager { * @param name Name of the world to unload * @return True if the world was unloaded, false if not. */ - boolean unloadWorld(String name); + //TODO boolean unloadWorld(String name); /** * Loads the world. Only use this if the world has been @@ -113,14 +111,14 @@ public interface WorldManager { * @param name The name of the world to load * @return True if success, false if failure. */ - boolean loadWorld(String name); + //TODO boolean loadWorld(String name); /** * Removes all players from the specified world. * * @param name World to remove players from. */ - void removePlayersFromWorld(String name); + //TODO void removePlayersFromWorld(String name); /** * Test if a given chunk generator is valid. @@ -130,14 +128,14 @@ public interface WorldManager { * @param worldName The worldName to use as the default. * @return A {@link Generator} or null */ - Generator getChunkGenerator(String generator, String generatorID, String worldName); + //TODO Generator getChunkGenerator(String generator, String generatorID, String worldName); /** * Returns a list of all the worlds Multiverse knows about. * * @return A list of {@link MultiverseWorld}. */ - Collection getMVWorlds(); + //TODO Collection getMVWorlds(); /** @@ -147,7 +145,7 @@ public interface WorldManager { * @param name The name or alias of the world to get. * @return A {@link MultiverseWorld} or null. */ - MultiverseWorld getMVWorld(String name); + //TODO MultiverseWorld getMVWorld(String name); /** * Checks to see if the given name is a valid {@link MultiverseWorld}. @@ -155,7 +153,7 @@ public interface WorldManager { * @param name The name or alias of the world to check. * @return True if the world exists, false if not. */ - boolean isMVWorld(String name); + //TODO boolean isMVWorld(String name); /** * Load the Worlds & Settings from the configuration file. @@ -163,16 +161,16 @@ public interface WorldManager { * @param forceLoad If set to true, this will perform a total * reset and not just load new worlds. */ - void loadWorlds(boolean forceLoad); + //TODO void loadWorlds(boolean forceLoad); /** * Loads the Worlds & Settings for any worlds that bukkit loaded before us. *

* This way people will _always_ have some worlds in the list. */ - void loadDefaultWorlds(); + //TODO void loadDefaultWorlds(); - WorldPurger getWorldPurger(); + //TODO WorldPurger getWorldPurger(); /** * Gets the world players will spawn in on first join. @@ -180,26 +178,26 @@ public interface WorldManager { * * @return A Multiverse world that players will spawn in or null if no MV world has been set. */ - MultiverseWorld getSpawnWorld(); + //TODO MultiverseWorld getSpawnWorld(); /** * Gets the list of worlds in the config, but unloaded. * * @return A List of worlds as strings. */ - List getUnloadedWorlds(); + //TODO List getUnloadedWorlds(); /** * This method populates an internal list and needs to be called after multiverse initialization. */ - void getDefaultWorldGenerators(); + //TODO void getDefaultWorldGenerators(); /** * Saves the world config to disk. * * @return True if success, false if fail. */ - boolean saveWorldsConfig(); + //TODO boolean saveWorldsConfig(); /** * Remove the world from the Multiverse list and from the config. @@ -207,21 +205,21 @@ public interface WorldManager { * @param name The name of the world to remove * @return True if success, false if failure. */ - boolean removeWorldFromConfig(String name); + //TODO boolean removeWorldFromConfig(String name); /** * Sets the initial spawn world for new players. * * @param world The World new players should spawn in. */ - void setFirstSpawnWorld(String world); + //TODO void setFirstSpawnWorld(String world); /** * Gets the world players should spawn in first. * * @return The {@link MultiverseWorld} new players should spawn in. */ - MultiverseWorld getFirstSpawnWorld(); + //TODO MultiverseWorld getFirstSpawnWorld(); /** * Regenerates a world. @@ -233,5 +231,5 @@ public interface WorldManager { * * @return True if success, false if fail. */ - boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed); + //TODO boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed); } diff --git a/base/src/main/java/com/onarandombox/multiverse/core/command/ImportCommand.java b/base/src/main/java/com/onarandombox/multiverse/core/command/ImportCommand.java index 2ba10aad..9b896058 100644 --- a/base/src/main/java/com/onarandombox/multiverse/core/command/ImportCommand.java +++ b/base/src/main/java/com/onarandombox/multiverse/core/command/ImportCommand.java @@ -9,6 +9,7 @@ import com.onarandombox.multiverse.core.api.Core; import com.onarandombox.multiverse.core.api.MVPerms; import com.onarandombox.multiverse.core.api.MultiverseWorld; import com.onarandombox.multiverse.core.minecraft.WorldEnvironment; +import com.onarandombox.multiverse.core.util.Language; import com.sk89q.minecraft.util.commands.CommandContext; import java.io.File; @@ -29,7 +30,7 @@ import java.util.List; ) public class ImportCommand extends MultiverseCommand { - public static final Message IMPORT = new Message("command.import.help", + public static final Message IMPORT_HELP = new Message("command.import.help", "Imports a world into the server from a folder with the given name.", "The folder must exist in the location where worlds are normally located and must contain Minecraft world data.", "You must specify a world environment such as NORMAL or NETHER.", @@ -49,9 +50,6 @@ public class ImportCommand extends MultiverseCommand { public static final Message NO_POTENTIAL_WORLDS = new Message("command.import.no_potential_worlds", "&cNo potential worlds found. Sorry!"); - public static final Message ALREADY_MV_WORLD = new Message("command.import.already_mv_world", - "&aMultiverse&f already knows about '&b%s&f'!"); - public static final Message INVALID_ENVIRONMENT = new Message("command.import.invalid_environment", "&cThat is not a valid environment."); @@ -71,7 +69,7 @@ public class ImportCommand extends MultiverseCommand { @Override public Message getHelp() { - return IMPORT; + return IMPORT_HELP; } @Override @@ -95,7 +93,7 @@ public class ImportCommand extends MultiverseCommand { // Make sure we don't already know about this world. if (core.getMVWorldManager().isMVWorld(worldName)) { - core.getMessager().message(sender, ALREADY_MV_WORLD, worldName); + core.getMessager().message(sender, Language.WORLD_ALREADY_EXISTS, worldName); return true; } diff --git a/base/src/main/java/com/onarandombox/multiverse/core/minecraft/WorldEnvironment.java b/base/src/main/java/com/onarandombox/multiverse/core/minecraft/WorldEnvironment.java index 94291456..20d4fed1 100644 --- a/base/src/main/java/com/onarandombox/multiverse/core/minecraft/WorldEnvironment.java +++ b/base/src/main/java/com/onarandombox/multiverse/core/minecraft/WorldEnvironment.java @@ -1,7 +1,9 @@ package com.onarandombox.multiverse.core.minecraft; public enum WorldEnvironment { - + NETHER, + NORMAL, + THE_END ; public static WorldEnvironment getFromString(String name) { diff --git a/base/src/main/java/com/onarandombox/multiverse/core/minecraft/WorldType.java b/base/src/main/java/com/onarandombox/multiverse/core/minecraft/WorldType.java index 170d08f6..39cc5e80 100644 --- a/base/src/main/java/com/onarandombox/multiverse/core/minecraft/WorldType.java +++ b/base/src/main/java/com/onarandombox/multiverse/core/minecraft/WorldType.java @@ -1,4 +1,8 @@ package com.onarandombox.multiverse.core.minecraft; -public class WorldType { +public enum WorldType { + FLAT, + LARGE_BIOMES, + NORMAL, + VERSION_1_1 } diff --git a/base/src/main/java/com/onarandombox/multiverse/core/util/Language.java b/base/src/main/java/com/onarandombox/multiverse/core/util/Language.java new file mode 100644 index 00000000..c7a710ee --- /dev/null +++ b/base/src/main/java/com/onarandombox/multiverse/core/util/Language.java @@ -0,0 +1,9 @@ +package com.onarandombox.multiverse.core.util; + +import com.dumptruckman.minecraft.pluginbase.locale.Message; + +public class Language { + + public static final Message WORLD_ALREADY_EXISTS = new Message("worlds.world_exists", + "&aMultiverse&f already knows about '&b%s&f'!"); +} diff --git a/bukkit/src/main/java/com/onarandombox/multiverse/core/BukkitWorldManager.java b/bukkit/src/main/java/com/onarandombox/multiverse/core/BukkitWorldManager.java new file mode 100644 index 00000000..aa24e9fa --- /dev/null +++ b/bukkit/src/main/java/com/onarandombox/multiverse/core/BukkitWorldManager.java @@ -0,0 +1,50 @@ +package com.onarandombox.multiverse.core; + +import com.dumptruckman.minecraft.pluginbase.util.Logging; +import com.onarandombox.multiverse.core.api.Core; +import com.onarandombox.multiverse.core.api.MultiverseWorld; +import com.onarandombox.multiverse.core.minecraft.WorldEnvironment; +import com.onarandombox.multiverse.core.minecraft.WorldType; +import org.bukkit.Bukkit; +import org.bukkit.World.Environment; +import org.bukkit.WorldCreator; + +class BukkitWorldManager extends AbstractWorldManager { + + BukkitWorldManager(final Core core) { + super(core); + } + + @Override + public MultiverseWorld createWorld(String name, WorldEnvironment env, Long seed, WorldType type, Boolean generateStructures, String generator, boolean useSpawnAdjust) throws WorldCreationException { + if (Bukkit.getWorld(name) != null) { + + } + WorldCreator c = new WorldCreator(name); + if (seed != null) { + c.seed(seed); + } + if (generator != null) { + c.generator(generator); + } + c.environment(Environment.valueOf(env.toString())); + if (type != null) { + c.type(org.bukkit.WorldType.valueOf(type.toString())); + } + if (generateStructures != null) { + c.generateStructures(generateStructures); + } + + 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) { + builder.append(" & seed: ").append(seed); + } + if (generator != null) { + builder.append(" & generator: ").append(generator); + } + Logging.info(builder.toString()); + } +} diff --git a/bukkit/src/main/java/com/onarandombox/multiverse/core/MultiverseCore.java b/bukkit/src/main/java/com/onarandombox/multiverse/core/MultiverseCore.java index 193cba67..f292364d 100644 --- a/bukkit/src/main/java/com/onarandombox/multiverse/core/MultiverseCore.java +++ b/bukkit/src/main/java/com/onarandombox/multiverse/core/MultiverseCore.java @@ -3,6 +3,7 @@ package com.onarandombox.multiverse.core; import com.dumptruckman.minecraft.pluginbase.plugin.AbstractBukkitPlugin; import com.onarandombox.multiverse.core.api.Core; import com.onarandombox.multiverse.core.api.CoreConfig; +import com.onarandombox.multiverse.core.api.WorldManager; import java.io.IOException; @@ -29,4 +30,9 @@ public class MultiverseCore extends AbstractBukkitPlugin implements protected boolean useDatabase() { return false; } + + @Override + public WorldManager getMVWorldManager() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } } diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml new file mode 100644 index 00000000..9eb1d333 --- /dev/null +++ b/bukkit/src/main/resources/plugin.yml @@ -0,0 +1,4 @@ +name: Multiverse-Core +main: com.onarandombox.MultiverseCore.MultiverseCore +authors: ['Rigby', 'fernferret', 'lithium3141', 'main--', 'dumptruckman'] +version: maven-version-number \ No newline at end of file