mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-23 07:51:46 +01:00
1.5 Compatibility
This commit is contained in:
parent
dad4547c21
commit
2ff10d0882
@ -32,65 +32,64 @@ import com.onarandombox.utils.PurgeWorlds;
|
||||
import com.onarandombox.utils.UpdateChecker;
|
||||
|
||||
public class MultiverseCore extends JavaPlugin {
|
||||
|
||||
|
||||
// Useless stuff to keep us going.
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
private static DebugLog debugLog;
|
||||
|
||||
|
||||
// Debug Mode
|
||||
private boolean debug;
|
||||
|
||||
|
||||
// Setup our Map for our Commands using the CommandHandler.
|
||||
private CommandManager commandManager;
|
||||
|
||||
|
||||
private final String tag = "[Multiverse-Core]";
|
||||
|
||||
|
||||
// Multiverse Permissions Handler
|
||||
public MVPermissions ph = new MVPermissions(this);
|
||||
|
||||
|
||||
// Permissions Handler
|
||||
public static PermissionHandler Permissions = null;
|
||||
|
||||
|
||||
// iConomy Handler
|
||||
public static iConomy iConomy = null;
|
||||
public static boolean useiConomy = false;
|
||||
|
||||
|
||||
// Configurations
|
||||
public Configuration configMV = null;
|
||||
public Configuration configWorlds = null;
|
||||
|
||||
|
||||
// Setup the block/player/entity listener.
|
||||
private MVPlayerListener playerListener = new MVPlayerListener(this);;
|
||||
|
||||
|
||||
private MVBlockListener blockListener = new MVBlockListener(this);
|
||||
private MVEntityListener entityListener = new MVEntityListener(this);
|
||||
private MVPluginListener pluginListener = new MVPluginListener(this);
|
||||
|
||||
|
||||
public UpdateChecker updateCheck;
|
||||
|
||||
|
||||
// HashMap to contain all the Worlds which this Plugin will manage.
|
||||
private HashMap<String, MVWorld> worlds = new HashMap<String, MVWorld>();
|
||||
|
||||
|
||||
// HashMap to contain information relating to the Players.
|
||||
public HashMap<String, MVPlayerSession> playerSessions = new HashMap<String, MVPlayerSession>();
|
||||
private PurgeWorlds worldPurger;
|
||||
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
// Create our DataFolder
|
||||
getDataFolder().mkdirs();
|
||||
// Setup our Debug Log
|
||||
debugLog = new DebugLog("Multiverse-Core", getDataFolder() + File.separator + "debug.log");
|
||||
|
||||
|
||||
// Setup & Load our Configuration files.
|
||||
loadConfigs();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void onEnable() {
|
||||
// Output a little snippet to show it's enabled.
|
||||
this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " Enabled - By " + getAuthors());
|
||||
|
||||
|
||||
// Setup all the Events the plugin needs to Monitor.
|
||||
this.registerEvents();
|
||||
// Setup Permissions, we'll do an initial check for the Permissions plugin then fall back on isOP().
|
||||
@ -103,16 +102,16 @@ public class MultiverseCore extends JavaPlugin {
|
||||
this.setupEconomy();
|
||||
// Call the Function to assign all the Commands to their Class.
|
||||
this.registerCommands();
|
||||
|
||||
|
||||
// Start the Update Checker
|
||||
// updateCheck = new UpdateChecker(this.getDescription().getName(), this.getDescription().getVersion());
|
||||
|
||||
|
||||
// Call the Function to load all the Worlds and setup the HashMap
|
||||
// When called with null, it tries to load ALL
|
||||
// this function will be called every time a plugin registers a new envtype with MV
|
||||
this.loadWorlds(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function to Register all the Events needed.
|
||||
*/
|
||||
@ -125,25 +124,25 @@ public class MultiverseCore extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Priority.Highest, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this);
|
||||
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow PVP as well as EnableHealth.
|
||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning.
|
||||
|
||||
|
||||
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.BLOCK_BREAK, blockListener, Priority.Normal, this); // To prevent Blocks being destroyed.
|
||||
// pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); // To prevent Blocks being placed.
|
||||
// pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
|
||||
// pm.registerEvent(Event.Type.EXPLOSION_PRIMED, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check for Permissions plugin and then setup our own Permissions Handler.
|
||||
*/
|
||||
private void setupPermissions() {
|
||||
Plugin p = this.getServer().getPluginManager().getPlugin("Permissions");
|
||||
|
||||
|
||||
if (MultiverseCore.Permissions == null) {
|
||||
if (p != null && p.isEnabled()) {
|
||||
MultiverseCore.Permissions = ((Permissions) p).getHandler();
|
||||
@ -151,20 +150,20 @@ public class MultiverseCore extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check for the iConomy plugin and set it up accordingly.
|
||||
*/
|
||||
private void setupEconomy() {
|
||||
Plugin test = this.getServer().getPluginManager().getPlugin("iConomy");
|
||||
|
||||
|
||||
if (MultiverseCore.iConomy == null) {
|
||||
if (test != null) {
|
||||
MultiverseCore.iConomy = (iConomy) test;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the Configuration files OR create the default config files.
|
||||
*/
|
||||
@ -172,11 +171,11 @@ public class MultiverseCore extends JavaPlugin {
|
||||
// Call the defaultConfiguration class to create the config files if they don't already exist.
|
||||
new DefaultConfiguration(getDataFolder(), "config.yml");
|
||||
new DefaultConfiguration(getDataFolder(), "worlds.yml");
|
||||
|
||||
|
||||
// Now grab the Configuration Files.
|
||||
this.configMV = new Configuration(new File(getDataFolder(), "config.yml"));
|
||||
this.configWorlds = new Configuration(new File(getDataFolder(), "worlds.yml"));
|
||||
|
||||
|
||||
// Now attempt to Load the configurations.
|
||||
try {
|
||||
this.configMV.load();
|
||||
@ -184,18 +183,18 @@ public class MultiverseCore extends JavaPlugin {
|
||||
} catch (Exception e) {
|
||||
log(Level.INFO, "- Failed to load config.yml");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
this.configWorlds.load();
|
||||
log(Level.INFO, "- World Config -- Loaded");
|
||||
} catch (Exception e) {
|
||||
log(Level.INFO, "- Failed to load worlds.yml");
|
||||
}
|
||||
|
||||
|
||||
// Setup the Debug option, we'll default to false because this option will not be in the default config.
|
||||
this.debug = this.configMV.getBoolean("debug", false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register Multiverse-Core commands to DThielke's Command Manager.
|
||||
*/
|
||||
@ -220,7 +219,7 @@ public class MultiverseCore extends JavaPlugin {
|
||||
this.commandManager.addCommand(new EnvironmentCommand(this));
|
||||
this.commandManager.addCommand(new PurgeCommand(this));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the Worlds & Settings from the configuration file.
|
||||
*/
|
||||
@ -229,12 +228,12 @@ public class MultiverseCore extends JavaPlugin {
|
||||
int count = 0;
|
||||
// Grab all the Worlds from the Config.
|
||||
List<String> worldKeys = this.configWorlds.getKeys("worlds");
|
||||
|
||||
|
||||
// Force the worlds to be loaded, ie don't just load new worlds.
|
||||
if (forceLoad) {
|
||||
this.worlds.clear();
|
||||
}
|
||||
|
||||
|
||||
// Check that the list is not null.
|
||||
if (worldKeys != null) {
|
||||
for (String worldKey : worldKeys) {
|
||||
@ -245,27 +244,27 @@ public class MultiverseCore extends JavaPlugin {
|
||||
// Grab the initial values from the config file.
|
||||
String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
|
||||
String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", "");
|
||||
|
||||
|
||||
String generatorstring = this.configWorlds.getString("worlds." + worldKey + ".generator");
|
||||
|
||||
|
||||
addWorld(worldKey, getEnvFromString(environment), seedString, generatorstring);
|
||||
|
||||
|
||||
// Increment the world count
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Ensure that the worlds created by the default server were loaded into MV, useful for first time runs
|
||||
// count += loadDefaultWorlds();
|
||||
// TODO: This was taken out because some people don't want nether! Instead show a message to people who have MVImport
|
||||
// and tell them to do MVImports for their worlds!
|
||||
|
||||
|
||||
// Simple Output to the Console to show how many Worlds were loaded.
|
||||
log(Level.INFO, count + " - World(s) loaded.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private int loadDefaultWorlds() {
|
||||
@ -276,22 +275,22 @@ public class MultiverseCore extends JavaPlugin {
|
||||
addWorld(world.getName(), Environment.NORMAL, null, null);
|
||||
additonalWorldsLoaded++;
|
||||
}
|
||||
|
||||
|
||||
// This next one could be null if they have it disabled in server.props
|
||||
World world_nether = this.getServer().getWorld(world.getName() + "_nether");
|
||||
if (world_nether != null && !this.worlds.containsKey(world_nether.getName())) {
|
||||
addWorld(world_nether.getName(), Environment.NETHER, null, null);
|
||||
additonalWorldsLoaded++;
|
||||
}
|
||||
|
||||
|
||||
return additonalWorldsLoaded;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new World to the Multiverse Setup.
|
||||
*
|
||||
*
|
||||
* Isn't there a prettier way to do this??!!?!?!
|
||||
*
|
||||
*
|
||||
* @param name World Name
|
||||
* @param environment Environment Type
|
||||
*/
|
||||
@ -305,7 +304,7 @@ public class MultiverseCore extends JavaPlugin {
|
||||
seed = (long) seedString.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String generatorID = null;
|
||||
String generatorName = null;
|
||||
if (generator != null) {
|
||||
@ -314,20 +313,20 @@ public class MultiverseCore extends JavaPlugin {
|
||||
generatorName = split[0];
|
||||
generatorID = id;
|
||||
}
|
||||
|
||||
|
||||
ChunkGenerator customGenerator = getChunkGenerator(generatorName, generatorID, name);
|
||||
|
||||
if (customGenerator == null && generator != null && !generator.isEmpty()) {
|
||||
|
||||
if (customGenerator == null && generator != null && (generator.length() > 0)) {
|
||||
if (!pluginExists(generatorName)) {
|
||||
log(Level.WARNING, "Could not find plugin: " + generatorName);
|
||||
} else {
|
||||
log(Level.WARNING, "Found plugin: " + generatorName + ", but did not find generatorID: " + generatorID);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
World world = null;
|
||||
if (seed != null) {
|
||||
if (customGenerator != null) {
|
||||
@ -350,31 +349,31 @@ public class MultiverseCore extends JavaPlugin {
|
||||
this.worldPurger.purgeWorld(null, mvworld);
|
||||
this.worlds.put(name, mvworld);
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean pluginExists(String generator) {
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin(generator);
|
||||
return plugin != null;
|
||||
}
|
||||
|
||||
|
||||
private ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName) {
|
||||
if (generator == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin(generator);
|
||||
if (plugin == null) {
|
||||
return null;
|
||||
} else {
|
||||
return plugin.getDefaultWorldGenerator(worldName, generatorID);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the world from the Multiverse list
|
||||
*
|
||||
*
|
||||
* @param name The name of the world to remove
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
@ -385,10 +384,10 @@ public class MultiverseCore extends JavaPlugin {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the world from the Multiverse list and from the config
|
||||
*
|
||||
*
|
||||
* @param name The name of the world to remove
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
@ -398,10 +397,10 @@ public class MultiverseCore extends JavaPlugin {
|
||||
this.configWorlds.save();
|
||||
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.
|
||||
*/
|
||||
@ -413,10 +412,10 @@ public class MultiverseCore extends JavaPlugin {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a folder Courtesy of: lithium3141
|
||||
*
|
||||
*
|
||||
* @param file The folder to delete
|
||||
* @return true if success
|
||||
*/
|
||||
@ -436,20 +435,19 @@ public class MultiverseCore extends JavaPlugin {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* What happens when the plugin gets disabled...
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
debugLog.close();
|
||||
MultiverseCore.Permissions = null;
|
||||
log(Level.INFO, "- Disabled");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab the players session if one exists, otherwise create a session then return it.
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
@ -461,36 +459,36 @@ public class MultiverseCore extends JavaPlugin {
|
||||
return this.playerSessions.get(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab and return the Teleport class.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public MVTeleport getTeleporter() {
|
||||
return new MVTeleport(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab the iConomy setup.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static iConomy getiConomy() {
|
||||
return iConomy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab the Permissions Handler for MultiVerse
|
||||
*/
|
||||
public MVPermissions getPermissions() {
|
||||
return this.ph;
|
||||
}
|
||||
|
||||
|
||||
public PurgeWorlds getWorldPurger() {
|
||||
return this.worldPurger;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* onCommand
|
||||
*/
|
||||
@ -502,10 +500,10 @@ public class MultiverseCore extends JavaPlugin {
|
||||
}
|
||||
return this.commandManager.dispatch(sender, command, commandLabel, args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print messages to the server Log as well as to our DebugLog. 'debugLog' is used to seperate Heroes information from the Servers Log Output.
|
||||
*
|
||||
*
|
||||
* @param level
|
||||
* @param msg
|
||||
*/
|
||||
@ -513,10 +511,10 @@ public class MultiverseCore extends JavaPlugin {
|
||||
log.log(level, this.tag + " " + msg);
|
||||
debugLog.log(level, this.tag + " " + msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print messages to the Debug Log, if the servers in Debug Mode then we also wan't to print the messages to the standard Server Console.
|
||||
*
|
||||
*
|
||||
* @param level
|
||||
* @param msg
|
||||
*/
|
||||
@ -526,20 +524,20 @@ public class MultiverseCore extends JavaPlugin {
|
||||
}
|
||||
debugLog.log(level, "[Debug] " + msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse the Authors Array into a readable String with ',' and 'and'.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getAuthors() {
|
||||
String authors = "";
|
||||
ArrayList<String> auths = this.getDescription().getAuthors();
|
||||
|
||||
|
||||
if (auths.size() == 1) {
|
||||
return auths.get(0);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < auths.size(); i++) {
|
||||
if (i == this.getDescription().getAuthors().size() - 1) {
|
||||
authors += " and " + this.getDescription().getAuthors().get(i);
|
||||
@ -549,18 +547,18 @@ public class MultiverseCore extends JavaPlugin {
|
||||
}
|
||||
return authors.substring(2);
|
||||
}
|
||||
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return this.commandManager;
|
||||
}
|
||||
|
||||
|
||||
public String getTag() {
|
||||
return this.tag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This code should get moved somewhere more appropriate, but for now, it's here.
|
||||
*
|
||||
*
|
||||
* @param env
|
||||
* @return
|
||||
*/
|
||||
@ -568,33 +566,33 @@ public class MultiverseCore extends JavaPlugin {
|
||||
// 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("SKYLANDS") || env.equalsIgnoreCase("SKYLAND") || env.equalsIgnoreCase("STARWARS"))
|
||||
env = "SKYLANDS";
|
||||
|
||||
|
||||
if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD"))
|
||||
env = "NORMAL";
|
||||
|
||||
|
||||
try {
|
||||
return Environment.valueOf(env);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: Find out where to put these next 3 methods! I just stuck them here for now --FF
|
||||
|
||||
|
||||
public Collection<MVWorld> getMVWorlds() {
|
||||
return this.worlds.values();
|
||||
}
|
||||
|
||||
|
||||
public MVWorld getMVWorld(String name) {
|
||||
if (this.worlds.containsKey(name)) {
|
||||
return this.worlds.get(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean isMVWorld(String name) {
|
||||
return this.worlds.containsKey(name);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user