Almost able to load a world.

This commit is contained in:
Jeremy Wood 2012-11-08 17:24:55 -05:00
parent 9adef4b2ab
commit 16eebc462b
11 changed files with 203 additions and 35 deletions

View File

@ -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<String, MultiverseWorld> worldMap;
AbstractWorldManager(final Core core) {
this.core = core;
worldMap = new HashMap<String, MultiverseWorld>();
}
@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;
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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
* <p>
@ -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<MultiverseWorld> getMVWorlds();
//TODO Collection<MultiverseWorld> 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.
* <p>
* 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<String> getUnloadedWorlds();
//TODO List<String> 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);
}

View File

@ -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;
}

View File

@ -1,7 +1,9 @@
package com.onarandombox.multiverse.core.minecraft;
public enum WorldEnvironment {
NETHER,
NORMAL,
THE_END
;
public static WorldEnvironment getFromString(String name) {

View File

@ -1,4 +1,8 @@
package com.onarandombox.multiverse.core.minecraft;
public class WorldType {
public enum WorldType {
FLAT,
LARGE_BIOMES,
NORMAL,
VERSION_1_1
}

View File

@ -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'!");
}

View File

@ -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());
}
}

View File

@ -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<CoreConfig> implements
protected boolean useDatabase() {
return false;
}
@Override
public WorldManager getMVWorldManager() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -0,0 +1,4 @@
name: Multiverse-Core
main: com.onarandombox.MultiverseCore.MultiverseCore
authors: ['Rigby', 'fernferret', 'lithium3141', 'main--', 'dumptruckman']
version: maven-version-number