mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 18:47:20 +01:00
Add the new style of saving/loading world properties.
All properties have been converted, but are not all implemented yet. I'm just committing because it's been several hours... o.O
This commit is contained in:
parent
6b95be4ca5
commit
c576d5a3a2
@ -8,7 +8,10 @@
|
|||||||
package com.onarandombox.MultiverseCore;
|
package com.onarandombox.MultiverseCore;
|
||||||
|
|
||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
|
import com.onarandombox.MultiverseCore.configuration.ConfigPropertyFactory;
|
||||||
|
import com.onarandombox.MultiverseCore.configuration.MVConfigProperty;
|
||||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||||
|
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||||
import com.onarandombox.MultiverseCore.utils.BlockSafety;
|
import com.onarandombox.MultiverseCore.utils.BlockSafety;
|
||||||
import com.onarandombox.MultiverseCore.utils.LocationManipulation;
|
import com.onarandombox.MultiverseCore.utils.LocationManipulation;
|
||||||
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
|
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
|
||||||
@ -57,6 +60,7 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
|
|
||||||
|
|
||||||
private Map<String, List<String>> masterList;
|
private Map<String, List<String>> masterList;
|
||||||
|
private Map<String, MVConfigProperty> propertyList;
|
||||||
|
|
||||||
private double scaling; // How stretched/compressed distances are
|
private double scaling; // How stretched/compressed distances are
|
||||||
private double price; // How much does it cost to enter this world
|
private double price; // How much does it cost to enter this world
|
||||||
@ -68,7 +72,7 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
private boolean canSave = false; // Prevents all the setters from constantly saving to the config when being called from the constructor.
|
private boolean canSave = false; // Prevents all the setters from constantly saving to the config when being called from the constructor.
|
||||||
private boolean allowWeather;
|
private boolean allowWeather;
|
||||||
private Location spawnLocation;
|
private Location spawnLocation;
|
||||||
private boolean isHidden = false;
|
//private boolean isHidden = false;
|
||||||
private boolean autoheal = true;
|
private boolean autoheal = true;
|
||||||
private boolean adjustSpawn = true;
|
private boolean adjustSpawn = true;
|
||||||
|
|
||||||
@ -98,31 +102,50 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
}
|
}
|
||||||
worldSection.set("environment", this.environment.toString());
|
worldSection.set("environment", this.environment.toString());
|
||||||
|
|
||||||
// Set local values that CAN be changed by the user
|
// Start NEW config awesomeness.
|
||||||
this.setAlias(worldSection.getString("alias.name", ""));
|
ConfigPropertyFactory fac = new ConfigPropertyFactory(this.worldSection);
|
||||||
this.setColor(worldSection.getString("alias.color", ChatColor.WHITE.toString()));
|
this.propertyList = new HashMap<String, MVConfigProperty>();
|
||||||
this.setPVPMode(worldSection.getBoolean("pvp", true));
|
this.propertyList.put("hidden", fac.getNewProperty("hidden", false));
|
||||||
this.setFakePVPMode(worldSection.getBoolean("fakepvp", false));
|
this.propertyList.put("alias", fac.getNewProperty("alias", "", "alias.name"));
|
||||||
this.setScaling(worldSection.getDouble("scale", this.getDefaultScale(this.environment)));
|
this.propertyList.put("color", fac.getNewProperty("color", EnglishChatColor.WHITE, "alias.color"));
|
||||||
this.setRespawnToWorld(worldSection.getString("respawnworld", ""));
|
this.propertyList.put("pvp", fac.getNewProperty("pvp", true));
|
||||||
this.setEnableWeather(worldSection.getBoolean("allowweather", true));
|
this.propertyList.put("fakepvp", fac.getNewProperty("fakepvp", false));
|
||||||
this.setDifficulty(worldSection.get("difficulty", "EASY"));
|
this.propertyList.put("scale", fac.getNewProperty("scale", this.getDefaultScale(this.environment)));
|
||||||
|
this.propertyList.put("respawn", fac.getNewProperty("respawn", "", "respawnworld"));
|
||||||
|
this.propertyList.put("weather", fac.getNewProperty("weather", true, "allowweather"));
|
||||||
|
this.propertyList.put("difficulty", fac.getNewProperty("difficulty", Difficulty.EASY));
|
||||||
|
this.propertyList.put("animals", fac.getNewProperty("animals", true, "animals.spawn"));
|
||||||
|
this.propertyList.put("monsters", fac.getNewProperty("monsters", true, "monsters.spawn"));
|
||||||
|
this.propertyList.put("currency", fac.getNewProperty("currency", -1, "entryfee.currency"));
|
||||||
|
this.propertyList.put("price", fac.getNewProperty("price", 0.0, "entryfee.price"));
|
||||||
|
this.propertyList.put("hunger", fac.getNewProperty("hunger", true));
|
||||||
|
this.propertyList.put("autoheal", fac.getNewProperty("autoheal", true));
|
||||||
|
this.propertyList.put("adjustspawn", fac.getNewProperty("adjustspawn", true));
|
||||||
|
this.propertyList.put("gamemode", fac.getNewProperty("gamemode", GameMode.SURVIVAL));
|
||||||
|
this.propertyList.put("memory", fac.getNewProperty("keepspawninmemory", true, "keepspawninmemory"));
|
||||||
|
this.propertyList.put("spawn", fac.getNewProperty("spawn", new Location(this.getCBWorld(), 0,0,0)));
|
||||||
|
|
||||||
this.setAllowAnimalSpawn(worldSection.getBoolean("animals.spawn", true));
|
// Set aliases
|
||||||
this.setAllowMonsterSpawn(worldSection.getBoolean("monsters.spawn", true));
|
this.propertyList.put("curr", this.propertyList.get("currency"));
|
||||||
this.setPrice(worldSection.getDouble("entryfee.amount", 0.0));
|
this.propertyList.put("scaling", this.propertyList.get("scale"));
|
||||||
this.setCurrency(worldSection.getInt("entryfee.currency", -1));
|
this.propertyList.put("aliascolor", this.propertyList.get("color"));
|
||||||
this.setHunger(worldSection.getBoolean("hunger", true));
|
this.propertyList.put("heal", this.propertyList.get("autoheal"));
|
||||||
this.setHidden(worldSection.getBoolean("hidden", false));
|
this.propertyList.put("storm", this.propertyList.get("weather"));
|
||||||
|
this.propertyList.put("spawnmemory", this.propertyList.get("memory"));
|
||||||
|
this.propertyList.put("mode", this.propertyList.get("gamemode"));
|
||||||
|
this.propertyList.put("diff", this.propertyList.get("difficulty"));
|
||||||
|
|
||||||
|
// Things I haven't converted yet.
|
||||||
this.getMobExceptions();
|
this.getMobExceptions();
|
||||||
|
|
||||||
this.setGameMode(worldSection.get("gamemode", GameMode.SURVIVAL.toString()));
|
|
||||||
|
|
||||||
this.setKeepSpawnInMemory(worldSection.getBoolean("keepspawninmemory", true));
|
|
||||||
|
|
||||||
this.getWorldBlacklist().addAll(worldSection.getList("worldblacklist", new ArrayList<String>()));
|
this.getWorldBlacklist().addAll(worldSection.getList("worldblacklist", new ArrayList<String>()));
|
||||||
|
|
||||||
|
// This method translates a MV1 style spawn stored in the config.
|
||||||
this.translateTempSpawn(worldSection);
|
this.translateTempSpawn(worldSection);
|
||||||
|
|
||||||
|
// This method takes a look at the given spawn and ensures its safe.
|
||||||
this.readSpawnFromConfig(this.getCBWorld());
|
this.readSpawnFromConfig(this.getCBWorld());
|
||||||
|
|
||||||
|
// Enable and do the save.
|
||||||
this.canSave = true;
|
this.canSave = true;
|
||||||
this.saveConfig();
|
this.saveConfig();
|
||||||
|
|
||||||
@ -137,6 +160,16 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean setWorldProperty(String name, String value) {
|
||||||
|
MVConfigProperty property = this.propertyList.get(name);
|
||||||
|
return property.parseValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWorldProperty(String name) {
|
||||||
|
MVConfigProperty property = this.propertyList.get(name);
|
||||||
|
return property.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private double getDefaultScale(Environment environment) {
|
private double getDefaultScale(Environment environment) {
|
||||||
if (environment == Environment.NETHER) {
|
if (environment == Environment.NETHER) {
|
||||||
return 8.0;
|
return 8.0;
|
||||||
@ -311,31 +344,6 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
this.plugin.getMVWorldManager().getWorldPurger().purgeWorld(null, this);
|
this.plugin.getMVWorldManager().getWorldPurger().purgeWorld(null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setVariable(String name, boolean value) {
|
|
||||||
if (name.equalsIgnoreCase("pvp")) {
|
|
||||||
this.setPVPMode(value);
|
|
||||||
} else if (name.equalsIgnoreCase("animals")) {
|
|
||||||
this.setAllowAnimalSpawn(value);
|
|
||||||
} else if (name.equalsIgnoreCase("monsters")) {
|
|
||||||
this.setAllowMonsterSpawn(value);
|
|
||||||
} else if (name.equalsIgnoreCase("memory") || name.equalsIgnoreCase("spawnmemory")) {
|
|
||||||
this.setKeepSpawnInMemory(value);
|
|
||||||
} else if ((name.equalsIgnoreCase("hunger")) || (name.equalsIgnoreCase("food"))) {
|
|
||||||
this.setHunger(value);
|
|
||||||
} else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) {
|
|
||||||
this.setEnableWeather(value);
|
|
||||||
} else if (name.equalsIgnoreCase("heal") || name.equalsIgnoreCase("autoheal")) {
|
|
||||||
this.setAutoHeal(value);
|
|
||||||
} else if (name.equalsIgnoreCase("adjustspawn")) {
|
|
||||||
this.setAdjustSpawn(value);
|
|
||||||
} else if (name.equalsIgnoreCase("hidden")) {
|
|
||||||
this.setHidden(value);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setKeepSpawnInMemory(boolean value) {
|
public void setKeepSpawnInMemory(boolean value) {
|
||||||
this.world.setKeepSpawnInMemory(value);
|
this.world.setKeepSpawnInMemory(value);
|
||||||
@ -344,59 +352,24 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Provide better feedback
|
||||||
@Override
|
@Override
|
||||||
public boolean setVariable(String name, String value) {
|
public boolean setVariable(String name, String value) throws PropertyDoesNotExistException {
|
||||||
if (name.equalsIgnoreCase("diff") || name.equalsIgnoreCase("difficulty")) {
|
if (this.propertyList.containsKey(name)) {
|
||||||
return this.setDifficulty(value);
|
if (this.propertyList.get(name).parseValue(value)) {
|
||||||
}
|
this.saveConfig();
|
||||||
if (name.equalsIgnoreCase("alias")) {
|
|
||||||
this.setAlias(value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (name.equalsIgnoreCase("respawn")) {
|
|
||||||
this.setRespawnToWorld(value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (name.equalsIgnoreCase("aliascolor") || name.equalsIgnoreCase("color")) {
|
|
||||||
return this.setColor(value);
|
|
||||||
}
|
|
||||||
if (name.equalsIgnoreCase("currency") || name.equalsIgnoreCase("curr")) {
|
|
||||||
try {
|
|
||||||
this.setCurrency(Integer.parseInt(value));
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (name.equalsIgnoreCase("price")) {
|
|
||||||
try {
|
|
||||||
this.setPrice(Double.parseDouble(value));
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (name.equalsIgnoreCase("scale") || name.equalsIgnoreCase("scaling")) {
|
|
||||||
try {
|
|
||||||
return this.setScaling(Double.parseDouble(value));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name.equalsIgnoreCase("gamemode") || name.equalsIgnoreCase("mode")) {
|
|
||||||
try {
|
|
||||||
return this.setGameMode(GameMode.valueOf(value.toUpperCase()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return this.setVariable(name, Boolean.parseBoolean(value));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
throw new PropertyDoesNotExistException(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVariable(String name) throws PropertyDoesNotExistException {
|
||||||
|
if (this.propertyList.containsKey(name)) {
|
||||||
|
return this.propertyList.get(name).toString();
|
||||||
|
}
|
||||||
|
throw new PropertyDoesNotExistException(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -497,27 +470,14 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets whether or not this world will display in chat, mvw and mvl regardless if a user has the
|
|
||||||
* access permissions to go to this world.
|
|
||||||
*
|
|
||||||
* @return True if the world will be hidden, false if not.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHidden() {
|
public boolean isHidden() {
|
||||||
return this.isHidden;
|
return (Boolean) this.propertyList.get("hidden").getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether or not this world will display in chat, mvw and mvl regardless if a user has the
|
|
||||||
* access permissions to go to this world.
|
|
||||||
*
|
|
||||||
* @param hidden Set
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void setHidden(boolean hidden) {
|
public void setHidden(boolean hidden) {
|
||||||
this.isHidden = hidden;
|
this.propertyList.get("hidden").parseValue(hidden + "");
|
||||||
this.worldSection.set("hidden", hidden);
|
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -754,13 +714,14 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readSpawnFromConfig(World w) {
|
private Location readSpawnFromConfig(World w) {
|
||||||
double x = worldSection.getDouble("spawn.x", w.getSpawnLocation().getX());
|
Location spawnLocation = w.getSpawnLocation();
|
||||||
double y = worldSection.getDouble("spawn.y", w.getSpawnLocation().getY());
|
double x = worldSection.getDouble("spawn.x", spawnLocation.getX());
|
||||||
double z = worldSection.getDouble("spawn.z", w.getSpawnLocation().getZ());
|
double y = worldSection.getDouble("spawn.y", spawnLocation.getY());
|
||||||
|
double z = worldSection.getDouble("spawn.z", spawnLocation.getZ());
|
||||||
|
float pitch = (float) worldSection.getDouble("spawn.pitch", spawnLocation.getPitch());
|
||||||
|
float yaw = (float) worldSection.getDouble("spawn.yaw", spawnLocation.getYaw());
|
||||||
this.plugin.log(Level.FINE, "Read spawn from config as: " + x + ", " + y + ", " + z);
|
this.plugin.log(Level.FINE, "Read spawn from config as: " + x + ", " + y + ", " + z);
|
||||||
float pitch = (float) worldSection.getDouble("spawn.pitch", w.getSpawnLocation().getPitch());
|
|
||||||
float yaw = (float) worldSection.getDouble("spawn.yaw", w.getSpawnLocation().getYaw());
|
|
||||||
|
|
||||||
this.setSpawnLocation(new Location(w, x, y, z, yaw, pitch));
|
this.setSpawnLocation(new Location(w, x, y, z, yaw, pitch));
|
||||||
this.plugin.log(Level.FINEST, "Spawn for '" + this.getName() + "' Located at: " + LocationManipulation.locationToString(this.getSpawnLocation()));
|
this.plugin.log(Level.FINEST, "Spawn for '" + this.getName() + "' Located at: " + LocationManipulation.locationToString(this.getSpawnLocation()));
|
||||||
@ -772,7 +733,7 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
this.plugin.log(Level.WARNING, "NOT adjusting spawn for '" + this.getAlias() + "' because you told me not to.");
|
this.plugin.log(Level.WARNING, "NOT adjusting spawn for '" + this.getAlias() + "' because you told me not to.");
|
||||||
this.plugin.log(Level.WARNING, "To turn on spawn adjustment for this world simply type:");
|
this.plugin.log(Level.WARNING, "To turn on spawn adjustment for this world simply type:");
|
||||||
this.plugin.log(Level.WARNING, "/mvm set adjustspawn true " + this.getAlias());
|
this.plugin.log(Level.WARNING, "/mvm set adjustspawn true " + this.getAlias());
|
||||||
return;
|
return this.spawnLocation;
|
||||||
}
|
}
|
||||||
this.plugin.log(Level.WARNING, "Spawn location from world.dat file was unsafe. Adjusting...");
|
this.plugin.log(Level.WARNING, "Spawn location from world.dat file was unsafe. Adjusting...");
|
||||||
Location newSpawn = teleporter.getSafeLocation(this.spawnLocation, 128, 128);
|
Location newSpawn = teleporter.getSafeLocation(this.spawnLocation, 128, 128);
|
||||||
@ -786,7 +747,7 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!");
|
this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this.spawnLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package com.onarandombox.MultiverseCore.api;
|
package com.onarandombox.MultiverseCore.api;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ public interface MultiverseWorld {
|
|||||||
*
|
*
|
||||||
* @return True if the value was set, false if not.
|
* @return True if the value was set, false if not.
|
||||||
*/
|
*/
|
||||||
public boolean setVariable(String property, String value);
|
public boolean setVariable(String property, String value) throws PropertyDoesNotExistException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
* Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||||
|
@ -11,6 +11,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
|||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
import com.onarandombox.MultiverseCore.enums.Action;
|
import com.onarandombox.MultiverseCore.enums.Action;
|
||||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||||
|
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -94,18 +95,21 @@ public class ModifySetCommand extends MultiverseCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ModifyCommand.validateAction(Action.Set, property)) {
|
|
||||||
sender.sendMessage("Sorry, you can't SET " + property);
|
|
||||||
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/l54PH");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) && !world.isValidAliasColor(value)) {
|
if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) && !world.isValidAliasColor(value)) {
|
||||||
sender.sendMessage(value + " is not a valid color. Please pick one of the following:");
|
sender.sendMessage(value + " is not a valid color. Please pick one of the following:");
|
||||||
sender.sendMessage(EnglishChatColor.getAllColors());
|
sender.sendMessage(EnglishChatColor.getAllColors());
|
||||||
} else if (world.setVariable(property, value)) {
|
return;
|
||||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
}
|
||||||
} else {
|
try {
|
||||||
sender.sendMessage(ChatColor.RED + "There was an error setting " + ChatColor.GRAY + property);
|
if (world.setVariable(property, value)) {
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "There was an error setting " + ChatColor.GRAY + property);
|
||||||
|
}
|
||||||
|
} catch (PropertyDoesNotExistException e) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Sorry, You can't set: '" + ChatColor.GRAY + property + ChatColor.RED + "'");
|
||||||
|
// TODO: Display the list
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "For a full list of thingys, see our wiki.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public class BooleanConfigProperty implements MVConfigProperty<Boolean> {
|
||||||
|
private String name;
|
||||||
|
private Boolean value;
|
||||||
|
private String configNode;
|
||||||
|
private ConfigurationSection section;
|
||||||
|
|
||||||
|
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = name;
|
||||||
|
this.section = section;
|
||||||
|
this.setValue(this.section.getBoolean(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String configNode) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = configNode;
|
||||||
|
this.section = section;
|
||||||
|
this.setValue(this.section.getBoolean(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setValue(Boolean value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
this.section.set(configNode, this.value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parseValue(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (value.toLowerCase().equals("true") || value.toLowerCase().equals("false")) {
|
||||||
|
this.setValue(Boolean.parseBoolean(value));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigNode() {
|
||||||
|
return this.configNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public class ColorConfigProperty implements MVConfigProperty<EnglishChatColor> {
|
||||||
|
private String name;
|
||||||
|
private EnglishChatColor value;
|
||||||
|
private String configNode;
|
||||||
|
private ConfigurationSection section;
|
||||||
|
|
||||||
|
public ColorConfigProperty(ConfigurationSection section, String name, EnglishChatColor defaultValue) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = name;
|
||||||
|
this.section = section;
|
||||||
|
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorConfigProperty(ConfigurationSection section, String name, EnglishChatColor defaultValue, String configNode) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = configNode;
|
||||||
|
this.section = section;
|
||||||
|
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnglishChatColor getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setValue(EnglishChatColor value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
this.section.set(configNode, this.value.getText());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parseValue(String value) {
|
||||||
|
EnglishChatColor color = EnglishChatColor.fromString(value);
|
||||||
|
if (color == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.value = color;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigNode() {
|
||||||
|
return this.configNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||||
|
import org.bukkit.Difficulty;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
/** A factory to create config properties for a given world. */
|
||||||
|
public class ConfigPropertyFactory {
|
||||||
|
private ConfigurationSection section;
|
||||||
|
|
||||||
|
public ConfigPropertyFactory(ConfigurationSection section) {
|
||||||
|
this.section = section;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Booleans
|
||||||
|
public BooleanConfigProperty getNewProperty(String name, boolean defaultValue) {
|
||||||
|
return new BooleanConfigProperty(this.section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String node) {
|
||||||
|
return new BooleanConfigProperty(this.section, name, defaultValue, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Integers
|
||||||
|
public IntegerConfigProperty getNewProperty(String name, int defaultValue) {
|
||||||
|
return new IntegerConfigProperty(this.section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegerConfigProperty getNewProperty(String name, int defaultValue, String node) {
|
||||||
|
return new IntegerConfigProperty(this.section, name, defaultValue, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Doubles
|
||||||
|
public DoubleConfigProperty getNewProperty(String name, double defaultValue) {
|
||||||
|
return new DoubleConfigProperty(this.section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DoubleConfigProperty getNewProperty(String name, double defaultValue, String node) {
|
||||||
|
return new DoubleConfigProperty(this.section, name, defaultValue, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings
|
||||||
|
public StringConfigProperty getNewProperty(String name, String defaultValue) {
|
||||||
|
return new StringConfigProperty(this.section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringConfigProperty getNewProperty(String name, String defaultValue, String node) {
|
||||||
|
return new StringConfigProperty(this.section, name, defaultValue, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Colors
|
||||||
|
public ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue) {
|
||||||
|
return new ColorConfigProperty(this.section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue, String node) {
|
||||||
|
return new ColorConfigProperty(this.section, name, defaultValue, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Difficulty
|
||||||
|
public DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue) {
|
||||||
|
return new DifficultyConfigProperty(this.section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue, String node) {
|
||||||
|
return new DifficultyConfigProperty(this.section, name, defaultValue, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GameMode
|
||||||
|
public GameModeConfigProperty getNewProperty(String name, GameMode defaultValue) {
|
||||||
|
return new GameModeConfigProperty(this.section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameModeConfigProperty getNewProperty(String name, GameMode defaultValue, String node) {
|
||||||
|
return new GameModeConfigProperty(this.section, name, defaultValue, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GameMode
|
||||||
|
public LocationConfigProperty getNewProperty(String name, Location defaultValue) {
|
||||||
|
return new LocationConfigProperty(this.section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocationConfigProperty getNewProperty(String name, Location defaultValue, String node) {
|
||||||
|
return new LocationConfigProperty(this.section, name, defaultValue, node);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||||
|
import org.bukkit.Difficulty;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public class DifficultyConfigProperty implements MVConfigProperty<Difficulty> {
|
||||||
|
private String name;
|
||||||
|
private Difficulty value;
|
||||||
|
private String configNode;
|
||||||
|
private ConfigurationSection section;
|
||||||
|
|
||||||
|
public DifficultyConfigProperty(ConfigurationSection section, String name, Difficulty defaultValue) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = name;
|
||||||
|
this.section = section;
|
||||||
|
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DifficultyConfigProperty(ConfigurationSection section, String name, Difficulty defaultValue, String configNode) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = configNode;
|
||||||
|
this.section = section;
|
||||||
|
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Difficulty getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setValue(Difficulty value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
this.section.set(configNode, this.value.toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parseValue(String value) {
|
||||||
|
try {
|
||||||
|
return this.setValue(Difficulty.getByValue(Integer.parseInt(value)));
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
try {
|
||||||
|
return this.setValue(Difficulty.valueOf(value.toUpperCase()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigNode() {
|
||||||
|
return this.configNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public class DoubleConfigProperty implements MVConfigProperty<Double> {
|
||||||
|
private String name;
|
||||||
|
private Double value;
|
||||||
|
private String configNode;
|
||||||
|
private ConfigurationSection section;
|
||||||
|
|
||||||
|
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = name;
|
||||||
|
this.section = section;
|
||||||
|
this.setValue(this.section.getDouble(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String configNode) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = configNode;
|
||||||
|
this.section = section;
|
||||||
|
this.setValue(this.section.getDouble(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Double getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setValue(Double value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
this.section.set(configNode, this.value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parseValue(String value) {
|
||||||
|
try {
|
||||||
|
this.setValue(Double.parseDouble(value));
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigNode() {
|
||||||
|
return this.configNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import org.bukkit.Difficulty;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public class GameModeConfigProperty implements MVConfigProperty<GameMode> {
|
||||||
|
private String name;
|
||||||
|
private GameMode value;
|
||||||
|
private String configNode;
|
||||||
|
private ConfigurationSection section;
|
||||||
|
|
||||||
|
public GameModeConfigProperty(ConfigurationSection section, String name, GameMode defaultValue) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = name;
|
||||||
|
this.section = section;
|
||||||
|
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameModeConfigProperty(ConfigurationSection section, String name, GameMode defaultValue, String configNode) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = configNode;
|
||||||
|
this.section = section;
|
||||||
|
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GameMode getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setValue(GameMode value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
this.section.set(configNode, this.value.toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parseValue(String value) {
|
||||||
|
try {
|
||||||
|
return this.setValue(GameMode.getByValue(Integer.parseInt(value)));
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
try {
|
||||||
|
return this.setValue(GameMode.valueOf(value.toUpperCase()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigNode() {
|
||||||
|
return this.configNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public class IntegerConfigProperty implements MVConfigProperty<Integer> {
|
||||||
|
private String name;
|
||||||
|
private Integer value;
|
||||||
|
private String configNode;
|
||||||
|
private ConfigurationSection section;
|
||||||
|
|
||||||
|
public IntegerConfigProperty(ConfigurationSection section, String name, Integer defaultValue) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = name;
|
||||||
|
this.section = section;
|
||||||
|
this.setValue(this.section.getInt(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegerConfigProperty(ConfigurationSection section, String name, Integer defaultValue, String configNode) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = configNode;
|
||||||
|
this.section = section;
|
||||||
|
this.setValue(this.section.getInt(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setValue(Integer value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
this.section.set(configNode, this.value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parseValue(String value) {
|
||||||
|
try {
|
||||||
|
this.setValue(Integer.parseInt(value));
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigNode() {
|
||||||
|
return this.configNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.utils.LocationManipulation;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public class LocationConfigProperty implements MVConfigProperty<Location> {
|
||||||
|
private String name;
|
||||||
|
private Location value;
|
||||||
|
private String configNode;
|
||||||
|
private ConfigurationSection section;
|
||||||
|
|
||||||
|
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = name;
|
||||||
|
this.section = section;
|
||||||
|
this.setValue(this.getLocationFromConfig(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = configNode;
|
||||||
|
this.section = section;
|
||||||
|
this.setValue(this.getLocationFromConfig(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parseValue(String value) {
|
||||||
|
Location parsed = LocationManipulation.getLocationFromString(value);
|
||||||
|
return this.setValue(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigNode() {
|
||||||
|
return this.configNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return LocationManipulation.strCoordsRaw(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setValue(Location value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
this.section.set(configNode + ".x", this.value.getX());
|
||||||
|
this.section.set(configNode + ".y", this.value.getY());
|
||||||
|
this.section.set(configNode + ".z", this.value.getZ());
|
||||||
|
this.section.set(configNode + ".pitch", this.value.getPitch());
|
||||||
|
this.section.set(configNode + ".yaw", this.value.getYaw());
|
||||||
|
this.section.set(configNode + ".world", this.value.getWorld().getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location getLocationFromConfig(String node, Location defaultValue) {
|
||||||
|
double x = this.section.getDouble(configNode + ".x", defaultValue.getX());
|
||||||
|
double y = this.section.getDouble(configNode + ".y", defaultValue.getY());
|
||||||
|
double z = this.section.getDouble(configNode + ".z", defaultValue.getZ());
|
||||||
|
double p = this.section.getDouble(configNode + ".pitch", defaultValue.getPitch());
|
||||||
|
double yaw = this.section.getDouble(configNode + ".yaw", defaultValue.getYaw());
|
||||||
|
String w = this.section.getString(configNode + ".world", defaultValue.getWorld().getName());
|
||||||
|
Location found = LocationManipulation.getLocationFromString(w + ":" + x + "," + y + "," + z + ":" + p + ":" + yaw);
|
||||||
|
if (found != null) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
package com.onarandombox.MultiverseCore.configuration;
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
public interface MVConfigProperty {
|
public interface MVConfigProperty<T> {
|
||||||
/**
|
/**
|
||||||
* Gets the name of this property.
|
* Gets the name of this property.
|
||||||
*
|
*
|
||||||
@ -15,4 +15,35 @@ public interface MVConfigProperty {
|
|||||||
*/
|
*/
|
||||||
public String getName();
|
public String getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of this property.
|
||||||
|
*
|
||||||
|
* @return The value of this property.
|
||||||
|
*/
|
||||||
|
public T getValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the string representation of this value.
|
||||||
|
*
|
||||||
|
* @return The value of this property as a string.
|
||||||
|
*/
|
||||||
|
public String toString();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of this property
|
||||||
|
*
|
||||||
|
* @param value The T representation of this value.
|
||||||
|
*/
|
||||||
|
public boolean setValue(T value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This parseValue should be used with strings.
|
||||||
|
*
|
||||||
|
* @param value The string representation of the value to set.
|
||||||
|
*
|
||||||
|
* @return True if the value was set, false if not.
|
||||||
|
*/
|
||||||
|
public boolean parseValue(String value);
|
||||||
|
|
||||||
|
public String getConfigNode();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public class StringConfigProperty implements MVConfigProperty<String> {
|
||||||
|
private String name;
|
||||||
|
private String value;
|
||||||
|
private String configNode;
|
||||||
|
private ConfigurationSection section;
|
||||||
|
|
||||||
|
public StringConfigProperty(ConfigurationSection section, String name, String defaultValue) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = name;
|
||||||
|
this.section = section;
|
||||||
|
this.parseValue(this.section.getString(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringConfigProperty(ConfigurationSection section, String name, String defaultValue, String configNode) {
|
||||||
|
this.name = name;
|
||||||
|
this.configNode = configNode;
|
||||||
|
this.section = section;
|
||||||
|
this.parseValue(this.section.getString(this.configNode, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parseValue(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.setValue(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigNode() {
|
||||||
|
return this.configNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setValue(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
this.section.set(configNode, this.value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -13,8 +13,6 @@ package com.onarandombox.MultiverseCore.enums;
|
|||||||
* @author fernferret
|
* @author fernferret
|
||||||
*/ // Color == Aliascolor
|
*/ // Color == Aliascolor
|
||||||
public enum SetProperties {
|
public enum SetProperties {
|
||||||
alias, animals, monsters, pvp, scaling, aliascolor, color, respawn,
|
spawn, autoheal,
|
||||||
currency, curr, price, scale, spawnmemory, memory, weather, storm,
|
|
||||||
gamemode, mode, hunger, difficulty, diff, hidden, spawn, autoheal,
|
|
||||||
heal, adjustspawn
|
heal, adjustspawn
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||||
|
* Multiverse 2 is licensed under the BSD License. *
|
||||||
|
* For more information please check the README.md file included *
|
||||||
|
* with this project. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.onarandombox.MultiverseCore.exceptions;
|
||||||
|
|
||||||
|
public class PropertyDoesNotExistException extends Exception {
|
||||||
|
public PropertyDoesNotExistException(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package com.onarandombox.MultiverseCore.utils;
|
package com.onarandombox.MultiverseCore.utils;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -224,4 +225,43 @@ public class LocationManipulation {
|
|||||||
int z = vector.getZ() < 0 ? vector.getZ() == 0 ? 0 : -1 : 1;
|
int z = vector.getZ() < 0 ? vector.getZ() == 0 ? 0 : -1 : 1;
|
||||||
return location.add(x, 0, z);
|
return location.add(x, 0, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Location getLocationFromString(String value) {
|
||||||
|
//format:
|
||||||
|
//world:x,y,z:pitch:yaw
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split the whole string, format is:
|
||||||
|
// {'world', 'x,y,z'[, 'pitch', 'yaw']}
|
||||||
|
String[] split = value.split(":");
|
||||||
|
if (split.length < 2 || split.length > 4) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Split the xyz string, format is:
|
||||||
|
// {'x', 'y', 'z'}
|
||||||
|
String[] xyzsplit = split[1].split(",");
|
||||||
|
if (xyzsplit.length != 3) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the world is valid
|
||||||
|
World w = Bukkit.getWorld(split[0]);
|
||||||
|
if (w == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (split.length == 2) {
|
||||||
|
return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]));
|
||||||
|
}
|
||||||
|
if (split.length == 3) {
|
||||||
|
return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), (float) Double.parseDouble(split[2]),(float) 0.0);
|
||||||
|
}
|
||||||
|
return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), (float) Double.parseDouble(split[2]), (float) Double.parseDouble(split[3]));
|
||||||
|
} catch(NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user