Refactor MVWorld

This commit is contained in:
Eric Stokes 2011-06-26 11:00:52 -06:00
parent cedc097efa
commit 028b910e9a

View File

@ -36,33 +36,47 @@ public class MVWorld {
public List<String> worldBlacklist; // Contain a list of Worlds which Players cannot use to Portal to this World.
public Double scaling; // How stretched/compressed distances are
private ChunkGenerator generator;
private String generatorString;
/**
* The generator as a string. This is used only for reporting.
* ex: BukkitFullOfMoon:GenID
*/
private String generator;
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
this.config = config;
this.plugin = instance;
// Set local values that CANNOT be changed by user
this.world = world;
this.name = world.getName();
this.generator = world.getGenerator();
this.generatorString = generatorString;
this.generator = generatorString;
this.seed = seed;
this.environment = world.getEnvironment();
// Write these files to the config (once it's saved)
if (generatorString != null) {
config.setProperty("worlds." + this.name + ".generator", this.generator);
}
if (seed != null) {
config.setProperty("worlds." + this.name + ".seed", this.seed);
}
config.setProperty("worlds." + this.name + ".environment", this.environment.toString());
// Initialize our lists
this.initLists();
// Set local values that CAN be changed by the user
this.setAlias(config.getString("worlds." + this.name + ".alias", ""));
this.setPvp(config.getBoolean("worlds." + this.name + ".pvp", true));
this.setScaling(config.getDouble("worlds." + this.name + ".scale", 1.0));
if (this.scaling <= 0) {
// Disallow negative or 0 scalings.
config.setProperty("worlds." + this.name + ".scale", 1.0);
this.scaling = 1.0;
}
this.setAnimals(config.getBoolean("worlds." + this.name + ".animals.spawn", true));
this.setMonsters(config.getBoolean("worlds." + this.name + ".monsters.spawn", true));
this.getMobExceptions();
this.playerWhitelist = config.getStringList("worlds." + this.name + ".playerWhitelist", this.playerWhitelist);
this.playerBlacklist = config.getStringList("worlds." + this.name + ".playerBlacklist", this.playerBlacklist);
@ -71,18 +85,6 @@ public class MVWorld {
this.editWhitelist = config.getStringList("worlds." + this.name + ".editWhitelist", this.editWhitelist);
this.editBlacklist = config.getStringList("worlds." + this.name + ".editBlacklist", this.editBlacklist);
this.animals = config.getBoolean("worlds." + this.name + ".animals.spawn", true);
this.monsters = config.getBoolean("worlds." + this.name + ".monsters.spawn", true);
this.getMobExceptions();
this.setRealMobBehaviors();
config.setProperty("worlds." + this.name + ".environment", this.environment.toString());
config.setProperty("worlds." + this.name + ".generator",generatorString);
if (seed != null) {
config.setProperty("worlds." + this.name + ".seed", this.seed);
}
config.save();
// The following 3 lines will add some sample data to new worlds created.
// if (config.getIntList("worlds." + name + ".blockBlacklist", new ArrayList<Integer>()).size() == 0) {
@ -109,19 +111,6 @@ public class MVWorld {
return this.world;
}
private void setRealMobBehaviors() {
boolean animals = true;
boolean monsters = true;
if (!this.animals && this.animalList.isEmpty()) {
animals = false;
}
if (!this.monsters && this.monsterList.isEmpty()) {
monsters = false;
}
this.world.setSpawnFlags(monsters, animals);
}
private void initLists() {
this.blockBlacklist = new ArrayList<Integer>();
this.playerWhitelist = new ArrayList<String>();
@ -172,32 +161,32 @@ public class MVWorld {
// The booleans
try {
boolean boolValue = Boolean.parseBoolean(value);
if(name.equalsIgnoreCase("pvp")){
if (name.equalsIgnoreCase("pvp")) {
this.pvp = boolValue;
}
else if(name.equalsIgnoreCase("animals")){
} else if (name.equalsIgnoreCase("animals")) {
this.animals = boolValue;
}
else if(name.equalsIgnoreCase("monsters")){
} else if (name.equalsIgnoreCase("monsters")) {
this.monsters = boolValue;
} else {
return false;
}
return true;
} catch (Exception e) {}
} catch (Exception e) {
}
// The Doubles
try {
double doubleValue = Double.parseDouble(value);
if(name.equalsIgnoreCase("scaling")){
if (name.equalsIgnoreCase("scaling")) {
this.scaling = doubleValue;
return true;
}
} catch (Exception e) {}
} catch (Exception e) {
}
// The Strings
if(name.equalsIgnoreCase("alias")) {
if (name.equalsIgnoreCase("alias")) {
this.alias = value;
return true;
}
@ -244,7 +233,7 @@ public class MVWorld {
this.animals = animals;
// If animals are a boolean, then we can turn them on or off on the server
// If there are ANY exceptions, there will be something spawning, so turn them on
if(this.getAnimalList().isEmpty()) {
if (this.getAnimalList().isEmpty()) {
this.world.setSpawnFlags(this.world.getAllowMonsters(), animals);
} else {
this.world.setSpawnFlags(this.world.getAllowMonsters(), true);
@ -265,7 +254,7 @@ public class MVWorld {
this.monsters = monsters;
// If monsters are a boolean, then we can turn them on or off on the server
// If there are ANY exceptions, there will be something spawning, so turn them on
if(this.getAnimalList().isEmpty()) {
if (this.getAnimalList().isEmpty()) {
this.world.setSpawnFlags(monsters, this.world.getAllowAnimals());
} else {
this.world.setSpawnFlags(true, this.world.getAllowAnimals());
@ -278,7 +267,6 @@ public class MVWorld {
return this.monsterList;
}
public Boolean getPvp() {
return this.pvp;
}