MVModify is working now. Yay.

Still need to purge animals/mobs when the var is set.
This commit is contained in:
Eric Stokes 2011-06-26 12:27:03 -06:00
parent 28276daa81
commit f33e93e077
3 changed files with 81 additions and 53 deletions

View File

@ -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());
}

View File

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

View File

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