From 19da2307238bf8580515e5eb6b545033fd2693f5 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 26 Jun 2011 08:55:24 -0600 Subject: [PATCH] More work on mvmodify; Better integration with Custom gens --- .../onarandombox/MultiverseCore/MVWorld.java | 202 ++++++++++++++++-- .../MultiverseCore/MultiverseCore.java | 109 ++++------ .../command/commands/CreateCommand.java | 46 ++-- .../command/commands/EnvironmentCommand.java | 6 - .../command/commands/ImportCommand.java | 13 +- .../command/commands/InfoCommand.java | 2 +- .../command/commands/ListCommand.java | 9 +- .../command/commands/ModifyCommand.java | 87 +++++++- .../command/commands/WhoCommand.java | 7 +- 9 files changed, 346 insertions(+), 135 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVWorld.java b/src/com/onarandombox/MultiverseCore/MVWorld.java index 0399bd5d..b7bca350 100644 --- a/src/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/com/onarandombox/MultiverseCore/MVWorld.java @@ -15,8 +15,8 @@ public class MVWorld { private Configuration config; // Hold the Configuration File. public World world; // The World Instance. - public String environment; // Hold the Environment type EG Environment.NETHER / Environment.NORMAL - public Long seed; + private Environment environment; // Hold the Environment type EG Environment.NETHER / Environment.NORMAL + private Long seed; 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. @@ -27,8 +27,8 @@ public class MVWorld { public Boolean monsters; // Does this World allow Monsters to Spawn? public List monsterList = new ArrayList(); // 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 blockBlacklist; // Contain a list of Blocks which we won't allow on this World. public List playerWhitelist; // Contain a list of Players/Groups which can join this World. public List playerBlacklist; // Contain a list of Players/Groups which cannot join this World. @@ -37,24 +37,28 @@ public class MVWorld { public List 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; - 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.plugin = instance; this.world = world; this.name = world.getName(); - this.environment = env; + this.generator = world.getGenerator(); + this.generatorString = generatorString; this.seed = seed; 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); - if(this.scaling <= 0) { + 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; @@ -70,23 +74,22 @@ public class MVWorld { 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", env); - if(seed != null) { + config.setProperty("worlds." + this.name + ".environment", world.getEnvironment()); + config.setProperty("worlds." + this.name + ".generatorString",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()).size() == 0) { -// addSampleData(); -// } + // if (config.getIntList("worlds." + name + ".blockBlacklist", new ArrayList()).size() == 0) { + // addSampleData(); + // } } - + private void getMobExceptions() { List temp; temp = this.config.getStringList("worlds." + this.name + ".animals.exceptions", this.animalList); @@ -109,16 +112,16 @@ public class MVWorld { private void setRealMobBehaviors() { boolean animals = true; boolean monsters = true; - if(!this.animals && this.animalList.isEmpty()) { + if (!this.animals && this.animalList.isEmpty()) { animals = false; } - if(!this.monsters && this.monsterList.isEmpty()) { + if (!this.monsters && this.monsterList.isEmpty()) { monsters = false; } this.world.setSpawnFlags(monsters, animals); } - + private void initLists() { this.blockBlacklist = new ArrayList(); this.playerWhitelist = new ArrayList(); @@ -160,4 +163,161 @@ public class MVWorld { this.config.setProperty("worlds." + this.name + ".worldBlacklist", this.worldBlacklist); 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 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 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 getBlockBlacklist() { + return this.blockBlacklist; + } + + public List getPlayerWhitelist() { + return this.playerWhitelist; + } + + public List getPlayerBlacklist() { + return this.playerBlacklist; + } + + public List getEditWhitelist() { + return this.editWhitelist; + } + + public List 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(); + } } diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index cef396a9..78d8bc5f 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -97,9 +97,6 @@ public class MultiverseCore extends JavaPlugin { // HashMap to contain all the Worlds which this Plugin will manage. private HashMap worlds = new HashMap(); - // HashMap to contain all custom generators. Plugins will have to register! - private HashMap worldGenerators = new HashMap(); - // HashMap to contain information relating to the Players. public HashMap playerSessions = new HashMap(); @@ -333,20 +330,13 @@ public class MultiverseCore extends JavaPlugin { 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. - if (filter == null && isStockWorldType) { - addWorld(worldKey, environment, seedString); - // Increment the world 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); - } + addWorld(worldKey, getEnvFromString(environment), seedString, generator + ":" + generatorID); + + // Increment the world count + count++; } } @@ -367,7 +357,7 @@ public class MultiverseCore extends JavaPlugin { World world = this.getServer().getWorlds().get(0); if (!this.worlds.containsKey(world.getName())) { log.info("Loading World & Settings - '" + world.getName() + "' - " + world.getEnvironment()); - addWorld(world.getName(), "NORMAL", ""); + addWorld(world.getName(), Environment.NORMAL, null, null); additonalWorldsLoaded++; } @@ -375,7 +365,7 @@ public class MultiverseCore extends JavaPlugin { World world_nether = this.getServer().getWorld(world.getName() + "_nether"); if (world_nether != null && !this.worlds.containsKey(world_nether.getName())) { log.info("Loading World & Settings - '" + world.getName() + "' - " + world_nether.getEnvironment()); - addWorld(world_nether.getName(), "NORMAL", ""); + addWorld(world_nether.getName(), Environment.NETHER, null, null); additonalWorldsLoaded++; } @@ -400,7 +390,7 @@ public class MultiverseCore extends JavaPlugin { * @param name World Name * @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; if (seedString.length() > 0) { @@ -411,43 +401,53 @@ public class MultiverseCore extends JavaPlugin { } } - Environment env = getEnvFromString(envString); - ChunkGenerator customGenerator = getChunkGenFromEnv(envString); - if (env == null) { - env = Environment.NORMAL; - // If the env was null, ie. not a built in one. - // AND the customGenerator is null, then someone - // screwed up... return false! - if (customGenerator == null) { - return false; - } + String generatorID = null; + String generatorName = null; + if (generator != null) { + String[] split = generator.split(":", 2); + String id = (split.length > 1) ? split[1] : null; + generatorName = split[0]; + generatorID = id; } + ChunkGenerator customGenerator = getChunkGenerator(generatorName, generatorID, name); + World world = null; if (seed != null) { if (customGenerator != null) { - World 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 + "' - " + envString + " with seed: " + seed); + world = getServer().createWorld(name, env, seed, customGenerator); + log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed + " & Custom Generator: " + generator); } else { - World world = getServer().createWorld(name, env, seed); - this.worlds.put(name, new MVWorld(world, this.configWorlds, this, seed, envString)); // Place the World into the HashMap. + world = getServer().createWorld(name, env, seed); log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed); } } else { if (customGenerator != null) { - World 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 + "' - " + envString); + world = getServer().createWorld(name, env, customGenerator); + log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " & Custom Generator: " + generator); } else { - World world = getServer().createWorld(name, env); - this.worlds.put(name, new MVWorld(world, this.configWorlds, this, null, envString)); // Place the World into the HashMap. + world = getServer().createWorld(name, env); log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env); } } + this.worlds.put(name, new MVWorld(world, this.configWorlds, this, seed, generator)); 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 * @@ -654,31 +654,10 @@ public class MultiverseCore extends JavaPlugin { try { return Environment.valueOf(env); } 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 /** @@ -731,16 +710,12 @@ public class MultiverseCore extends JavaPlugin { } } - public Set getWorldGenerators() { - return this.worldGenerators.keySet(); - } - public Collection getMVWorlds() { return this.worlds.values(); } - + public MVWorld getMVWorld(String name) { - if(this.worlds.containsKey(name)) { + if (this.worlds.containsKey(name)) { return this.worlds.get(name); } return null; diff --git a/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java index 93c1d9e0..5ca12a7c 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/CreateCommand.java @@ -3,6 +3,7 @@ package com.onarandombox.MultiverseCore.command.commands; import java.io.File; import org.bukkit.ChatColor; +import org.bukkit.World.Environment; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; @@ -14,9 +15,9 @@ public class CreateCommand extends BaseCommand { super(plugin); this.name = "Create World"; 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.maxArgs = 3; + this.maxArgs = 4; this.identifiers.add("mvcreate"); this.permission = "multiverse.world.create"; this.requiresOp = true; @@ -25,33 +26,46 @@ public class CreateCommand extends BaseCommand { @Override public void execute(CommandSender sender, String[] args) { - // TODO: Permissions, check - - int numOfParams = args.length; - - boolean hasSeed = numOfParams == 3; String worldName = args[0]; String env = args[1]; - String seed = ""; - if (hasSeed) { - seed = args[2]; - } + String seed = this.getFlag("-s", args); + String generator = this.getFlag("-g", args); 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 + "If you are confident it is a world you can import with /mvimport"); 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!"); } else { 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; } + + /** + * 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; + } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java index 7740174a..e5cc903f 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/EnvironmentCommand.java @@ -30,12 +30,6 @@ public class EnvironmentCommand extends BaseCommand{ sender.sendMessage(ChatColor.GREEN + "NORMAL"); sender.sendMessage(ChatColor.RED + "NETHER"); 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); - } } } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java index 3ba85ca5..04e56108 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ImportCommand.java @@ -3,6 +3,7 @@ package com.onarandombox.MultiverseCore.command.commands; import java.io.File; import org.bukkit.ChatColor; +import org.bukkit.World.Environment; import org.bukkit.command.CommandSender; import com.onarandombox.MultiverseCore.MultiverseCore; @@ -14,9 +15,9 @@ public class ImportCommand extends BaseCommand { super(plugin); this.name = "Import World"; 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.maxArgs = 2; + this.maxArgs = 3; this.identifiers.add("mvimport"); this.permission = "multiverse.world.import"; this.requiresOp = true; @@ -30,11 +31,17 @@ public class ImportCommand extends BaseCommand { return; } + String generator = null; + if(args.length == 3) { + generator = args[2]; + } + String env = args[1]; + Environment environment = this.plugin.getEnvFromString(env); if (new File(worldName).exists() && env != null) { sender.sendMessage(ChatColor.AQUA + "Starting world import..."); - this.plugin.addWorld(worldName, env, ""); + this.plugin.addWorld(worldName, environment, null, generator); sender.sendMessage(ChatColor.GREEN + "Complete!"); return; } else if(env == null) { diff --git a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java index 5d2d57c4..7df0a501 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/InfoCommand.java @@ -54,7 +54,7 @@ public class InfoCommand extends BaseCommand { aPage[1] = "World Scale: " + world.scaling; // 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... // Stopping work on it for now --FF 20110623 diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java index 5d857e6b..ee105aed 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ListCommand.java @@ -38,11 +38,8 @@ public class ListCommand extends BaseCommand { } ChatColor color = ChatColor.GOLD; - Environment env = this.plugin.getEnvFromString(world.environment); - if(this.plugin.getEnvFromString(world.environment) == null) { - color = ChatColor.GOLD; - } - else if (env == Environment.NETHER) { + Environment env = world.getEnvironment(); + if (env == Environment.NETHER) { color = ChatColor.RED; } else if (env == Environment.NORMAL) { color = ChatColor.GREEN; @@ -50,7 +47,7 @@ public class ListCommand extends BaseCommand { 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"); diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java index eecdff55..9872a870 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java @@ -1,15 +1,29 @@ package com.onarandombox.MultiverseCore.command.commands; +import java.lang.reflect.Method; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.util.config.Configuration; import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; 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 { + + private Configuration config; public ModifyCommand(MultiverseCore plugin) { super(plugin); @@ -21,12 +35,13 @@ public class ModifyCommand extends BaseCommand { this.identifiers.add("mvmodify"); this.permission = "multiverse.world.modify"; this.requiresOp = true; + this.config = plugin.configWorlds; } - + @Override public void execute(CommandSender sender, String[] args) { // 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("Nothing changed."); return; @@ -37,27 +52,79 @@ public class ModifyCommand extends BaseCommand { String value; String property; Player p; - if(args.length == 3) { + if (args.length == 3) { 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 { - + 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) { - if(action.equalsIgnoreCase("set")) { + if (action.equalsIgnoreCase("set")) { return Action.Set; } - if(action.equalsIgnoreCase("add") || action.equalsIgnoreCase("+")) { + if (action.equalsIgnoreCase("add") || action.equalsIgnoreCase("+")) { return Action.Add; } - if(action.equalsIgnoreCase("remove") || action.equalsIgnoreCase("-")) { + if (action.equalsIgnoreCase("remove") || action.equalsIgnoreCase("-")) { return Action.Remove; } return null; } - + } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java index 090f55fe..f5a3966f 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/WhoCommand.java @@ -59,11 +59,8 @@ public class WhoCommand extends BaseCommand { } ChatColor color = ChatColor.GOLD; - Environment env = this.plugin.getEnvFromString(world.environment); - if(this.plugin.getEnvFromString(world.environment) == null) { - color = ChatColor.GOLD; - } - else if (env == Environment.NETHER) { + Environment env = world.getEnvironment(); + if (env == Environment.NETHER) { color = ChatColor.RED; } else if (env == Environment.NORMAL) { color = ChatColor.GREEN;