From f33e93e07767b663db0fbef078578baac1c5f610 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 26 Jun 2011 12:27:03 -0600 Subject: [PATCH] MVModify is working now. Yay. Still need to purge animals/mobs when the var is set. --- .../onarandombox/MultiverseCore/MVWorld.java | 61 ++++++++++++++-- .../MultiverseCore/MultiverseCore.java | 4 -- .../command/commands/ModifyCommand.java | 69 ++++++++----------- 3 files changed, 81 insertions(+), 53 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVWorld.java b/src/com/onarandombox/MultiverseCore/MVWorld.java index 43ce75a5..f7e97052 100644 --- a/src/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/com/onarandombox/MultiverseCore/MVWorld.java @@ -158,11 +158,27 @@ public class MVWorld { } public boolean clearVariable(String property) { - return false; + if(property.equalsIgnoreCase("blockblacklist")) { + this.blockBlacklist.clear(); + } + else if (this.masterList.keySet().contains(property)) { + this.masterList.get(property).clear(); + } else { + return false; + } + this.config.setProperty("worlds." + this.name + "." + property.toLowerCase(), this.blockBlacklist); + this.config.save(); + return true; } - public boolean addToList(String list, String value) { + if(list.equalsIgnoreCase("blockblacklist")) { + try{ + int intVal = Integer.parseInt(value); + return addToList(list, intVal); + } catch (Exception e) { + } + } if (this.masterList.keySet().contains(list)) { this.masterList.get(list).add(value); @@ -172,7 +188,15 @@ public class MVWorld { } return false; } + public boolean removeFromList(String list, String value) { + if(list.equalsIgnoreCase("blockblacklist")) { + try{ + int intVal = Integer.parseInt(value); + return removeFromList(list, intVal); + } catch (Exception e) { + } + } if (this.masterList.keySet().contains(list)) { this.masterList.get(list).remove(value); @@ -183,7 +207,7 @@ public class MVWorld { return false; } - public boolean addToList(String list, Integer value) { + private boolean addToList(String list, Integer value) { if (list.equalsIgnoreCase("blockblacklist")) { this.blockBlacklist.add(value); this.config.setProperty("worlds." + this.name + ".blockblacklist", this.blockBlacklist); @@ -192,7 +216,7 @@ public class MVWorld { } - public boolean removeFromList(String list, Integer value) { + private boolean removeFromList(String list, Integer value) { if (list.equalsIgnoreCase("blockblacklist")) { this.blockBlacklist.remove(value); this.config.setProperty("worlds." + this.name + ".blockblacklist", this.blockBlacklist); @@ -201,7 +225,7 @@ public class MVWorld { } - public boolean setVariable(String name, boolean value) { + private boolean setVariable(String name, boolean value) { if (name.equalsIgnoreCase("pvp")) { this.setPvp(value); } else if (name.equalsIgnoreCase("animals")) { @@ -214,19 +238,36 @@ public class MVWorld { return true; } - public boolean setVariable(String name, double value) { + private boolean setVariable(String name, double value) { if (name.equalsIgnoreCase("scaling")) { this.setScaling(value); return true; } + return false; } - + /** + * This is the one people have access to. It'll handle the rest. + * @param name + * @param value + * @return + */ public boolean setVariable(String name, String value) { if (name.equalsIgnoreCase("alias")) { this.alias = value; return true; } + try { + boolean boolValue = Boolean.parseBoolean(value); + return this.setVariable(name, boolValue); + } catch (Exception e) { + } + + try { + double doubValue = Double.parseDouble(value); + return this.setVariable(name, doubValue); + } catch (Exception e) { + } return false; } @@ -272,6 +313,9 @@ public class MVWorld { // 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); + if(!animals) { + // TODO: Purge + } } else { this.world.setSpawnFlags(this.world.getAllowMonsters(), true); } @@ -293,6 +337,9 @@ public class MVWorld { // 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()); + if(!monsters) { + // TODO: Purge + } } else { this.world.setSpawnFlags(true, this.world.getAllowAnimals()); } diff --git a/src/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/com/onarandombox/MultiverseCore/MultiverseCore.java index 6710ae72..7331dc05 100644 --- a/src/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -327,8 +327,6 @@ public class MultiverseCore extends JavaPlugin { String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String. String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", ""); - log(Level.INFO, "Loading World & Settings - '" + worldKey + "' - " + environment); - String generatorstring = this.configWorlds.getString("worlds." + worldKey + ".generator"); addWorld(worldKey, getEnvFromString(environment), seedString, generatorstring); @@ -354,7 +352,6 @@ public class MultiverseCore extends JavaPlugin { // Load the default world: 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(), Environment.NORMAL, null, null); additonalWorldsLoaded++; } @@ -362,7 +359,6 @@ public class MultiverseCore extends JavaPlugin { // This next one could be null if they have it disabled in server.props 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(), Environment.NETHER, null, null); additonalWorldsLoaded++; } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java index 98ea613f..3b321949 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java @@ -12,24 +12,28 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; enum Action { - Set, Add, Remove + Set, Add, Remove, Clear } // 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 AddProperties { + animallist, monsterlist, blockblacklist, playerwhitelist, playerblacklist, editwhitelist, editblacklist, worldblacklist +} -enum SetProperties {alias,animals,monsters,pvp,scaling} +enum SetProperties { + alias, animals, monsters, pvp, scaling +} public class ModifyCommand extends BaseCommand { private Configuration config; - + public ModifyCommand(MultiverseCore plugin) { super(plugin); this.name = "Modify a World"; this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used"; - this.usage = "/mvmodify" + ChatColor.GOLD + " [WORLD] " + ChatColor.GREEN + "{SET|ADD|REMOVE} {VALUE} {PROPERTY}"; + this.usage = "/mvmodify" + ChatColor.GOLD + " [WORLD] " + ChatColor.GREEN + "{SET|ADD|REMOVE|CLEAR} {PROPERTY} {VALUE}"; this.minArgs = 3; this.maxArgs = 4; this.identifiers.add("mvmodify"); @@ -56,14 +60,15 @@ public class ModifyCommand extends BaseCommand { p = (Player) sender; world = this.plugin.getMVWorld(p.getWorld().getName()); action = getActionEnum(args[0]); - value = args[1]; - property = args[2]; + value = args[2]; + property = args[1]; } else { world = this.plugin.getMVWorld(args[0]); action = getActionEnum(args[1]); - value = args[2]; - property = args[3]; + value = args[3]; + property = args[2]; } + System.out.print(args[0]); if (world == null) { sender.sendMessage("That world does not exist!"); @@ -81,47 +86,27 @@ public class ModifyCommand extends BaseCommand { sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!"); return; } - // TODO: Refactor this garbage. But I have deadlines to meet... - if(action == Action.Set) { - if(world.setVariable(property, value)) { + 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; - } else if(action == Action.Add) { - if(AddProperties.valueOf(property) == AddProperties.blockblacklist) { - try { - world.addToList("blockblacklist", Integer.parseInt(property)); - } catch(Exception e) { - sender.sendMessage("There was an error setting " + property); - sender.sendMessage("You must pass an integer"); - return; - } - } else { - world.addToList(property, value); + } else if (action == Action.Add) { + if (world.removeFromList(property, value)) { sender.sendMessage(value + " was added to " + property); - } - } else if(action == Action.Remove) { - if(AddProperties.valueOf(property) == AddProperties.blockblacklist) { - try { - if(world.removeFromList("blockblacklist", Integer.parseInt(property))) { - sender.sendMessage(value + " was removed from " + property); - } else { - sender.sendMessage(value + " could not be removed from " + property); - } - } catch(Exception e) { - sender.sendMessage("There was an error setting " + property); - sender.sendMessage("You must pass an integer"); - return; - } } else { - if(world.removeFromList(property, value)){ - sender.sendMessage(value + " was removed from " + property); - } else { - sender.sendMessage(value + " could not be removed from " + property); - } + sender.sendMessage(value + " could not be added to " + property); } + } else if (action == Action.Remove) { + if (world.removeFromList(property, value)) { + sender.sendMessage(value + " was removed from " + property); + } else { + sender.sendMessage(value + " could not be removed from " + property); + } + } else if(action == Action.Clear) { + } }