mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-02 16:59:56 +01:00
Plugins can register with MV as a custom world type now!
This commit is contained in:
parent
a2bef29bc2
commit
09b6d72881
@ -38,7 +38,7 @@ public class MVWorld {
|
|||||||
|
|
||||||
public Double scaling; // How stretched/compressed distances are
|
public Double scaling; // How stretched/compressed distances are
|
||||||
|
|
||||||
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, ChunkGenerator customGenerator) {
|
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String env) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.plugin = instance;
|
this.plugin = instance;
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ public class MVWorld {
|
|||||||
this.monsterList.add(s.toUpperCase());
|
this.monsterList.add(s.toUpperCase());
|
||||||
//System.out.print(s);
|
//System.out.print(s);
|
||||||
}
|
}
|
||||||
config.setProperty("worlds." + this.name + ".environment", this.environment.toString());
|
config.setProperty("worlds." + this.name + ".environment", env);
|
||||||
if(seed != null) {
|
if(seed != null) {
|
||||||
config.setProperty("worlds." + this.name + ".seed", this.seed);
|
config.setProperty("worlds." + this.name + ".seed", this.seed);
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,9 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
// updateCheck = new UpdateChecker(this.getDescription().getName(), this.getDescription().getVersion());
|
// updateCheck = new UpdateChecker(this.getDescription().getName(), this.getDescription().getVersion());
|
||||||
|
|
||||||
// Call the Function to load all the Worlds and setup the HashMap
|
// Call the Function to load all the Worlds and setup the HashMap
|
||||||
loadWorlds();
|
// When called with null, it tries to load ALL
|
||||||
|
// this function will be called every time a plugin registers a new envtype with MV
|
||||||
|
loadWorlds(null);
|
||||||
|
|
||||||
// Purge Worlds of old Monsters/Animals which don't adhere to the setup.
|
// Purge Worlds of old Monsters/Animals which don't adhere to the setup.
|
||||||
purgeWorlds();
|
purgeWorlds();
|
||||||
@ -310,7 +312,7 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Load the Worlds & Settings from the configuration file.
|
* Load the Worlds & Settings from the configuration file.
|
||||||
*/
|
*/
|
||||||
public void loadWorlds() {
|
public void loadWorlds(String filter) {
|
||||||
// Basic Counter to count how many Worlds we are loading.
|
// Basic Counter to count how many Worlds we are loading.
|
||||||
int count = 0;
|
int count = 0;
|
||||||
// Grab all the Worlds from the Config.
|
// Grab all the Worlds from the Config.
|
||||||
@ -327,14 +329,22 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
String environment = configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
|
String environment = configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
|
||||||
String seedString = configWorlds.getString("worlds." + worldKey + ".seed", "");
|
String seedString = configWorlds.getString("worlds." + worldKey + ".seed", "");
|
||||||
|
|
||||||
|
|
||||||
log(Level.INFO, "Loading World & Settings - '" + worldKey + "' - " + environment);
|
log(Level.INFO, "Loading World & Settings - '" + worldKey + "' - " + environment);
|
||||||
|
|
||||||
|
boolean isStockWorldType = this.getEnvFromString(environment) != null;
|
||||||
|
|
||||||
// If we don't have a seed then add a standard World, else add the world with the Seed.
|
// If we don't have a seed then add a standard World, else add the world with the Seed.
|
||||||
addWorld(worldKey, environment, seedString);
|
if (filter == null && isStockWorldType) {
|
||||||
// Increment the World Count.
|
addWorld(worldKey, environment, seedString);
|
||||||
count++;
|
// Increment the world count
|
||||||
|
count++;
|
||||||
|
} else if (filter != null && filter.equalsIgnoreCase(environment)) {
|
||||||
|
addWorld(worldKey, environment, seedString);
|
||||||
|
// Increment the world count
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
log(Level.INFO, "World " + worldKey + " was not loaded YET. Multiverse is waiting for a plugin to handle the environment type " + environment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +365,7 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
World world = this.getServer().getWorlds().get(0);
|
World world = this.getServer().getWorlds().get(0);
|
||||||
if (!this.worlds.containsKey(world.getName())) {
|
if (!this.worlds.containsKey(world.getName())) {
|
||||||
log.info("Loading World & Settings - '" + world.getName() + "' - " + world.getEnvironment());
|
log.info("Loading World & Settings - '" + world.getName() + "' - " + world.getEnvironment());
|
||||||
addWorld(world.getName(), Environment.NORMAL, null, null);
|
addWorld(world.getName(), "NORMAL", "");
|
||||||
additonalWorldsLoaded++;
|
additonalWorldsLoaded++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +373,7 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
World world_nether = this.getServer().getWorld(world.getName() + "_nether");
|
World world_nether = this.getServer().getWorld(world.getName() + "_nether");
|
||||||
if (world_nether != null && !this.worlds.containsKey(world_nether.getName())) {
|
if (world_nether != null && !this.worlds.containsKey(world_nether.getName())) {
|
||||||
log.info("Loading World & Settings - '" + world.getName() + "' - " + world_nether.getEnvironment());
|
log.info("Loading World & Settings - '" + world.getName() + "' - " + world_nether.getEnvironment());
|
||||||
addWorld(world_nether.getName(), Environment.NETHER, null, null);
|
addWorld(world_nether.getName(), "NORMAL", "");
|
||||||
additonalWorldsLoaded++;
|
additonalWorldsLoaded++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,37 +389,6 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
public long getSeed(World w) {
|
public long getSeed(World w) {
|
||||||
return ((CraftWorld) w).getHandle().worldData.b();
|
return ((CraftWorld) w).getHandle().worldData.b();
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param envString
|
|
||||||
* @param seedString
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean addWorld(String name, String envString, String seedString) {
|
|
||||||
Long seed = null;
|
|
||||||
Environment env = getEnvFromString(envString);
|
|
||||||
ChunkGenerator customGenerator = getChunkGenFromEnv(envString);
|
|
||||||
if(env == null) {
|
|
||||||
env = Environment.NORMAL;
|
|
||||||
// If the env was null, ie. not a built in one.
|
|
||||||
// AND the customGenerator is null, then someone
|
|
||||||
// screwed up... return false!
|
|
||||||
if(customGenerator == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seedString.length() > 0) {
|
|
||||||
try {
|
|
||||||
seed = Long.parseLong(seedString);
|
|
||||||
} catch (NumberFormatException numberformatexception) {
|
|
||||||
seed = (long) seedString.hashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.addWorld(name, env, seed, customGenerator);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new World to the Multiverse Setup.
|
* Add a new World to the Multiverse Setup.
|
||||||
@ -419,33 +398,52 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
* @param name World Name
|
* @param name World Name
|
||||||
* @param environment Environment Type
|
* @param environment Environment Type
|
||||||
*/
|
*/
|
||||||
private void addWorld(String name, Environment environment, Long seed, ChunkGenerator customGenerator) {
|
public boolean addWorld(String name, String envString, String seedString) {
|
||||||
if (seed != null) {
|
|
||||||
if (customGenerator != null) {
|
Long seed = null;
|
||||||
World world = getServer().createWorld(name, environment, seed, customGenerator);
|
if (seedString.length() > 0) {
|
||||||
worlds.put(name, new MVWorld(world, configWorlds, this, seed, customGenerator)); // Place the World into the HashMap.
|
try {
|
||||||
log(Level.INFO, "Loading World & Settings - '" + name + "' - CUSTOMENV with seed: " + seed);
|
seed = Long.parseLong(seedString);
|
||||||
} else {
|
} catch (NumberFormatException numberformatexception) {
|
||||||
World world = getServer().createWorld(name, environment, seed);
|
seed = (long) seedString.hashCode();
|
||||||
worlds.put(name, new MVWorld(world, configWorlds, this, seed, null)); // Place the World into the HashMap.
|
|
||||||
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + environment + " with seed: " + seed);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (customGenerator != null) {
|
|
||||||
World world = getServer().createWorld(name, environment, customGenerator);
|
|
||||||
worlds.put(name, new MVWorld(world, configWorlds, this, null, customGenerator)); // Place the World into the HashMap.
|
|
||||||
log(Level.INFO, "Loading World & Settings - '" + name + "' - CUSTOMENV");
|
|
||||||
} else {
|
|
||||||
World world = getServer().createWorld(name, environment);
|
|
||||||
worlds.put(name, new MVWorld(world, configWorlds, this, null, null)); // Place the World into the HashMap.
|
|
||||||
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + environment);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
Environment env = getEnvFromString(envString);
|
||||||
|
ChunkGenerator customGenerator = getChunkGenFromEnv(envString);
|
||||||
public void addWorld(String name, Environment environment) {
|
if (env == null) {
|
||||||
addWorld(name, environment, null, null);
|
env = Environment.NORMAL;
|
||||||
|
// If the env was null, ie. not a built in one.
|
||||||
|
// AND the customGenerator is null, then someone
|
||||||
|
// screwed up... return false!
|
||||||
|
if (customGenerator == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seed != null) {
|
||||||
|
if (customGenerator != null) {
|
||||||
|
World world = getServer().createWorld(name, env, seed, customGenerator);
|
||||||
|
worlds.put(name, new MVWorld(world, configWorlds, this, seed, envString)); // Place the World into the HashMap.
|
||||||
|
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + envString + " with seed: " + seed);
|
||||||
|
} else {
|
||||||
|
World world = getServer().createWorld(name, env, seed);
|
||||||
|
worlds.put(name, new MVWorld(world, configWorlds, this, seed, envString)); // Place the World into the HashMap.
|
||||||
|
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (customGenerator != null) {
|
||||||
|
World world = getServer().createWorld(name, env, customGenerator);
|
||||||
|
worlds.put(name, new MVWorld(world, configWorlds, this, null, envString)); // Place the World into the HashMap.
|
||||||
|
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + envString);
|
||||||
|
} else {
|
||||||
|
World world = getServer().createWorld(name, env);
|
||||||
|
worlds.put(name, new MVWorld(world, configWorlds, this, null, envString)); // Place the World into the HashMap.
|
||||||
|
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -655,7 +653,7 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
return Environment.valueOf(env);
|
return Environment.valueOf(env);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// Sender will be null on loadWorlds
|
// Sender will be null on loadWorlds
|
||||||
return Environment.NORMAL;
|
return null;
|
||||||
// TODO: Show the player the mvenvironments command.
|
// TODO: Show the player the mvenvironments command.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -668,10 +666,11 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean registerEnvType(String name, ChunkGenerator generator) {
|
public boolean registerEnvType(String name, ChunkGenerator generator) {
|
||||||
if (worldGenerators.containsKey(name)) {
|
if (this.worldGenerators.containsKey(name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
worldGenerators.put(name, generator);
|
this.worldGenerators.put(name, generator);
|
||||||
|
this.loadWorlds(name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,11 +31,11 @@ public class ImportCommand extends BaseCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment env = plugin.getEnvFromString(args[1]);
|
String env = args[1];
|
||||||
|
|
||||||
if (new File(worldName).exists() && env != null) {
|
if (new File(worldName).exists() && env != null) {
|
||||||
sender.sendMessage(ChatColor.AQUA + "Starting world import...");
|
sender.sendMessage(ChatColor.AQUA + "Starting world import...");
|
||||||
plugin.addWorld(worldName, env);
|
plugin.addWorld(worldName, env, "");
|
||||||
sender.sendMessage(ChatColor.GREEN + "Complete!");
|
sender.sendMessage(ChatColor.GREEN + "Complete!");
|
||||||
return;
|
return;
|
||||||
} else if(env == null) {
|
} else if(env == null) {
|
||||||
|
@ -26,7 +26,7 @@ public class ReloadCommand extends BaseCommand {
|
|||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
plugin.log(Level.INFO, "Reloading Multiverse-Core config");
|
plugin.log(Level.INFO, "Reloading Multiverse-Core config");
|
||||||
plugin.loadConfigs();
|
plugin.loadConfigs();
|
||||||
plugin.loadWorlds();
|
plugin.loadWorlds(null);
|
||||||
plugin.log(Level.INFO, "Reload Complete!");
|
plugin.log(Level.INFO, "Reload Complete!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user