Refactor MVWorld

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

View File

@ -27,7 +27,7 @@ public class MVWorld {
public List<String> monsterList = new ArrayList<String>(); // Contain a list of Monsters which we want to ignore the Spawn Setting. public List<String> monsterList = new ArrayList<String>(); // Contain a list of Monsters which we want to ignore the Spawn Setting.
private Boolean pvp; // Does this World allow PVP? private Boolean pvp; // Does this World allow PVP?
public List<Integer> blockBlacklist; // Contain a list of Blocks which we won't allow on this World. public List<Integer> blockBlacklist; // Contain a list of Blocks which we won't allow on this World.
public List<String> playerWhitelist; // Contain a list of Players/Groups which can join this World. public List<String> playerWhitelist; // Contain a list of Players/Groups which can join this World.
public List<String> playerBlacklist; // Contain a list of Players/Groups which cannot join this World. public List<String> playerBlacklist; // Contain a list of Players/Groups which cannot join this World.
@ -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 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 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) { public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
this.config = config; this.config = config;
this.plugin = instance; this.plugin = instance;
// Set local values that CANNOT be changed by user
this.world = world; this.world = world;
this.name = world.getName(); this.name = world.getName();
this.generator = world.getGenerator(); this.generator = generatorString;
this.generatorString = generatorString;
this.seed = seed; this.seed = seed;
this.environment = world.getEnvironment(); 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(); this.initLists();
// Set local values that CAN be changed by the user
this.setAlias(config.getString("worlds." + this.name + ".alias", "")); this.setAlias(config.getString("worlds." + this.name + ".alias", ""));
this.setPvp(config.getBoolean("worlds." + this.name + ".pvp", true)); this.setPvp(config.getBoolean("worlds." + this.name + ".pvp", true));
this.setScaling(config.getDouble("worlds." + this.name + ".scale", 1.0)); this.setScaling(config.getDouble("worlds." + this.name + ".scale", 1.0));
if (this.scaling <= 0) { if (this.scaling <= 0) {
// Disallow negative or 0 scalings. // Disallow negative or 0 scalings.
config.setProperty("worlds." + this.name + ".scale", 1.0); config.setProperty("worlds." + this.name + ".scale", 1.0);
this.scaling = 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.playerWhitelist = config.getStringList("worlds." + this.name + ".playerWhitelist", this.playerWhitelist);
this.playerBlacklist = config.getStringList("worlds." + this.name + ".playerBlacklist", this.playerBlacklist); 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.editWhitelist = config.getStringList("worlds." + this.name + ".editWhitelist", this.editWhitelist);
this.editBlacklist = config.getStringList("worlds." + this.name + ".editBlacklist", this.editBlacklist); 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(); config.save();
// The following 3 lines will add some sample data to new worlds created. // The following 3 lines will add some sample data to new worlds created.
// if (config.getIntList("worlds." + name + ".blockBlacklist", new ArrayList<Integer>()).size() == 0) { // if (config.getIntList("worlds." + name + ".blockBlacklist", new ArrayList<Integer>()).size() == 0) {
@ -109,19 +111,6 @@ public class MVWorld {
return this.world; 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() { private void initLists() {
this.blockBlacklist = new ArrayList<Integer>(); this.blockBlacklist = new ArrayList<Integer>();
this.playerWhitelist = new ArrayList<String>(); this.playerWhitelist = new ArrayList<String>();
@ -172,32 +161,32 @@ public class MVWorld {
// The booleans // The booleans
try { try {
boolean boolValue = Boolean.parseBoolean(value); boolean boolValue = Boolean.parseBoolean(value);
if(name.equalsIgnoreCase("pvp")){ if (name.equalsIgnoreCase("pvp")) {
this.pvp = boolValue; this.pvp = boolValue;
} } else if (name.equalsIgnoreCase("animals")) {
else if(name.equalsIgnoreCase("animals")){
this.animals = boolValue; this.animals = boolValue;
} } else if (name.equalsIgnoreCase("monsters")) {
else if(name.equalsIgnoreCase("monsters")){
this.monsters = boolValue; this.monsters = boolValue;
} else { } else {
return false; return false;
} }
return true; return true;
} catch (Exception e) {} } catch (Exception e) {
}
// The Doubles // The Doubles
try { try {
double doubleValue = Double.parseDouble(value); double doubleValue = Double.parseDouble(value);
if(name.equalsIgnoreCase("scaling")){ if (name.equalsIgnoreCase("scaling")) {
this.scaling = doubleValue; this.scaling = doubleValue;
return true; return true;
} }
} catch (Exception e) {} } catch (Exception e) {
}
// The Strings // The Strings
if(name.equalsIgnoreCase("alias")) { if (name.equalsIgnoreCase("alias")) {
this.alias = value; this.alias = value;
return true; return true;
} }
@ -208,43 +197,43 @@ public class MVWorld {
public Environment getEnvironment() { public Environment getEnvironment() {
return this.environment; return this.environment;
} }
public void setEnvironment(Environment environment) { public void setEnvironment(Environment environment) {
this.environment = environment; this.environment = environment;
} }
public Long getSeed() { public Long getSeed() {
return this.seed; return this.seed;
} }
public void setSeed(Long seed) { public void setSeed(Long seed) {
this.seed = seed; this.seed = seed;
} }
public String getName() { public String getName() {
return this.name; return this.name;
} }
public String getAlias() { public String getAlias() {
return this.alias; return this.alias;
} }
public void setAlias(String alias) { public void setAlias(String alias) {
this.alias = alias; this.alias = alias;
this.config.setProperty("worlds." + this.name + ".alias", alias); this.config.setProperty("worlds." + this.name + ".alias", alias);
this.config.save(); this.config.save();
} }
public Boolean hasAnimals() { public Boolean hasAnimals() {
return this.animals; return this.animals;
} }
public void setAnimals(Boolean animals) { public void setAnimals(Boolean animals) {
this.animals = animals; this.animals = animals;
// If animals are a boolean, then we can turn them on or off on the server // 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 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); this.world.setSpawnFlags(this.world.getAllowMonsters(), animals);
} else { } else {
this.world.setSpawnFlags(this.world.getAllowMonsters(), true); this.world.setSpawnFlags(this.world.getAllowMonsters(), true);
@ -252,20 +241,20 @@ public class MVWorld {
this.config.setProperty("worlds." + this.name + ".animals", animals); this.config.setProperty("worlds." + this.name + ".animals", animals);
this.config.save(); this.config.save();
} }
public List<String> getAnimalList() { public List<String> getAnimalList() {
return this.animalList; return this.animalList;
} }
public Boolean hasMonsters() { public Boolean hasMonsters() {
return this.monsters; return this.monsters;
} }
public void setMonsters(Boolean monsters) { public void setMonsters(Boolean monsters) {
this.monsters = monsters; this.monsters = monsters;
// If monsters are a boolean, then we can turn them on or off on the server // 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 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()); this.world.setSpawnFlags(monsters, this.world.getAllowAnimals());
} else { } else {
this.world.setSpawnFlags(true, this.world.getAllowAnimals()); this.world.setSpawnFlags(true, this.world.getAllowAnimals());
@ -273,16 +262,15 @@ public class MVWorld {
this.config.setProperty("worlds." + this.name + ".monsters", monsters); this.config.setProperty("worlds." + this.name + ".monsters", monsters);
this.config.save(); this.config.save();
} }
public List<String> getMonsterList() { public List<String> getMonsterList() {
return this.monsterList; return this.monsterList;
} }
public Boolean getPvp() { public Boolean getPvp() {
return this.pvp; return this.pvp;
} }
public void setPvp(Boolean pvp) { public void setPvp(Boolean pvp) {
this.world.setPVP(pvp); this.world.setPVP(pvp);
this.pvp = pvp; this.pvp = pvp;
@ -290,31 +278,31 @@ public class MVWorld {
this.config.save(); this.config.save();
} }
public List<Integer> getBlockBlacklist() { public List<Integer> getBlockBlacklist() {
return this.blockBlacklist; return this.blockBlacklist;
} }
public List<String> getPlayerWhitelist() { public List<String> getPlayerWhitelist() {
return this.playerWhitelist; return this.playerWhitelist;
} }
public List<String> getPlayerBlacklist() { public List<String> getPlayerBlacklist() {
return this.playerBlacklist; return this.playerBlacklist;
} }
public List<String> getEditWhitelist() { public List<String> getEditWhitelist() {
return this.editWhitelist; return this.editWhitelist;
} }
public List<String> getEditBlacklist() { public List<String> getEditBlacklist() {
return this.editBlacklist; return this.editBlacklist;
} }
public Double getScaling() { public Double getScaling() {
return this.scaling; return this.scaling;
} }
public void setScaling(Double scaling) { public void setScaling(Double scaling) {
this.scaling = scaling; this.scaling = scaling;
this.config.setProperty("worlds." + this.name + ".scaling", scaling); this.config.setProperty("worlds." + this.name + ".scaling", scaling);