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.
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<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.
@ -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;
}
@ -208,43 +197,43 @@ public class MVWorld {
public Environment getEnvironment() {
return this.environment;
}
public void setEnvironment(Environment environment) {
this.environment = environment;
}
public Long getSeed() {
return this.seed;
}
public void setSeed(Long seed) {
this.seed = seed;
}
public String getName() {
return this.name;
}
public String getAlias() {
return this.alias;
}
public void setAlias(String alias) {
this.alias = alias;
this.config.setProperty("worlds." + this.name + ".alias", alias);
this.config.save();
}
public Boolean hasAnimals() {
return this.animals;
}
public void setAnimals(Boolean animals) {
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);
@ -252,20 +241,20 @@ public class MVWorld {
this.config.setProperty("worlds." + this.name + ".animals", animals);
this.config.save();
}
public List<String> getAnimalList() {
return this.animalList;
}
public Boolean hasMonsters() {
return this.monsters;
}
public void setMonsters(Boolean monsters) {
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());
@ -273,16 +262,15 @@ public class MVWorld {
this.config.setProperty("worlds." + this.name + ".monsters", monsters);
this.config.save();
}
public List<String> getMonsterList() {
return this.monsterList;
}
public Boolean getPvp() {
return this.pvp;
}
public void setPvp(Boolean pvp) {
this.world.setPVP(pvp);
this.pvp = pvp;
@ -290,31 +278,31 @@ public class MVWorld {
this.config.save();
}
public List<Integer> getBlockBlacklist() {
return this.blockBlacklist;
}
public List<String> getPlayerWhitelist() {
return this.playerWhitelist;
}
public List<String> getPlayerBlacklist() {
return this.playerBlacklist;
}
public List<String> getEditWhitelist() {
return this.editWhitelist;
}
public List<String> getEditBlacklist() {
return this.editBlacklist;
}
public Double getScaling() {
return this.scaling;
}
public void setScaling(Double scaling) {
this.scaling = scaling;
this.config.setProperty("worlds." + this.name + ".scaling", scaling);