mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-09-18 18:41:35 +02:00
Refactor MVWorld
This commit is contained in:
parent
cedc097efa
commit
028b910e9a
@ -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;
|
||||||
}
|
}
|
||||||
@ -244,7 +233,7 @@ public class MVWorld {
|
|||||||
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);
|
||||||
@ -265,7 +254,7 @@ public class MVWorld {
|
|||||||
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());
|
||||||
@ -278,7 +267,6 @@ public class MVWorld {
|
|||||||
return this.monsterList;
|
return this.monsterList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Boolean getPvp() {
|
public Boolean getPvp() {
|
||||||
return this.pvp;
|
return this.pvp;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user