More work on mvmodify; Better integration with Custom gens

This commit is contained in:
Eric Stokes 2011-06-26 08:55:24 -06:00
parent b2bcb941c3
commit 19da230723
9 changed files with 346 additions and 135 deletions

View File

@ -15,8 +15,8 @@ public class MVWorld {
private Configuration config; // Hold the Configuration File. private Configuration config; // Hold the Configuration File.
public World world; // The World Instance. public World world; // The World Instance.
public String environment; // Hold the Environment type EG Environment.NETHER / Environment.NORMAL private Environment environment; // Hold the Environment type EG Environment.NETHER / Environment.NORMAL
public Long seed; private Long seed;
public String name; // The Worlds Name, EG its folder name. public String name; // The Worlds Name, EG its folder name.
public String alias = ""; // Short Alias for the World, this will be used in Chat Prefixes. public String alias = ""; // Short Alias for the World, this will be used in Chat Prefixes.
@ -27,7 +27,7 @@ public class MVWorld {
public Boolean monsters; // Does this World allow Monsters to Spawn? public Boolean monsters; // Does this World allow Monsters to Spawn?
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.
public 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.
@ -37,24 +37,28 @@ 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;
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String env) {
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
this.config = config; this.config = config;
this.plugin = instance; this.plugin = instance;
this.world = world; this.world = world;
this.name = world.getName(); this.name = world.getName();
this.environment = env; this.generator = world.getGenerator();
this.generatorString = generatorString;
this.seed = seed; this.seed = seed;
this.initLists(); this.initLists();
this.alias = config.getString("worlds." + this.name + ".alias", ""); this.setAlias(config.getString("worlds." + this.name + ".alias", ""));
this.pvp = config.getBoolean("worlds." + this.name + ".pvp", true); this.setPvp(config.getBoolean("worlds." + this.name + ".pvp", true));
this.scaling = 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;
@ -70,21 +74,20 @@ public class MVWorld {
this.animals = config.getBoolean("worlds." + this.name + ".animals.spawn", true); this.animals = config.getBoolean("worlds." + this.name + ".animals.spawn", true);
this.monsters = config.getBoolean("worlds." + this.name + ".monsters.spawn", true); this.monsters = config.getBoolean("worlds." + this.name + ".monsters.spawn", true);
this.getMobExceptions(); this.getMobExceptions();
this.setRealMobBehaviors(); this.setRealMobBehaviors();
config.setProperty("worlds." + this.name + ".environment", env); config.setProperty("worlds." + this.name + ".environment", world.getEnvironment());
if(seed != null) { config.setProperty("worlds." + this.name + ".generatorString",generatorString);
if (seed != null) {
config.setProperty("worlds." + this.name + ".seed", this.seed); 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) {
// addSampleData(); // addSampleData();
// } // }
} }
private void getMobExceptions() { private void getMobExceptions() {
@ -109,10 +112,10 @@ public class MVWorld {
private void setRealMobBehaviors() { private void setRealMobBehaviors() {
boolean animals = true; boolean animals = true;
boolean monsters = true; boolean monsters = true;
if(!this.animals && this.animalList.isEmpty()) { if (!this.animals && this.animalList.isEmpty()) {
animals = false; animals = false;
} }
if(!this.monsters && this.monsterList.isEmpty()) { if (!this.monsters && this.monsterList.isEmpty()) {
monsters = false; monsters = false;
} }
this.world.setSpawnFlags(monsters, animals); this.world.setSpawnFlags(monsters, animals);
@ -160,4 +163,161 @@ public class MVWorld {
this.config.setProperty("worlds." + this.name + ".worldBlacklist", this.worldBlacklist); this.config.setProperty("worlds." + this.name + ".worldBlacklist", this.worldBlacklist);
this.config.save(); this.config.save();
} }
public boolean clearVariable(String property) {
return false;
}
public boolean setVariable(String name, String value) {
// The booleans
try {
boolean boolValue = Boolean.parseBoolean(value);
if(name.equalsIgnoreCase("pvp")){
this.pvp = boolValue;
}
else if(name.equalsIgnoreCase("animals")){
this.animals = boolValue;
}
else if(name.equalsIgnoreCase("monsters")){
this.monsters = boolValue;
} else {
return false;
}
return true;
} catch (Exception e) {}
// The Doubles
try {
double doubleValue = Double.parseDouble(value);
if(name.equalsIgnoreCase("scaling")){
this.scaling = doubleValue;
return true;
}
} catch (Exception e) {}
// The Strings
if(name.equalsIgnoreCase("alias")) {
this.alias = value;
return true;
}
return false;
}
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()) {
this.world.setSpawnFlags(this.world.getAllowMonsters(), animals);
} else {
this.world.setSpawnFlags(this.world.getAllowMonsters(), true);
}
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()) {
this.world.setSpawnFlags(monsters, this.world.getAllowAnimals());
} else {
this.world.setSpawnFlags(true, this.world.getAllowAnimals());
}
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;
this.config.setProperty("worlds." + this.name + ".pvp", pvp);
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);
this.config.save();
}
} }

View File

@ -97,9 +97,6 @@ public class MultiverseCore extends JavaPlugin {
// HashMap to contain all the Worlds which this Plugin will manage. // HashMap to contain all the Worlds which this Plugin will manage.
private HashMap<String, MVWorld> worlds = new HashMap<String, MVWorld>(); private HashMap<String, MVWorld> worlds = new HashMap<String, MVWorld>();
// HashMap to contain all custom generators. Plugins will have to register!
private HashMap<String, ChunkGenerator> worldGenerators = new HashMap<String, ChunkGenerator>();
// HashMap to contain information relating to the Players. // HashMap to contain information relating to the Players.
public HashMap<String, MVPlayerSession> playerSessions = new HashMap<String, MVPlayerSession>(); public HashMap<String, MVPlayerSession> playerSessions = new HashMap<String, MVPlayerSession>();
@ -333,20 +330,13 @@ public class MultiverseCore extends JavaPlugin {
log(Level.INFO, "Loading World & Settings - '" + worldKey + "' - " + environment); log(Level.INFO, "Loading World & Settings - '" + worldKey + "' - " + environment);
boolean isStockWorldType = this.getEnvFromString(environment) != null; String generator = this.configWorlds.getString("worlds." + worldKey + ".generator.name");
String generatorID = this.configWorlds.getString("worlds." + worldKey + ".generator.id");
// If we don't have a seed then add a standard World, else add the world with the Seed. addWorld(worldKey, getEnvFromString(environment), seedString, generator + ":" + generatorID);
if (filter == null && isStockWorldType) {
addWorld(worldKey, environment, seedString); // Increment the world count
// Increment the world count 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);
}
} }
} }
@ -367,7 +357,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(), "NORMAL", ""); addWorld(world.getName(), Environment.NORMAL, null, null);
additonalWorldsLoaded++; additonalWorldsLoaded++;
} }
@ -375,7 +365,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(), "NORMAL", ""); addWorld(world_nether.getName(), Environment.NETHER, null, null);
additonalWorldsLoaded++; additonalWorldsLoaded++;
} }
@ -400,7 +390,7 @@ public class MultiverseCore extends JavaPlugin {
* @param name World Name * @param name World Name
* @param environment Environment Type * @param environment Environment Type
*/ */
public boolean addWorld(String name, String envString, String seedString) { public boolean addWorld(String name, Environment env, String seedString, String generator) {
Long seed = null; Long seed = null;
if (seedString.length() > 0) { if (seedString.length() > 0) {
@ -411,43 +401,53 @@ public class MultiverseCore extends JavaPlugin {
} }
} }
Environment env = getEnvFromString(envString); String generatorID = null;
ChunkGenerator customGenerator = getChunkGenFromEnv(envString); String generatorName = null;
if (env == null) { if (generator != null) {
env = Environment.NORMAL; String[] split = generator.split(":", 2);
// If the env was null, ie. not a built in one. String id = (split.length > 1) ? split[1] : null;
// AND the customGenerator is null, then someone generatorName = split[0];
// screwed up... return false! generatorID = id;
if (customGenerator == null) {
return false;
}
} }
ChunkGenerator customGenerator = getChunkGenerator(generatorName, generatorID, name);
World world = null;
if (seed != null) { if (seed != null) {
if (customGenerator != null) { if (customGenerator != null) {
World world = getServer().createWorld(name, env, seed, customGenerator); world = getServer().createWorld(name, env, seed, customGenerator);
this.worlds.put(name, new MVWorld(world, this.configWorlds, this, seed, envString)); // Place the World into the HashMap. log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed + " & Custom Generator: " + generator);
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + envString + " with seed: " + seed);
} else { } else {
World world = getServer().createWorld(name, env, seed); world = getServer().createWorld(name, env, seed);
this.worlds.put(name, new MVWorld(world, this.configWorlds, this, seed, envString)); // Place the World into the HashMap.
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed); log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed);
} }
} else { } else {
if (customGenerator != null) { if (customGenerator != null) {
World world = getServer().createWorld(name, env, customGenerator); world = getServer().createWorld(name, env, customGenerator);
this.worlds.put(name, new MVWorld(world, this.configWorlds, this, null, envString)); // Place the World into the HashMap. log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " & Custom Generator: " + generator);
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + envString);
} else { } else {
World world = getServer().createWorld(name, env); world = getServer().createWorld(name, env);
this.worlds.put(name, new MVWorld(world, this.configWorlds, this, null, envString)); // Place the World into the HashMap.
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env); log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env);
} }
} }
this.worlds.put(name, new MVWorld(world, this.configWorlds, this, seed, generator));
return true; return true;
} }
private ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName) {
if (generator == null) {
return null;
}
Plugin plugin = getServer().getPluginManager().getPlugin(generator);
if (plugin == null) {
return null;
} else {
return plugin.getDefaultWorldGenerator(worldName, generatorID);
}
}
/** /**
* Remove the world from the Multiverse list * Remove the world from the Multiverse list
* *
@ -654,31 +654,10 @@ public class MultiverseCore extends JavaPlugin {
try { try {
return Environment.valueOf(env); return Environment.valueOf(env);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return null; return Environment.NORMAL;
} }
} }
private ChunkGenerator getChunkGenFromEnv(String env) {
if (this.worldGenerators.containsKey(env)) {
return this.worldGenerators.get(env);
}
return null;
}
/**
* Other plugin devs can use this to tell MultiVerse about other environment types
* @param name
* @param generator
* @return
*/
public boolean registerEnvType(String name, ChunkGenerator generator) {
if (this.worldGenerators.containsKey(name)) {
return false;
}
this.worldGenerators.put(name, generator);
this.loadWorlds(name);
return true;
}
// TODO: Find out where to put these next 3 methods! I just stuck them here for now --FF // TODO: Find out where to put these next 3 methods! I just stuck them here for now --FF
/** /**
@ -731,16 +710,12 @@ public class MultiverseCore extends JavaPlugin {
} }
} }
public Set<String> getWorldGenerators() {
return this.worldGenerators.keySet();
}
public Collection<MVWorld> getMVWorlds() { public Collection<MVWorld> getMVWorlds() {
return this.worlds.values(); return this.worlds.values();
} }
public MVWorld getMVWorld(String name) { public MVWorld getMVWorld(String name) {
if(this.worlds.containsKey(name)) { if (this.worlds.containsKey(name)) {
return this.worlds.get(name); return this.worlds.get(name);
} }
return null; return null;

View File

@ -3,6 +3,7 @@ package com.onarandombox.MultiverseCore.command.commands;
import java.io.File; import java.io.File;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
@ -14,9 +15,9 @@ public class CreateCommand extends BaseCommand {
super(plugin); super(plugin);
this.name = "Create World"; this.name = "Create World";
this.description = "Creates a new world of the specified type"; this.description = "Creates a new world of the specified type";
this.usage = "/mvcreate" + ChatColor.GREEN + " {NAME} {TYPE}" + ChatColor.GOLD + " [SEED]"; this.usage = "/mvcreate" + ChatColor.GREEN + " {NAME} {TYPE}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:GENID]]";
this.minArgs = 2; this.minArgs = 2;
this.maxArgs = 3; this.maxArgs = 4;
this.identifiers.add("mvcreate"); this.identifiers.add("mvcreate");
this.permission = "multiverse.world.create"; this.permission = "multiverse.world.create";
this.requiresOp = true; this.requiresOp = true;
@ -25,33 +26,46 @@ public class CreateCommand extends BaseCommand {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
// TODO: Permissions, check
int numOfParams = args.length;
boolean hasSeed = numOfParams == 3;
String worldName = args[0]; String worldName = args[0];
String env = args[1]; String env = args[1];
String seed = ""; String seed = this.getFlag("-s", args);
if (hasSeed) { String generator = this.getFlag("-g", args);
seed = args[2];
}
if (new File(worldName).exists() || this.plugin.isMVWorld(worldName)) { if (new File(worldName).exists() || this.plugin.isMVWorld(worldName)) {
sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!"); sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport"); sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
return; return;
} }
if (this.plugin.addWorld(worldName, env, seed)) {
Environment environment = this.plugin.getEnvFromString(env);
if (this.plugin.addWorld(worldName, environment, seed, generator)) {
sender.sendMessage(ChatColor.GREEN + "Complete!"); sender.sendMessage(ChatColor.GREEN + "Complete!");
} else { } else {
sender.sendMessage(ChatColor.RED + "FAILED."); sender.sendMessage(ChatColor.RED + "FAILED.");
if(this.plugin.getEnvFromString(env) == null) {
sender.sendMessage("That world type did not exist.");
sender.sendMessage("For a list of available world types, type: /mvenv");
}
} }
return; return;
} }
/**
* Returns the given flag value
*
* @param flag A param flag, like -s or -g
* @param args All arguments to search through
* @return A string or null
*/
private String getFlag(String flag, String[] args) {
int i = 0;
try {
for (String s : args) {
if (s.equalsIgnoreCase(flag)) {
return args[i++];
}
i++;
}
} catch (IndexOutOfBoundsException e) {
}
return null;
}
} }

View File

@ -30,12 +30,6 @@ public class EnvironmentCommand extends BaseCommand{
sender.sendMessage(ChatColor.GREEN + "NORMAL"); sender.sendMessage(ChatColor.GREEN + "NORMAL");
sender.sendMessage(ChatColor.RED + "NETHER"); sender.sendMessage(ChatColor.RED + "NETHER");
sender.sendMessage(ChatColor.AQUA + "SKYLANDS"); sender.sendMessage(ChatColor.AQUA + "SKYLANDS");
if(this.plugin.getWorldGenerators().size() > 0) {
sender.sendMessage(ChatColor.DARK_AQUA + "CUSTOM WORLD TYPES:");
}
for(String s : this.plugin.getWorldGenerators()) {
sender.sendMessage(ChatColor.GOLD + s);
}
} }
} }

View File

@ -3,6 +3,7 @@ package com.onarandombox.MultiverseCore.command.commands;
import java.io.File; import java.io.File;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
@ -14,9 +15,9 @@ public class ImportCommand extends BaseCommand {
super(plugin); super(plugin);
this.name = "Import World"; this.name = "Import World";
this.description = "Imports a new world of the specified type"; this.description = "Imports a new world of the specified type";
this.usage = "/mvimport" + ChatColor.GREEN + " {NAME} {TYPE}"; this.usage = "/mvimport" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + "[GENERATOR[:ID]]";
this.minArgs = 2; this.minArgs = 2;
this.maxArgs = 2; this.maxArgs = 3;
this.identifiers.add("mvimport"); this.identifiers.add("mvimport");
this.permission = "multiverse.world.import"; this.permission = "multiverse.world.import";
this.requiresOp = true; this.requiresOp = true;
@ -30,11 +31,17 @@ public class ImportCommand extends BaseCommand {
return; return;
} }
String generator = null;
if(args.length == 3) {
generator = args[2];
}
String env = args[1]; String env = args[1];
Environment environment = this.plugin.getEnvFromString(env);
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...");
this.plugin.addWorld(worldName, env, ""); this.plugin.addWorld(worldName, environment, null, generator);
sender.sendMessage(ChatColor.GREEN + "Complete!"); sender.sendMessage(ChatColor.GREEN + "Complete!");
return; return;
} else if(env == null) { } else if(env == null) {

View File

@ -54,7 +54,7 @@ public class InfoCommand extends BaseCommand {
aPage[1] = "World Scale: " + world.scaling; aPage[1] = "World Scale: " + world.scaling;
// PVP: 1 // PVP: 1
aPage[2] = "PVP: " + world.pvp; aPage[2] = "PVP: " + world.getPvp();
// This feature is not mission critical and I am spending too much time on it... // This feature is not mission critical and I am spending too much time on it...
// Stopping work on it for now --FF 20110623 // Stopping work on it for now --FF 20110623

View File

@ -38,11 +38,8 @@ public class ListCommand extends BaseCommand {
} }
ChatColor color = ChatColor.GOLD; ChatColor color = ChatColor.GOLD;
Environment env = this.plugin.getEnvFromString(world.environment); Environment env = world.getEnvironment();
if(this.plugin.getEnvFromString(world.environment) == null) { if (env == Environment.NETHER) {
color = ChatColor.GOLD;
}
else if (env == Environment.NETHER) {
color = ChatColor.RED; color = ChatColor.RED;
} else if (env == Environment.NORMAL) { } else if (env == Environment.NORMAL) {
color = ChatColor.GREEN; color = ChatColor.GREEN;
@ -50,7 +47,7 @@ public class ListCommand extends BaseCommand {
color = ChatColor.AQUA; color = ChatColor.AQUA;
} }
output += ChatColor.WHITE + world.name + " - " + color + world.environment + " \n"; output += ChatColor.WHITE + world.name + " - " + color + world.getEnvironment() + " \n";
} }
String[] response = output.split("\n"); String[] response = output.split("\n");

View File

@ -1,16 +1,30 @@
package com.onarandombox.MultiverseCore.command.commands; package com.onarandombox.MultiverseCore.command.commands;
import java.lang.reflect.Method;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.config.Configuration;
import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.command.BaseCommand; import com.onarandombox.MultiverseCore.command.BaseCommand;
enum Action{Set, Add, Remove} enum Action {
Set, Add, Remove
}
// This will contain all the properties that support the ADD/REMOVE
// Anything not in here will only support the SET action
enum AddProperties {animallist,monsterlist,blockblacklist,playerwhitelist,playerblacklist,editwhitelist,editblacklist,worldblacklist}
enum SetProperties {alias,animals,monsters,pvp,scaling}
public class ModifyCommand extends BaseCommand { public class ModifyCommand extends BaseCommand {
private Configuration config;
public ModifyCommand(MultiverseCore plugin) { public ModifyCommand(MultiverseCore plugin) {
super(plugin); super(plugin);
this.name = "Modify a World"; this.name = "Modify a World";
@ -21,12 +35,13 @@ public class ModifyCommand extends BaseCommand {
this.identifiers.add("mvmodify"); this.identifiers.add("mvmodify");
this.permission = "multiverse.world.modify"; this.permission = "multiverse.world.modify";
this.requiresOp = true; this.requiresOp = true;
this.config = plugin.configWorlds;
} }
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
// We NEED a world from the command line // We NEED a world from the command line
if(args.length == 3 && !(sender instanceof Player)){ if (args.length == 3 && !(sender instanceof Player)) {
sender.sendMessage("From the command line, WORLD is required."); sender.sendMessage("From the command line, WORLD is required.");
sender.sendMessage("Nothing changed."); sender.sendMessage("Nothing changed.");
return; return;
@ -37,24 +52,76 @@ public class ModifyCommand extends BaseCommand {
String value; String value;
String property; String property;
Player p; Player p;
if(args.length == 3) { if (args.length == 3) {
p = (Player) sender; p = (Player) sender;
world = plugin.getMVWorld(p.getWorld().getName()); world = this.plugin.getMVWorld(p.getWorld().getName());
action = getActionEnum(args[0]);
value = args[1];
property = args[2];
} else { } else {
world = this.plugin.getMVWorld(args[0]);
action = getActionEnum(args[1]);
value = args[2];
property = args[3];
} }
if (world == null) {
sender.sendMessage("That world does not exist!");
return;
}
if (action == null) {
sender.sendMessage("That wasn't a valid action. Valid actions are:");
sender.sendMessage("SET, ADD or REMOVE");
return;
}
if (!this.validateAction(action, property)) {
sender.sendMessage("Sorry, you can't use " + action + " with " + property);
sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!");
return;
}
if(action == Action.Set) {
if(world.setVariable(property, value)) {
sender.sendMessage("Property " + property + " was set to " + value);
} else {
sender.sendMessage("There was an error setting " + property);
}
return;
}
}
private boolean validateAction(Action action, String property) {
if (action == Action.Set) {
try {
SetProperties.valueOf(property);
return true;
} catch (IllegalArgumentException e) {
return false;
}
} else {
try {
AddProperties.valueOf(property);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
} }
private Action getActionEnum(String action) { private Action getActionEnum(String action) {
if(action.equalsIgnoreCase("set")) { if (action.equalsIgnoreCase("set")) {
return Action.Set; return Action.Set;
} }
if(action.equalsIgnoreCase("add") || action.equalsIgnoreCase("+")) { if (action.equalsIgnoreCase("add") || action.equalsIgnoreCase("+")) {
return Action.Add; return Action.Add;
} }
if(action.equalsIgnoreCase("remove") || action.equalsIgnoreCase("-")) { if (action.equalsIgnoreCase("remove") || action.equalsIgnoreCase("-")) {
return Action.Remove; return Action.Remove;
} }
return null; return null;

View File

@ -59,11 +59,8 @@ public class WhoCommand extends BaseCommand {
} }
ChatColor color = ChatColor.GOLD; ChatColor color = ChatColor.GOLD;
Environment env = this.plugin.getEnvFromString(world.environment); Environment env = world.getEnvironment();
if(this.plugin.getEnvFromString(world.environment) == null) { if (env == Environment.NETHER) {
color = ChatColor.GOLD;
}
else if (env == Environment.NETHER) {
color = ChatColor.RED; color = ChatColor.RED;
} else if (env == Environment.NORMAL) { } else if (env == Environment.NORMAL) {
color = ChatColor.GREEN; color = ChatColor.GREEN;