mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-09-16 09:37:37 +02:00
MVModify is working now. Yay.
Still need to purge animals/mobs when the var is set.
This commit is contained in:
parent
28276daa81
commit
f33e93e077
@ -158,11 +158,27 @@ public class MVWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean clearVariable(String property) {
|
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) {
|
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)) {
|
if (this.masterList.keySet().contains(list)) {
|
||||||
|
|
||||||
this.masterList.get(list).add(value);
|
this.masterList.get(list).add(value);
|
||||||
@ -172,7 +188,15 @@ public class MVWorld {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeFromList(String list, String value) {
|
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)) {
|
if (this.masterList.keySet().contains(list)) {
|
||||||
|
|
||||||
this.masterList.get(list).remove(value);
|
this.masterList.get(list).remove(value);
|
||||||
@ -183,7 +207,7 @@ public class MVWorld {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addToList(String list, Integer value) {
|
private boolean addToList(String list, Integer value) {
|
||||||
if (list.equalsIgnoreCase("blockblacklist")) {
|
if (list.equalsIgnoreCase("blockblacklist")) {
|
||||||
this.blockBlacklist.add(value);
|
this.blockBlacklist.add(value);
|
||||||
this.config.setProperty("worlds." + this.name + ".blockblacklist", this.blockBlacklist);
|
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")) {
|
if (list.equalsIgnoreCase("blockblacklist")) {
|
||||||
this.blockBlacklist.remove(value);
|
this.blockBlacklist.remove(value);
|
||||||
this.config.setProperty("worlds." + this.name + ".blockblacklist", this.blockBlacklist);
|
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")) {
|
if (name.equalsIgnoreCase("pvp")) {
|
||||||
this.setPvp(value);
|
this.setPvp(value);
|
||||||
} else if (name.equalsIgnoreCase("animals")) {
|
} else if (name.equalsIgnoreCase("animals")) {
|
||||||
@ -214,19 +238,36 @@ public class MVWorld {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setVariable(String name, double value) {
|
private boolean setVariable(String name, double value) {
|
||||||
if (name.equalsIgnoreCase("scaling")) {
|
if (name.equalsIgnoreCase("scaling")) {
|
||||||
this.setScaling(value);
|
this.setScaling(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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) {
|
public boolean setVariable(String name, String value) {
|
||||||
if (name.equalsIgnoreCase("alias")) {
|
if (name.equalsIgnoreCase("alias")) {
|
||||||
this.alias = value;
|
this.alias = value;
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -272,6 +313,9 @@ public class MVWorld {
|
|||||||
// If there are ANY exceptions, there will be something spawning, so turn them on
|
// If there are ANY exceptions, there will be something spawning, so turn them on
|
||||||
if (this.getAnimalList().isEmpty()) {
|
if (this.getAnimalList().isEmpty()) {
|
||||||
this.world.setSpawnFlags(this.world.getAllowMonsters(), animals);
|
this.world.setSpawnFlags(this.world.getAllowMonsters(), animals);
|
||||||
|
if(!animals) {
|
||||||
|
// TODO: Purge
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.world.setSpawnFlags(this.world.getAllowMonsters(), true);
|
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 there are ANY exceptions, there will be something spawning, so turn them on
|
||||||
if (this.getAnimalList().isEmpty()) {
|
if (this.getAnimalList().isEmpty()) {
|
||||||
this.world.setSpawnFlags(monsters, this.world.getAllowAnimals());
|
this.world.setSpawnFlags(monsters, this.world.getAllowAnimals());
|
||||||
|
if(!monsters) {
|
||||||
|
// TODO: Purge
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.world.setSpawnFlags(true, this.world.getAllowAnimals());
|
this.world.setSpawnFlags(true, this.world.getAllowAnimals());
|
||||||
}
|
}
|
||||||
|
@ -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 environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
|
||||||
String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", "");
|
String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", "");
|
||||||
|
|
||||||
log(Level.INFO, "Loading World & Settings - '" + worldKey + "' - " + environment);
|
|
||||||
|
|
||||||
String generatorstring = this.configWorlds.getString("worlds." + worldKey + ".generator");
|
String generatorstring = this.configWorlds.getString("worlds." + worldKey + ".generator");
|
||||||
|
|
||||||
addWorld(worldKey, getEnvFromString(environment), seedString, generatorstring);
|
addWorld(worldKey, getEnvFromString(environment), seedString, generatorstring);
|
||||||
@ -354,7 +352,6 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
// Load the default world:
|
// Load the default world:
|
||||||
World world = this.getServer().getWorlds().get(0);
|
World world = this.getServer().getWorlds().get(0);
|
||||||
if (!this.worlds.containsKey(world.getName())) {
|
if (!this.worlds.containsKey(world.getName())) {
|
||||||
log.info("Loading World & Settings - '" + world.getName() + "' - " + world.getEnvironment());
|
|
||||||
addWorld(world.getName(), Environment.NORMAL, null, null);
|
addWorld(world.getName(), Environment.NORMAL, null, null);
|
||||||
additonalWorldsLoaded++;
|
additonalWorldsLoaded++;
|
||||||
}
|
}
|
||||||
@ -362,7 +359,6 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
// This next one could be null if they have it disabled in server.props
|
// This next one could be null if they have it disabled in server.props
|
||||||
World world_nether = this.getServer().getWorld(world.getName() + "_nether");
|
World world_nether = this.getServer().getWorld(world.getName() + "_nether");
|
||||||
if (world_nether != null && !this.worlds.containsKey(world_nether.getName())) {
|
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);
|
addWorld(world_nether.getName(), Environment.NETHER, null, null);
|
||||||
additonalWorldsLoaded++;
|
additonalWorldsLoaded++;
|
||||||
}
|
}
|
||||||
|
@ -12,24 +12,28 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
|||||||
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
||||||
|
|
||||||
enum Action {
|
enum Action {
|
||||||
Set, Add, Remove
|
Set, Add, Remove, Clear
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will contain all the properties that support the ADD/REMOVE
|
// This will contain all the properties that support the ADD/REMOVE
|
||||||
// Anything not in here will only support the SET action
|
// 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 {
|
public class ModifyCommand extends BaseCommand {
|
||||||
|
|
||||||
private Configuration config;
|
private Configuration config;
|
||||||
|
|
||||||
public ModifyCommand(MultiverseCore plugin) {
|
public ModifyCommand(MultiverseCore plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
this.name = "Modify a World";
|
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.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.minArgs = 3;
|
||||||
this.maxArgs = 4;
|
this.maxArgs = 4;
|
||||||
this.identifiers.add("mvmodify");
|
this.identifiers.add("mvmodify");
|
||||||
@ -56,14 +60,15 @@ public class ModifyCommand extends BaseCommand {
|
|||||||
p = (Player) sender;
|
p = (Player) sender;
|
||||||
world = this.plugin.getMVWorld(p.getWorld().getName());
|
world = this.plugin.getMVWorld(p.getWorld().getName());
|
||||||
action = getActionEnum(args[0]);
|
action = getActionEnum(args[0]);
|
||||||
value = args[1];
|
value = args[2];
|
||||||
property = args[2];
|
property = args[1];
|
||||||
} else {
|
} else {
|
||||||
world = this.plugin.getMVWorld(args[0]);
|
world = this.plugin.getMVWorld(args[0]);
|
||||||
action = getActionEnum(args[1]);
|
action = getActionEnum(args[1]);
|
||||||
value = args[2];
|
value = args[3];
|
||||||
property = args[3];
|
property = args[2];
|
||||||
}
|
}
|
||||||
|
System.out.print(args[0]);
|
||||||
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
sender.sendMessage("That world does not exist!");
|
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!");
|
sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: Refactor this garbage. But I have deadlines to meet...
|
if (action == Action.Set) {
|
||||||
if(action == Action.Set) {
|
if (world.setVariable(property, value)) {
|
||||||
if(world.setVariable(property, value)) {
|
|
||||||
sender.sendMessage("Property " + property + " was set to " + value);
|
sender.sendMessage("Property " + property + " was set to " + value);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("There was an error setting " + property);
|
sender.sendMessage("There was an error setting " + property);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if(action == Action.Add) {
|
} else if (action == Action.Add) {
|
||||||
if(AddProperties.valueOf(property) == AddProperties.blockblacklist) {
|
if (world.removeFromList(property, value)) {
|
||||||
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);
|
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 {
|
} else {
|
||||||
if(world.removeFromList(property, value)){
|
sender.sendMessage(value + " could not be added to " + property);
|
||||||
sender.sendMessage(value + " was removed from " + property);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(value + " could not be removed from " + 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) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user