From 28276daa8106a1bea22dadd06ca7ee44e9156c11 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 26 Jun 2011 11:57:45 -0600 Subject: [PATCH] More MVWorld Refactors although the modify command got a lot messier... --- .../onarandombox/MultiverseCore/MVWorld.java | 30 ++++++++++----- .../command/commands/ModifyCommand.java | 38 +++++++++++++++++-- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/MVWorld.java b/src/com/onarandombox/MultiverseCore/MVWorld.java index b7078283..43ce75a5 100644 --- a/src/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/com/onarandombox/MultiverseCore/MVWorld.java @@ -161,7 +161,7 @@ public class MVWorld { return false; } - // This has been checked, see 3 lines below. + public boolean addToList(String list, String value) { if (this.masterList.keySet().contains(list)) { @@ -172,6 +172,16 @@ public class MVWorld { } return false; } + public boolean removeFromList(String list, String value) { + if (this.masterList.keySet().contains(list)) { + + this.masterList.get(list).remove(value); + this.config.setProperty("worlds." + this.name + "." + list.toLowerCase(), this.blockBlacklist); + this.config.save(); + return true; + } + return false; + } public boolean addToList(String list, Integer value) { if (list.equalsIgnoreCase("blockblacklist")) { @@ -182,6 +192,15 @@ public class MVWorld { } + public boolean removeFromList(String list, Integer value) { + if (list.equalsIgnoreCase("blockblacklist")) { + this.blockBlacklist.remove(value); + this.config.setProperty("worlds." + this.name + ".blockblacklist", this.blockBlacklist); + } + return false; + + } + public boolean setVariable(String name, boolean value) { if (name.equalsIgnoreCase("pvp")) { this.setPvp(value); @@ -204,15 +223,6 @@ public class MVWorld { } public boolean setVariable(String name, String value) { - - // The Doubles - try { - double doubleValue = Double.parseDouble(value); - - } catch (Exception e) { - } - - // The Strings if (name.equalsIgnoreCase("alias")) { this.alias = value; return true; diff --git a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java index 9872a870..98ea613f 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/ModifyCommand.java @@ -81,7 +81,7 @@ 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)) { sender.sendMessage("Property " + property + " was set to " + value); @@ -89,10 +89,40 @@ public class ModifyCommand extends BaseCommand { 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); + 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); + } + } } - - - } private boolean validateAction(Action action, String property) {