More MVWorld Refactors

although the modify command got a lot messier...
This commit is contained in:
Eric Stokes 2011-06-26 11:57:45 -06:00
parent 04c6024616
commit 28276daa81
2 changed files with 54 additions and 14 deletions

View File

@ -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;

View File

@ -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) {