Add WorldManager API, API is now level 2

This commit is contained in:
Eric Stokes 2011-10-08 11:57:50 -06:00
parent 2d112edee5
commit 6e4de79bfb
4 changed files with 107 additions and 46 deletions

View File

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

View File

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

View File

@ -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
* <p/>
* 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<MVWorld> 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);
}

View File

@ -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<String, MVWorld> worlds;
@ -42,18 +43,7 @@ public class WorldManager {
this.worldPurger = new PurgeWorlds(this.plugin);
}
/**
* Add a new World to the Multiverse Setup.
* <p/>
* 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);
}