mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 20:41:59 +01:00
Merge with betterproperties
This commit is contained in:
commit
af428a236d
6
.gitignore
vendored
6
.gitignore
vendored
@ -33,4 +33,8 @@
|
||||
.idea/
|
||||
|
||||
# Fern's utils
|
||||
uploadtoserver.sh
|
||||
uploadtoserver.sh
|
||||
|
||||
# Testing files:
|
||||
debug.log
|
||||
|
||||
|
39
pom.xml
39
pom.xml
@ -117,7 +117,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>1.0.0-R1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@ -185,12 +185,45 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End of Economy Dependencies -->
|
||||
<!-- Start of JUnit Dependencies -->
|
||||
<!-- Start of Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- End of JUnit Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.4.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-easymock</artifactId>
|
||||
<version>1.4.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.4.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
<!-- End of Test Dependencies -->
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -8,7 +8,9 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.configuration.*;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import com.onarandombox.MultiverseCore.utils.BlockSafety;
|
||||
import com.onarandombox.MultiverseCore.utils.LocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
|
||||
@ -37,40 +39,16 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
private World world; // The World Instance.
|
||||
private Environment environment; // Hold the Environment type EG Environment.NETHER / Environment.NORMAL
|
||||
private Long seed;
|
||||
|
||||
private Long seed; // The world seed
|
||||
private String name; // The Worlds Name, EG its folder name.
|
||||
private String alias = ""; // Short Alias for the World, this will be used in Chat Prefixes.
|
||||
private ChatColor aliasColor; // Color for this world
|
||||
|
||||
private boolean allowAnimals; // Does this World allow Animals to Spawn?
|
||||
private boolean allowMonsters; // Does this World allow Monsters to Spawn?
|
||||
|
||||
private boolean keepSpawnInMemory; // Does the World have the spawn loaded all the time?
|
||||
|
||||
private boolean pvp; // Does this World allow PVP?
|
||||
private boolean fakePVP; // Should this world have fakePVP on? (used for PVP zones)
|
||||
|
||||
private GameMode gameMode = GameMode.SURVIVAL;
|
||||
|
||||
private String respawnWorld; // Contains the name of the World to respawn the player to
|
||||
|
||||
|
||||
private Map<String, List<String>> masterList;
|
||||
private Map<String, MVConfigProperty> propertyList;
|
||||
|
||||
private double scaling; // How stretched/compressed distances are
|
||||
private double price; // How much does it cost to enter this world
|
||||
private int currency = -1; // What is the currency
|
||||
private boolean hunger = true;
|
||||
private Permission permission;
|
||||
private Permission exempt;
|
||||
|
||||
private boolean canSave = false; // Prevents all the setters from constantly saving to the config when being called from the constructor.
|
||||
private boolean allowWeather;
|
||||
private Location spawnLocation;
|
||||
private boolean isHidden = false;
|
||||
private boolean autoheal = true;
|
||||
private boolean adjustSpawn = true;
|
||||
|
||||
public MVWorld(World world, FileConfiguration config, MultiverseCore instance, Long seed, String generatorString) {
|
||||
this.config = config;
|
||||
@ -98,31 +76,50 @@ public class MVWorld implements MultiverseWorld {
|
||||
}
|
||||
worldSection.set("environment", this.environment.toString());
|
||||
|
||||
// Set local values that CAN be changed by the user
|
||||
this.setAlias(worldSection.getString("alias.name", ""));
|
||||
this.setColor(worldSection.getString("alias.color", ChatColor.WHITE.toString()));
|
||||
this.setPVPMode(worldSection.getBoolean("pvp", true));
|
||||
this.setFakePVPMode(worldSection.getBoolean("fakepvp", false));
|
||||
this.setScaling(worldSection.getDouble("scale", this.getDefaultScale(this.environment)));
|
||||
this.setRespawnToWorld(worldSection.getString("respawnworld", ""));
|
||||
this.setEnableWeather(worldSection.getBoolean("allowweather", true));
|
||||
this.setDifficulty(worldSection.get("difficulty", "EASY"));
|
||||
// Start NEW config awesomeness.
|
||||
ConfigPropertyFactory fac = new ConfigPropertyFactory(this.worldSection);
|
||||
this.propertyList = new HashMap<String, MVConfigProperty>();
|
||||
// The format of these are either:
|
||||
// getNewProperty(name, defaultValue, helpText)
|
||||
// or
|
||||
// getNewProperty(name, defaultValue, yamlConfigNode, helpText)
|
||||
//
|
||||
// If the first type is used, name is used as the yamlConfigNode
|
||||
this.propertyList.put("hidden", fac.getNewProperty("hidden", false, "Sorry, 'hidden' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("alias", fac.getNewProperty("alias", "", "alias.name", "Alias must be a valid string."));
|
||||
this.propertyList.put("color", fac.getNewProperty("color", EnglishChatColor.WHITE, "alias.color", "Sorry, 'color' must either one of: " + EnglishChatColor.getAllColors()));
|
||||
this.propertyList.put("pvp", fac.getNewProperty("pvp", true, "Sorry, 'pvp' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("scale", fac.getNewProperty("scale", this.getDefaultScale(this.environment), "Scale must be a positive double value. ex: " + ChatColor.GOLD + "2.3"));
|
||||
this.propertyList.put("respawn", fac.getNewProperty("respawn", "", "respawnworld", "You must set this to the " + ChatColor.GOLD + " NAME" + ChatColor.RED + " not alias of a world."));
|
||||
this.propertyList.put("weather", fac.getNewProperty("weather", true, "allowweather", "Sorry, 'weather' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("difficulty", fac.getNewProperty("difficulty", Difficulty.EASY, "Difficulty must be set as one of the following: " + ChatColor.GREEN + "peaceful " + ChatColor.AQUA + "easy " + ChatColor.GOLD + "normal " + ChatColor.RED + "hard"));
|
||||
this.propertyList.put("animals", fac.getNewProperty("animals", true, "animals.spawn", "Sorry, 'animals' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("monsters", fac.getNewProperty("monsters", true, "monsters.spawn", "Sorry, 'monsters' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("currency", fac.getNewProperty("currency", -1, "entryfee.currency", "Currency must be an integer between -1 and the highest Minecraft item ID."));
|
||||
this.propertyList.put("price", fac.getNewProperty("price", 0.0, "entryfee.price", "Price must be a double value. ex: " + ChatColor.GOLD + "1.2" + ChatColor.WHITE + ". Set to a negative value to give players money for entering this world."));
|
||||
this.propertyList.put("hunger", fac.getNewProperty("hunger", true, "Sorry, 'hunger' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("autoheal", fac.getNewProperty("autoheal", true, "Sorry, 'autoheal' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("adjustspawn", fac.getNewProperty("adjustspawn", true, "Sorry, 'adjustspawn' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("gamemode", fac.getNewProperty("gamemode", GameMode.SURVIVAL, "GameMode must be set as one of the following: " + ChatColor.RED + "survival " + ChatColor.GREEN + "creative "));
|
||||
this.propertyList.put("memory", fac.getNewProperty("keepspawninmemory", true, "keepspawninmemory", "Sorry, 'memory' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
|
||||
this.propertyList.put("spawn", fac.getNewProperty("spawn", this.world.getSpawnLocation(), "There is no help available for this variable. Go bug Rigby90 about it."));
|
||||
((LocationConfigProperty) this.propertyList.get("spawn")).setValue(this.readSpawnFromConfig(this.getCBWorld()));
|
||||
|
||||
this.setAllowAnimalSpawn(worldSection.getBoolean("animals.spawn", true));
|
||||
this.setAllowMonsterSpawn(worldSection.getBoolean("monsters.spawn", true));
|
||||
this.setPrice(worldSection.getDouble("entryfee.amount", 0.0));
|
||||
this.setCurrency(worldSection.getInt("entryfee.currency", -1));
|
||||
this.setHunger(worldSection.getBoolean("hunger", true));
|
||||
this.setHidden(worldSection.getBoolean("hidden", false));
|
||||
// Set aliases
|
||||
this.propertyList.put("curr", this.propertyList.get("currency"));
|
||||
this.propertyList.put("scaling", this.propertyList.get("scale"));
|
||||
this.propertyList.put("aliascolor", this.propertyList.get("color"));
|
||||
this.propertyList.put("heal", this.propertyList.get("autoheal"));
|
||||
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.setGameMode(worldSection.get("gamemode", GameMode.SURVIVAL.toString()));
|
||||
|
||||
this.setKeepSpawnInMemory(worldSection.getBoolean("keepspawninmemory", true));
|
||||
|
||||
this.getWorldBlacklist().addAll(worldSection.getList("worldblacklist", new ArrayList<String>()));
|
||||
this.translateTempSpawn(worldSection);
|
||||
this.readSpawnFromConfig(this.getCBWorld());
|
||||
|
||||
// Enable and do the save.
|
||||
this.canSave = true;
|
||||
this.saveConfig();
|
||||
|
||||
@ -137,6 +134,46 @@ public class MVWorld implements MultiverseWorld {
|
||||
}
|
||||
}
|
||||
|
||||
public void changeActiveEffects() {
|
||||
// Disable any current weather
|
||||
if (!(Boolean) this.propertyList.get("weather").getValue()) {
|
||||
this.getCBWorld().setStorm(false);
|
||||
this.getCBWorld().setThundering(false);
|
||||
}
|
||||
|
||||
// Set the spawn location
|
||||
Location spawnLocation = ((LocationConfigProperty) this.propertyList.get("spawn")).getValue();
|
||||
this.getCBWorld().setSpawnLocation(spawnLocation.getBlockX(), spawnLocation.getBlockY(), spawnLocation.getBlockZ());
|
||||
|
||||
// Syncronize all Mob settings
|
||||
this.syncMobs();
|
||||
|
||||
// Ensure the memory setting is correct
|
||||
this.world.setKeepSpawnInMemory(((BooleanConfigProperty) this.propertyList.get("memory")).getValue());
|
||||
|
||||
// Set the PVP mode
|
||||
this.world.setPVP(((BooleanConfigProperty) this.propertyList.get("pvp")).getValue());
|
||||
|
||||
// Ensure the scale is above 0
|
||||
if (((DoubleConfigProperty) this.propertyList.get("scale")).getValue() <= 0) {
|
||||
// Disallow negative or 0 scalings.
|
||||
((DoubleConfigProperty) this.propertyList.get("scale")).setValue(1.0);
|
||||
this.plugin.log(Level.WARNING, "Someone tried to set a scale <= 0, defaulting to 1.");
|
||||
}
|
||||
|
||||
// Set the gamemode
|
||||
// TODO: Move this to a per world gamemode
|
||||
if (MultiverseCore.EnforceGameModes) {
|
||||
for (Player p : this.plugin.getServer().getWorld(this.getName()).getPlayers()) {
|
||||
this.plugin.log(Level.FINER, "Setting " + p.getName() + "'s GameMode to " + this.propertyList.get("mode").getValue().toString());
|
||||
this.plugin.getPlayerListener().handleGameMode(p, this);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the difficulty
|
||||
this.getCBWorld().setDifficulty(((DifficultyConfigProperty) this.propertyList.get("diff")).getValue());
|
||||
}
|
||||
|
||||
private double getDefaultScale(Environment environment) {
|
||||
if (environment == Environment.NETHER) {
|
||||
return 8.0;
|
||||
@ -144,17 +181,6 @@ public class MVWorld implements MultiverseWorld {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
public void setEnableWeather(boolean weather) {
|
||||
this.allowWeather = weather;
|
||||
// Disable any current weather
|
||||
if (!weather) {
|
||||
this.getCBWorld().setStorm(false);
|
||||
this.getCBWorld().setThundering(false);
|
||||
}
|
||||
this.worldSection.set("allowweather", weather);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void addToUpperLists(Permission permission) {
|
||||
Permission all = this.plugin.getServer().getPluginManager().getPermission("multiverse.*");
|
||||
Permission allWorlds = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
|
||||
@ -181,35 +207,19 @@ public class MVWorld implements MultiverseWorld {
|
||||
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allWorlds);
|
||||
}
|
||||
|
||||
private void translateTempSpawn(ConfigurationSection section) {
|
||||
String tempspawn = section.getString("tempspawn", "");
|
||||
if (tempspawn.length() > 0) {
|
||||
String[] coordsString = tempspawn.split(":");
|
||||
if (coordsString.length >= 3) {
|
||||
int[] coords = new int[3];
|
||||
try {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
coords[i] = Integer.parseInt(coordsString[i]);
|
||||
}
|
||||
this.setSpawnLocation(new Location(this.getCBWorld(), coords[0], coords[1], coords[2]));
|
||||
} catch (NumberFormatException e) {
|
||||
this.plugin.log(Level.WARNING, "A MV1 spawn value was found, but it could not be migrated. Format Error. Sorry.");
|
||||
}
|
||||
} else {
|
||||
this.plugin.log(Level.WARNING, "A MV1 spawn value was found, but it could not be migrated. Format Error. Sorry.");
|
||||
}
|
||||
|
||||
this.worldSection.set("tempspawn", null);
|
||||
}
|
||||
}
|
||||
|
||||
public String getColoredWorldString() {
|
||||
if (this.getColor() == null) {
|
||||
return this.getAlias() + ChatColor.WHITE;
|
||||
EnglishChatColor worldColor = ((ColorConfigProperty) this.propertyList.get("color")).getValue();
|
||||
String alias = ((StringConfigProperty) this.propertyList.get("alias")).getValue();
|
||||
if (worldColor.getColor() == null) {
|
||||
return alias + ChatColor.WHITE;
|
||||
}
|
||||
return this.getColor() + this.getAlias() + ChatColor.WHITE;
|
||||
if (alias.length() == 0) {
|
||||
alias = this.getName();
|
||||
}
|
||||
return worldColor.getColor() + alias + ChatColor.WHITE;
|
||||
}
|
||||
|
||||
// TODO: Migrate this method.
|
||||
private void getMobExceptions() {
|
||||
List<String> temp;
|
||||
temp = this.worldSection.getList("animals.exceptions", new ArrayList<String>());
|
||||
@ -284,175 +294,111 @@ public class MVWorld implements MultiverseWorld {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Deprecated, use {@link #addToVariable(String, String)} now. */
|
||||
@Deprecated
|
||||
public boolean addToList(String list, String value) {
|
||||
return this.addToVariable(list, value);
|
||||
}
|
||||
|
||||
// Deprecated, use {@link #removeFromVariable(String, String)} now.
|
||||
@Deprecated
|
||||
public boolean removeFromList(String list, String value) {
|
||||
return this.removeFromVariable(list, value);
|
||||
}
|
||||
|
||||
private void syncMobs() {
|
||||
|
||||
if (this.getAnimalList().isEmpty()) {
|
||||
this.world.setSpawnFlags(this.world.getAllowMonsters(), this.allowAnimals);
|
||||
this.world.setSpawnFlags(this.world.getAllowMonsters(), ((BooleanConfigProperty) this.propertyList.get("animals")).getValue());
|
||||
} else {
|
||||
this.world.setSpawnFlags(this.world.getAllowMonsters(), true);
|
||||
}
|
||||
if (this.getMonsterList().isEmpty()) {
|
||||
this.world.setSpawnFlags(this.allowMonsters, this.world.getAllowAnimals());
|
||||
this.world.setSpawnFlags(((BooleanConfigProperty) this.propertyList.get("monsters")).getValue(), this.world.getAllowAnimals());
|
||||
} else {
|
||||
this.world.setSpawnFlags(true, this.world.getAllowAnimals());
|
||||
}
|
||||
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
|
||||
public void setKeepSpawnInMemory(boolean value) {
|
||||
this.world.setKeepSpawnInMemory(value);
|
||||
this.keepSpawnInMemory = value;
|
||||
this.worldSection.set("keepspawninmemory", value);
|
||||
((BooleanConfigProperty) this.propertyList.get("memory")).setValue(value);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
// TODO: Provide better feedback
|
||||
@Override
|
||||
public boolean setVariable(String name, String value) {
|
||||
if (name.equalsIgnoreCase("diff") || name.equalsIgnoreCase("difficulty")) {
|
||||
return this.setDifficulty(value);
|
||||
}
|
||||
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));
|
||||
public boolean setProperty(String name, String value) throws PropertyDoesNotExistException {
|
||||
if (this.propertyList.containsKey(name)) {
|
||||
if (this.propertyList.get(name).parseValue(value)) {
|
||||
this.saveConfig();
|
||||
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;
|
||||
}
|
||||
throw new PropertyDoesNotExistException(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertyValue(String name) throws PropertyDoesNotExistException {
|
||||
if (this.propertyList.containsKey(name)) {
|
||||
return this.propertyList.get(name).toString();
|
||||
}
|
||||
throw new PropertyDoesNotExistException(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MVConfigProperty getProperty(String name) throws PropertyDoesNotExistException {
|
||||
if (this.propertyList.containsKey(name)) {
|
||||
return this.propertyList.get(name);
|
||||
}
|
||||
throw new PropertyDoesNotExistException(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Environment getEnvironment() {
|
||||
// This variable is not settable in-game, therefore does not get a property.
|
||||
return this.environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
// This variable is not settable in-game, therefore does not get a property.
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSeed() {
|
||||
// This variable is not settable in-game, therefore does not get a property.
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSeed(Long seed) {
|
||||
// This variable is not settable in-game, therefore does not get a property.
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// This variable is not settable in-game, therefore does not get a property.
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlias() {
|
||||
if (this.alias == null || this.alias.length() == 0) {
|
||||
String alias = ((StringConfigProperty) this.propertyList.get("alias")).getValue();
|
||||
if (alias == null || alias.length() == 0) {
|
||||
return this.name;
|
||||
}
|
||||
return this.alias;
|
||||
return alias;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
this.worldSection.set("alias.name", alias);
|
||||
saveConfig();
|
||||
((StringConfigProperty) this.propertyList.get("alias")).setValue(alias);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAnimalsSpawn() {
|
||||
return this.allowAnimals;
|
||||
return ((BooleanConfigProperty) this.propertyList.get("animals")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowAnimalSpawn(boolean animals) {
|
||||
this.allowAnimals = animals;
|
||||
// If animals are a boolean, then we can turn them on or off on the server
|
||||
// If there are ANY exceptions, there will be something spawning, so turn them on
|
||||
this.worldSection.set("animals.spawn", animals);
|
||||
saveConfig();
|
||||
this.syncMobs();
|
||||
((BooleanConfigProperty) this.propertyList.get("animals")).setValue(animals);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -462,17 +408,13 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
@Override
|
||||
public boolean canMonstersSpawn() {
|
||||
return this.allowMonsters;
|
||||
return ((BooleanConfigProperty) this.propertyList.get("monsters")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowMonsterSpawn(boolean monsters) {
|
||||
this.allowMonsters = monsters;
|
||||
// If monsters are a boolean, then we can turn them on or off on the server
|
||||
// If there are ANY exceptions, there will be something spawning, so turn them on
|
||||
this.worldSection.set("monsters.spawn", monsters);
|
||||
saveConfig();
|
||||
this.syncMobs();
|
||||
((BooleanConfigProperty) this.propertyList.get("monsters")).setValue(monsters);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -482,51 +424,24 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
@Override
|
||||
public boolean isPVPEnabled() {
|
||||
return this.pvp;
|
||||
return ((BooleanConfigProperty) this.propertyList.get("pvp")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPVPMode(boolean pvp) {
|
||||
if (this.fakePVP) {
|
||||
this.world.setPVP(true);
|
||||
} else {
|
||||
this.world.setPVP(pvp);
|
||||
}
|
||||
this.pvp = pvp;
|
||||
this.worldSection.set("pvp", pvp);
|
||||
saveConfig();
|
||||
((BooleanConfigProperty) this.propertyList.get("pvp")).setValue(pvp);
|
||||
this.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
|
||||
public boolean isHidden() {
|
||||
return this.isHidden;
|
||||
return ((BooleanConfigProperty) 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
|
||||
public void setHidden(boolean hidden) {
|
||||
this.isHidden = hidden;
|
||||
this.worldSection.set("hidden", hidden);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public void setFakePVPMode(Boolean fakePVPMode) {
|
||||
this.fakePVP = fakePVPMode;
|
||||
this.worldSection.set("fakepvp", this.fakePVP);
|
||||
// Now that we've set PVP mode, make sure to go through the normal setting too!
|
||||
// This method will perform the save for us to eliminate one write.
|
||||
this.setPVPMode(this.pvp);
|
||||
((BooleanConfigProperty) this.propertyList.get("hidden")).setValue(hidden);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
public List<String> getWorldBlacklist() {
|
||||
@ -535,34 +450,23 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
@Override
|
||||
public double getScaling() {
|
||||
return this.scaling;
|
||||
return ((DoubleConfigProperty) this.propertyList.get("scale")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setScaling(double scaling) {
|
||||
boolean success = true;
|
||||
if (scaling <= 0) {
|
||||
// Disallow negative or 0 scalings.
|
||||
scaling = 1.0;
|
||||
this.plugin.log(Level.WARNING, "Someone tried to set a scale <= 0, defaulting to 1.");
|
||||
success = false;
|
||||
}
|
||||
this.scaling = scaling;
|
||||
this.worldSection.set("scale", scaling);
|
||||
((DoubleConfigProperty) this.propertyList.get("scale")).setValue(scaling);
|
||||
saveConfig();
|
||||
return success;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setColor(String aliasColor) {
|
||||
EnglishChatColor color = EnglishChatColor.fromString(aliasColor);
|
||||
if (color == null) {
|
||||
return false;
|
||||
boolean success = this.propertyList.get("color").parseValue(aliasColor);
|
||||
if (success) {
|
||||
saveConfig();
|
||||
}
|
||||
this.aliasColor = color.getColor();
|
||||
this.worldSection.set("alias.color", color.getText());
|
||||
saveConfig();
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
public boolean isValidAliasColor(String aliasColor) {
|
||||
@ -571,7 +475,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
@Override
|
||||
public ChatColor getColor() {
|
||||
return this.aliasColor;
|
||||
return ((ColorConfigProperty) this.propertyList.get("color")).getValue().getColor();
|
||||
}
|
||||
|
||||
public boolean clearList(String property) {
|
||||
@ -585,27 +489,19 @@ public class MVWorld implements MultiverseWorld {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean getFakePVP() {
|
||||
return this.fakePVP;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getRespawnToWorld() {
|
||||
if (this.respawnWorld == null) {
|
||||
return null;
|
||||
}
|
||||
return (this.plugin.getServer().getWorld(this.respawnWorld));
|
||||
return (this.plugin.getServer().getWorld(((StringConfigProperty) this.propertyList.get("respawn")).getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setRespawnToWorld(String respawnToWorld) {
|
||||
if (this.plugin.getServer().getWorld(respawnToWorld) != null) {
|
||||
this.respawnWorld = respawnToWorld;
|
||||
this.worldSection.set("respawnworld", respawnToWorld);
|
||||
saveConfig();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ((StringConfigProperty) this.propertyList.get("respawn")).setValue(respawnToWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -615,32 +511,24 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
@Override
|
||||
public int getCurrency() {
|
||||
return this.currency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPrice() {
|
||||
return this.price;
|
||||
return ((IntegerConfigProperty) this.propertyList.get("curr")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrency(int currency) {
|
||||
this.currency = currency;
|
||||
this.worldSection.set("entryfee.currency", currency);
|
||||
saveConfig();
|
||||
((IntegerConfigProperty) this.propertyList.get("curr")).setValue(currency);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPrice() {
|
||||
return ((DoubleConfigProperty) this.propertyList.get("price")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
this.worldSection.set("entryfee.amount", price);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
/** This method really isn't needed */
|
||||
@Deprecated
|
||||
public boolean isExempt(Player p) {
|
||||
return (this.plugin.getMVPerms().hasPermission(p, this.exempt.getName(), true));
|
||||
((DoubleConfigProperty) this.propertyList.get("price")).setValue(price);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -651,6 +539,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
private void saveConfig() {
|
||||
if (this.canSave) {
|
||||
try {
|
||||
this.changeActiveEffects();
|
||||
this.config.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
|
||||
} catch (IOException e) {
|
||||
this.plugin.log(Level.SEVERE, "Could not save worlds.yml. Please check your filesystem permissions.");
|
||||
@ -660,122 +549,74 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
@Override
|
||||
public boolean setGameMode(String gameMode) {
|
||||
GameMode mode;
|
||||
try {
|
||||
mode = GameMode.valueOf(gameMode.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
int modeInt = Integer.parseInt(gameMode);
|
||||
mode = GameMode.getByValue(modeInt);
|
||||
|
||||
} catch (Exception e2) {
|
||||
return false;
|
||||
}
|
||||
if (this.propertyList.get("mode").parseValue(gameMode)) {
|
||||
saveConfig();
|
||||
return true;
|
||||
}
|
||||
if (mode == null) {
|
||||
return false;
|
||||
}
|
||||
this.setGameMode(mode);
|
||||
this.worldSection.set("gamemode", mode.toString());
|
||||
saveConfig();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* FernFerret messed up and now config values could be in either string or Int
|
||||
*
|
||||
* @param mode The gamemode as an object.
|
||||
*
|
||||
* @return True if the mode was set, false if not.
|
||||
*/
|
||||
private boolean setGameMode(Object mode) {
|
||||
if (mode instanceof Integer) {
|
||||
return this.setGameMode(GameMode.getByValue((Integer) mode));
|
||||
}
|
||||
try {
|
||||
return this.setGameMode((String) mode);
|
||||
} catch (ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setGameMode(GameMode mode) {
|
||||
|
||||
this.gameMode = mode;
|
||||
this.worldSection.set("gamemode", this.gameMode.toString());
|
||||
saveConfig();
|
||||
|
||||
if (MultiverseCore.EnforceGameModes) {
|
||||
for (Player p : this.plugin.getServer().getWorld(this.getName()).getPlayers()) {
|
||||
this.plugin.log(Level.FINER, "Setting " + p.getName() + "'s GameMode to " + this.gameMode.toString());
|
||||
this.plugin.getPlayerListener().handleGameMode(p, this);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
return ((GameModeConfigProperty) this.propertyList.get("mode")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnableWeather(boolean weather) {
|
||||
((BooleanConfigProperty) this.propertyList.get("weather")).setValue(weather);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWeatherEnabled() {
|
||||
return this.allowWeather;
|
||||
return ((BooleanConfigProperty) this.propertyList.get("weather")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKeepingSpawnInMemory() {
|
||||
return this.keepSpawnInMemory;
|
||||
return ((BooleanConfigProperty) this.propertyList.get("memory")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHunger(boolean hunger) {
|
||||
this.hunger = hunger;
|
||||
this.worldSection.set("hunger", this.hunger);
|
||||
saveConfig();
|
||||
((BooleanConfigProperty) this.propertyList.get("weather")).setValue(hunger);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHunger() {
|
||||
return this.hunger;
|
||||
return ((BooleanConfigProperty) this.propertyList.get("hunger")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawnLocation(Location l) {
|
||||
this.getCBWorld().setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
this.worldSection.set("spawn.x", l.getX());
|
||||
this.worldSection.set("spawn.y", l.getY());
|
||||
this.worldSection.set("spawn.z", l.getZ());
|
||||
this.worldSection.set("spawn.pitch", l.getPitch());
|
||||
this.worldSection.set("spawn.yaw", l.getYaw());
|
||||
this.getCBWorld().setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
this.spawnLocation = l.clone();
|
||||
saveConfig();
|
||||
((LocationConfigProperty) this.propertyList.get("spawn")).setValue(l);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
private void readSpawnFromConfig(World w) {
|
||||
double x = worldSection.getDouble("spawn.x", w.getSpawnLocation().getX());
|
||||
double y = worldSection.getDouble("spawn.y", w.getSpawnLocation().getY());
|
||||
double z = worldSection.getDouble("spawn.z", w.getSpawnLocation().getZ());
|
||||
private Location readSpawnFromConfig(World w) {
|
||||
Location spawnLocation = w.getSpawnLocation();
|
||||
double x = worldSection.getDouble("spawn.x", spawnLocation.getX());
|
||||
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);
|
||||
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.plugin.log(Level.FINEST, "Spawn for '" + this.getName() + "' Located at: " + LocationManipulation.locationToString(this.getSpawnLocation()));
|
||||
SafeTTeleporter teleporter = this.plugin.getTeleporter();
|
||||
BlockSafety bs = new BlockSafety();
|
||||
if (!bs.playerCanSpawnHereSafely(this.spawnLocation)) {
|
||||
if (!this.adjustSpawn) {
|
||||
if (!bs.playerCanSpawnHereSafely(spawnLocation)) {
|
||||
if (!((BooleanConfigProperty) this.propertyList.get("adjustspawn")).getValue()) {
|
||||
this.plugin.log(Level.WARNING, "Spawn location from world.dat file was unsafe!!");
|
||||
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, "/mvm set adjustspawn true " + this.getAlias());
|
||||
return;
|
||||
return spawnLocation;
|
||||
}
|
||||
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(spawnLocation, 128, 128);
|
||||
// I think we could also do this, as I think this is what Notch does.
|
||||
// Not sure how it will work in the nether...
|
||||
//Location newSpawn = this.spawnLocation.getWorld().getHighestBlockAt(this.spawnLocation).getLocation();
|
||||
@ -786,12 +627,12 @@ public class MVWorld implements MultiverseWorld {
|
||||
this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!");
|
||||
}
|
||||
}
|
||||
|
||||
return spawnLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getSpawnLocation() {
|
||||
return this.spawnLocation;
|
||||
return ((LocationConfigProperty) this.propertyList.get("spawn")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -799,74 +640,34 @@ public class MVWorld implements MultiverseWorld {
|
||||
return this.getCBWorld().getDifficulty();
|
||||
}
|
||||
|
||||
/**
|
||||
* FernFerret messed up and now config values could be in either string or Int
|
||||
*
|
||||
* @param mode The gamemode as an object.
|
||||
*
|
||||
* @return True if the mode was set, false if not.
|
||||
*/
|
||||
private boolean setDifficulty(Object mode) {
|
||||
if (mode instanceof Integer) {
|
||||
return this.setDifficulty(Difficulty.getByValue((Integer) mode));
|
||||
}
|
||||
try {
|
||||
return this.setDifficulty((String) mode);
|
||||
} catch (ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDifficulty(String difficulty) {
|
||||
Difficulty worlddiff;
|
||||
try {
|
||||
worlddiff = Difficulty.valueOf(difficulty.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
int diff = Integer.parseInt(difficulty);
|
||||
worlddiff = Difficulty.getByValue(diff);
|
||||
|
||||
} catch (Exception e2) {
|
||||
return false;
|
||||
}
|
||||
if (this.propertyList.get("diff").parseValue(difficulty)) {
|
||||
saveConfig();
|
||||
return true;
|
||||
}
|
||||
if (worlddiff == null) {
|
||||
return false;
|
||||
}
|
||||
this.setDifficulty(worlddiff);
|
||||
saveConfig();
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean setDifficulty(Difficulty diff) {
|
||||
this.getCBWorld().setDifficulty(diff);
|
||||
this.worldSection.set("difficulty", diff.toString());
|
||||
saveConfig();
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAutoHeal() {
|
||||
return this.autoheal;
|
||||
return ((BooleanConfigProperty) this.propertyList.get("autoheal")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoHeal(boolean heal) {
|
||||
this.autoheal = heal;
|
||||
this.worldSection.set("autoheal", this.autoheal);
|
||||
((BooleanConfigProperty) this.propertyList.get("autoheal")).setValue(heal);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdjustSpawn(boolean adjust) {
|
||||
this.adjustSpawn = adjust;
|
||||
this.worldSection.set("adjustspawn", this.adjustSpawn);
|
||||
((BooleanConfigProperty) this.propertyList.get("adjustspawn")).setValue(adjust);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAdjustSpawn() {
|
||||
return this.adjustSpawn;
|
||||
return ((BooleanConfigProperty) this.propertyList.get("adjustspawn")).getValue();
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -52,7 +53,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
public static boolean EnforceGameModes;
|
||||
public static boolean PrefixChat;
|
||||
public static boolean BedRespawn;
|
||||
private File testConfigDirectory;
|
||||
private PluginDescriptionFile testDescriptionFile;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "The Multiverse-Core Plugin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String dumpVersionInfo(String buffer) {
|
||||
@ -91,7 +98,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// Configurations
|
||||
private FileConfiguration multiverseConfig = null;
|
||||
|
||||
private WorldManager worldManager = new WorldManager(this);
|
||||
private WorldManager worldManager;
|
||||
|
||||
// Setup the block/player/entity listener.
|
||||
private MVPlayerListener playerListener = new MVPlayerListener(this);
|
||||
@ -124,6 +131,28 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
debugLog = new DebugLog("Multiverse-Core", getDataFolder() + File.separator + "debug.log");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
if (this.testConfigDirectory != null) {
|
||||
return this.testConfigDirectory;
|
||||
}
|
||||
return super.getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginDescriptionFile getDescription() {
|
||||
if (this.testDescriptionFile != null) {
|
||||
return this.testDescriptionFile;
|
||||
}
|
||||
return super.getDescription(); //To change body of overridden methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
public void setTestMode(File configDir, PluginDescriptionFile descriptionFile) {
|
||||
this.testConfigDirectory = configDir;
|
||||
this.testDescriptionFile = descriptionFile;
|
||||
}
|
||||
|
||||
public FileConfiguration getMVConfiguration() {
|
||||
return this.multiverseConfig;
|
||||
}
|
||||
@ -133,6 +162,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
System.out.println("Enabling... Found server... " + this.getServer());
|
||||
this.worldManager = new WorldManager(this);
|
||||
// Perform initial checks for AllPay
|
||||
if (!this.validateAllpay() || !this.validateCH()) {
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
@ -230,6 +261,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
|
||||
/** Function to Register all the Events needed. */
|
||||
private void registerEvents() {
|
||||
System.out.print(getServer().getName());
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
// pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Highest, this); // Low so it acts above any other.
|
||||
pm.registerEvent(Event.Type.PLAYER_TELEPORT, this.playerListener, Priority.Highest, this); // Cancel Teleports if needed.
|
||||
@ -453,6 +485,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private String getAuthors() {
|
||||
String authors = "";
|
||||
ArrayList<String> auths = this.getDescription().getAuthors();
|
||||
if (auths.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (auths.size() == 1) {
|
||||
return auths.get(0);
|
||||
@ -488,8 +523,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER"))
|
||||
env = "NETHER";
|
||||
|
||||
if (env.equalsIgnoreCase("SKYLANDS") || env.equalsIgnoreCase("SKYLAND") || env.equalsIgnoreCase("STARWARS"))
|
||||
env = "SKYLANDS";
|
||||
if (env.equalsIgnoreCase("END") || env.equalsIgnoreCase("THEEND") || env.equalsIgnoreCase("STARWARS"))
|
||||
env = "THE_END";
|
||||
|
||||
if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD"))
|
||||
env = "NORMAL";
|
||||
@ -544,15 +579,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
return this.destFactory;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public com.onarandombox.utils.DestinationFactory getDestinationFactory() {
|
||||
return new com.onarandombox.utils.DestinationFactory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a convenience method to allow the QueuedCommand system to call it. You should NEVER call this directly.
|
||||
*
|
||||
* @param p Player
|
||||
* @param teleporter The Person requesting that the teleport should happen.
|
||||
* @param p Player The Person being teleported.
|
||||
* @param l The potentially unsafe location.
|
||||
*/
|
||||
public void teleportPlayer(CommandSender teleporter, Player p, Location l) {
|
||||
@ -560,6 +591,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.getTeleporter().safelyTeleport(teleporter, p, l, false);
|
||||
}
|
||||
|
||||
|
||||
public File getServerFolder() {
|
||||
return new File(this.getDataFolder().getAbsolutePath()).getParentFile().getParentFile();
|
||||
}
|
||||
|
||||
private void checkServerProps() {
|
||||
File serverFolder = new File(this.getDataFolder().getAbsolutePath()).getParentFile().getParentFile();
|
||||
File serverProperties = new File(serverFolder.getAbsolutePath() + File.separator + "server.properties");
|
||||
|
@ -141,4 +141,12 @@ public interface MVWorldManager {
|
||||
* @return A valid {@link PurgeWorlds}.
|
||||
*/
|
||||
public PurgeWorlds getWorldPurger();
|
||||
|
||||
/**
|
||||
* Gets the world players will spawn in on first join.
|
||||
* Currently this always returns worlds.get(0) from Bukkit.
|
||||
*
|
||||
* @return A Multiverse world that players will spawn in or null if no MV world has been set.
|
||||
*/
|
||||
public MultiverseWorld getSpawnWorld();
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.configuration.MVConfigProperty;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
@ -27,14 +29,41 @@ public interface MultiverseWorld {
|
||||
public World getCBWorld();
|
||||
|
||||
/**
|
||||
* Adds the property to the given value. The property must be a {@link com.onarandombox.MultiverseCore.enums.SetProperties}.
|
||||
* Adds the property to the given value.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.SetProperties} to set.
|
||||
* @param property The name of a world property to set.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
*
|
||||
* @return True if the value was set, false if not.
|
||||
*
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
public boolean setVariable(String property, String value);
|
||||
public boolean setProperty(String property, String value) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Gets the actual MVConfigProperty from this world.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
*
|
||||
* @return A valid MVWorldProperty.
|
||||
*
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
public MVConfigProperty getProperty(String property) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Gets the string representation of a property.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
*
|
||||
* @return A valid MVWorldProperty.
|
||||
*
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
public String getPropertyValue(String property) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
@ -177,6 +206,7 @@ public interface MultiverseWorld {
|
||||
*
|
||||
* @return True if this world has fakepvp on
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getFakePVP();
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,7 @@ public class CreateCommand extends MultiverseCommand {
|
||||
this.setPermission("multiverse.core.create", "Creates a new world and loads it.", PermissionDefault.OP);
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "world" + ChatColor.GREEN + " normal");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "lavaland" + ChatColor.RED + " nether");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "starwars" + ChatColor.AQUA + " skylands");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "starwars" + ChatColor.AQUA + " end");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -s gargamel");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon");
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
|
@ -33,7 +33,7 @@ public class EnvironmentCommand extends MultiverseCommand {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:");
|
||||
sender.sendMessage(ChatColor.GREEN + "NORMAL");
|
||||
sender.sendMessage(ChatColor.RED + "NETHER");
|
||||
sender.sendMessage(ChatColor.AQUA + "SKYLANDS");
|
||||
sender.sendMessage(ChatColor.AQUA + "END");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -138,7 +138,6 @@ public class InfoCommand extends MultiverseCommand {
|
||||
message.add(new FancyHeader("PVP Settings", colors));
|
||||
message.add(new FancyMessage("Multiverse Setting: ", world.isPVPEnabled() + "", colors));
|
||||
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getPVP() + "", colors));
|
||||
message.add(new FancyMessage("Fake PVP Enabled: ", world.getFakePVP() + "", colors));
|
||||
worldInfo.add(message);
|
||||
// Page 3
|
||||
message = new ArrayList<FancyText>();
|
||||
|
@ -50,7 +50,7 @@ public class ListCommand extends MultiverseCommand {
|
||||
color = ChatColor.RED;
|
||||
} else if (env == Environment.NORMAL) {
|
||||
color = ChatColor.GREEN;
|
||||
} else if (env == Environment.SKYLANDS) {
|
||||
} else if (env == Environment.THE_END) {
|
||||
color = ChatColor.AQUA;
|
||||
}
|
||||
String outputCache = world.getColoredWorldString() + ChatColor.WHITE + " - " + color + world.getEnvironment() + " \n";
|
||||
|
@ -10,7 +10,6 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import com.onarandombox.MultiverseCore.enums.AddProperties;
|
||||
import com.onarandombox.MultiverseCore.enums.SetProperties;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@ -40,14 +39,7 @@ public class ModifyCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
protected static boolean validateAction(Action action, String property) {
|
||||
if (action == Action.Set) {
|
||||
try {
|
||||
SetProperties.valueOf(property);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (action != Action.Set) {
|
||||
try {
|
||||
AddProperties.valueOf(property);
|
||||
return true;
|
||||
@ -55,6 +47,7 @@ public class ModifyCommand extends MultiverseCommand {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,8 +9,8 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -55,6 +55,10 @@ public class ModifySetCommand extends MultiverseCommand {
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// Special case for spawn:
|
||||
if (args.size() == 1) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You must be a player to set the" + ChatColor.GREEN + " spawn");
|
||||
return;
|
||||
}
|
||||
if (args.get(0).equalsIgnoreCase("spawn")) {
|
||||
SetSpawnCommand c = new SetSpawnCommand(this.plugin);
|
||||
c.setWorldSpawn(sender);
|
||||
@ -94,18 +98,21 @@ public class ModifySetCommand extends MultiverseCommand {
|
||||
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)) {
|
||||
sender.sendMessage(value + " is not a valid color. Please pick one of the following:");
|
||||
sender.sendMessage(EnglishChatColor.getAllColors());
|
||||
} else 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);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (world.setProperty(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
||||
} else {
|
||||
sender.sendMessage(world.getProperty(property).getHelp());
|
||||
}
|
||||
} 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,29 @@
|
||||
/******************************************************************************
|
||||
* 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.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public abstract class PaginatedCommand extends MultiverseCommand {
|
||||
|
||||
private int linesToShow = 9;
|
||||
|
||||
public PaginatedCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
protected void displayPage(CommandSender s, int pageNum, String filter) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
private String help;
|
||||
|
||||
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String help) {
|
||||
this.name = name;
|
||||
this.configNode = name;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.setValue(this.section.getBoolean(this.configNode, defaultValue));
|
||||
}
|
||||
|
||||
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
private String help;
|
||||
|
||||
public ColorConfigProperty(ConfigurationSection section, String name, EnglishChatColor defaultValue, String help) {
|
||||
this.name = name;
|
||||
this.configNode = name;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||
}
|
||||
|
||||
public ColorConfigProperty(ConfigurationSection section, String name, EnglishChatColor defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
}
|
@ -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, String help) {
|
||||
return new BooleanConfigProperty(this.section, name, defaultValue, help);
|
||||
}
|
||||
|
||||
public BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String node, String help) {
|
||||
return new BooleanConfigProperty(this.section, name, defaultValue, node, help) ;
|
||||
}
|
||||
|
||||
// Integers
|
||||
public IntegerConfigProperty getNewProperty(String name, int defaultValue, String help) {
|
||||
return new IntegerConfigProperty(this.section, name, defaultValue, help) ;
|
||||
}
|
||||
|
||||
public IntegerConfigProperty getNewProperty(String name, int defaultValue, String node, String help) {
|
||||
return new IntegerConfigProperty(this.section, name, defaultValue, node, help) ;
|
||||
}
|
||||
|
||||
// Doubles
|
||||
public DoubleConfigProperty getNewProperty(String name, double defaultValue, String help) {
|
||||
return new DoubleConfigProperty(this.section, name, defaultValue, help) ;
|
||||
}
|
||||
|
||||
public DoubleConfigProperty getNewProperty(String name, double defaultValue, String node, String help) {
|
||||
return new DoubleConfigProperty(this.section, name, defaultValue, node, help) ;
|
||||
}
|
||||
|
||||
// Strings
|
||||
public StringConfigProperty getNewProperty(String name, String defaultValue, String help) {
|
||||
return new StringConfigProperty(this.section, name, defaultValue, help) ;
|
||||
}
|
||||
|
||||
public StringConfigProperty getNewProperty(String name, String defaultValue, String node, String help) {
|
||||
return new StringConfigProperty(this.section, name, defaultValue, node, help) ;
|
||||
}
|
||||
|
||||
// Colors
|
||||
public ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue, String help) {
|
||||
return new ColorConfigProperty(this.section, name, defaultValue, help) ;
|
||||
}
|
||||
|
||||
public ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue, String node, String help) {
|
||||
return new ColorConfigProperty(this.section, name, defaultValue, node, help) ;
|
||||
}
|
||||
|
||||
// Difficulty
|
||||
public DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue, String help) {
|
||||
return new DifficultyConfigProperty(this.section, name, defaultValue, help) ;
|
||||
}
|
||||
|
||||
public DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue, String node, String help) {
|
||||
return new DifficultyConfigProperty(this.section, name, defaultValue, node, help) ;
|
||||
}
|
||||
|
||||
// GameMode
|
||||
public GameModeConfigProperty getNewProperty(String name, GameMode defaultValue, String help) {
|
||||
return new GameModeConfigProperty(this.section, name, defaultValue, help) ;
|
||||
}
|
||||
|
||||
public GameModeConfigProperty getNewProperty(String name, GameMode defaultValue, String node, String help) {
|
||||
return new GameModeConfigProperty(this.section, name, defaultValue, node, help) ;
|
||||
}
|
||||
|
||||
// GameMode
|
||||
public LocationConfigProperty getNewProperty(String name, Location defaultValue, String help) {
|
||||
return new LocationConfigProperty(this.section, name, defaultValue, help) ;
|
||||
}
|
||||
|
||||
public LocationConfigProperty getNewProperty(String name, Location defaultValue, String node, String help) {
|
||||
return new LocationConfigProperty(this.section, name, defaultValue, node, help) ;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
private String help;
|
||||
|
||||
public DifficultyConfigProperty(ConfigurationSection section, String name, Difficulty defaultValue, String help) {
|
||||
this.name = name;
|
||||
this.configNode = name;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||
}
|
||||
|
||||
public DifficultyConfigProperty(ConfigurationSection section, String name, Difficulty defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
private String help;
|
||||
|
||||
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String help) {
|
||||
this.name = name;
|
||||
this.configNode = name;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.setValue(this.section.getDouble(this.configNode, defaultValue));
|
||||
}
|
||||
|
||||
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
private String help;
|
||||
|
||||
public GameModeConfigProperty(ConfigurationSection section, String name, GameMode defaultValue, String help) {
|
||||
this.name = name;
|
||||
this.configNode = name;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
||||
}
|
||||
|
||||
public GameModeConfigProperty(ConfigurationSection section, String name, GameMode defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
private String help;
|
||||
|
||||
public IntegerConfigProperty(ConfigurationSection section, String name, Integer defaultValue, String help) {
|
||||
this.name = name;
|
||||
this.configNode = name;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.setValue(this.section.getInt(this.configNode, defaultValue));
|
||||
}
|
||||
|
||||
public IntegerConfigProperty(ConfigurationSection section, String name, Integer defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
private String help;
|
||||
|
||||
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String help) {
|
||||
this.name = name;
|
||||
this.configNode = name;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.setValue(this.getLocationFromConfig(this.configNode, defaultValue));
|
||||
}
|
||||
|
||||
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
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 String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
public interface MVConfigProperty<T> {
|
||||
/**
|
||||
* Gets the name of this property.
|
||||
*
|
||||
* @return The name of this property.
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* Gets the help string for this
|
||||
*
|
||||
* @return The value of this property as a string.
|
||||
*/
|
||||
public String getHelp();
|
||||
|
||||
/**
|
||||
* 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,83 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
private String help;
|
||||
|
||||
public StringConfigProperty(ConfigurationSection section, String name, String defaultValue, String help) {
|
||||
this.name = name;
|
||||
this.configNode = name;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
this.parseValue(this.section.getString(this.configNode, defaultValue));
|
||||
}
|
||||
|
||||
public StringConfigProperty(ConfigurationSection section, String name, String defaultValue, String configNode, String help) {
|
||||
this.name = name;
|
||||
this.configNode = configNode;
|
||||
this.section = section;
|
||||
this.help = help;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the help string for this
|
||||
*
|
||||
* @return The value of this property as a string.
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setValue(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.value = value;
|
||||
this.section.set(configNode, this.value);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -49,47 +49,6 @@ public class MVEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event - When a Entity is Damaged, we first sort out whether it is of importance to us, such as EntityVSEntity or
|
||||
* EntityVSProjectile. Then we grab the attacked and defender and check if its a player. Then deal with the PVP
|
||||
* Aspect.
|
||||
*/
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Entity attacker;
|
||||
Entity defender;
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
|
||||
attacker = sub.getDamager();
|
||||
defender = sub.getEntity();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (attacker == null || defender == null) {
|
||||
return;
|
||||
}
|
||||
if (defender instanceof Player) {
|
||||
Player player = (Player) defender;
|
||||
World w = player.getWorld();
|
||||
|
||||
if (w == null || !this.worldManager.isMVWorld(w.getName())) {
|
||||
// if the world is not handled, we don't care
|
||||
return;
|
||||
}
|
||||
MultiverseWorld world = this.worldManager.getMVWorld(w.getName());
|
||||
|
||||
if (attacker instanceof Player) {
|
||||
if (!world.isPVPEnabled() && world.getFakePVP()) {
|
||||
((Player) attacker).sendMessage(ChatColor.RED + "PVP is disabled in this World.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
|
@ -27,24 +27,11 @@ public class MVPluginListener extends ServerListener {
|
||||
/** Keep an eye out for Plugins which we can utilize. */
|
||||
@Override
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (event.getPlugin() instanceof com.onarandombox.MultiverseCore.MVPlugin) {
|
||||
this.plugin.log(Level.SEVERE, "Your version of '" + event.getPlugin() + "' is OUT OF DATE.");
|
||||
this.plugin.log(Level.SEVERE, "Please grab the latest version from:");
|
||||
this.plugin.log(Level.SEVERE, "http://bukkit.onarandombox.com/?dir=" + event.getPlugin().getDescription().getName().toLowerCase());
|
||||
this.plugin.log(Level.SEVERE, "I'm going to disable " + event.getPlugin().getDescription().getName() + " now.");
|
||||
this.plugin.log(Level.SEVERE, "IF YOU DO NOT UPDATE, YOUR SERVER WILL **NOT** FUNCTION PROPERLY!!!");
|
||||
this.plugin.getServer().getPluginManager().disablePlugin(event.getPlugin());
|
||||
}
|
||||
// Let AllPay handle all econ plugin loadings, only go for econ plugins we support
|
||||
if (Arrays.asList(AllPay.validEconPlugins).contains(event.getPlugin().getDescription().getName())) {
|
||||
this.plugin.setBank(this.plugin.getBanker().loadEconPlugin());
|
||||
}
|
||||
if (event.getPlugin().getDescription().getName().equals("MultiVerse")) {
|
||||
if (event.getPlugin().isEnabled()) {
|
||||
this.plugin.getServer().getPluginManager().disablePlugin(event.getPlugin());
|
||||
this.plugin.log(Level.WARNING, "I just disabled the old version of Multiverse for you. You should remove the JAR now, your configs have been migrated.");
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getPlugin().getDescription().getName().equals("Spout")) {
|
||||
this.plugin.setSpout();
|
||||
this.plugin.log(Level.INFO, "Spout integration enabled.");
|
||||
|
@ -25,13 +25,6 @@ public class BlockSafety {
|
||||
|
||||
/**
|
||||
* This function checks whether the block at the given coordinates are above air or not.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isBlockAboveAir(Location l) {
|
||||
Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
|
||||
@ -53,29 +46,25 @@ public class BlockSafety {
|
||||
* This function checks whether the block at the coordinates given is safe or not by checking for Laval/Fire/Air
|
||||
* etc. This also ensures there is enough space for a player to spawn!
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean playerCanSpawnHereSafely(Location l) {
|
||||
World world = l.getWorld();
|
||||
Location actual = l.clone();
|
||||
Location upOne = l.clone();
|
||||
Location downOne = l.clone();
|
||||
upOne.setY(upOne.getY() + 1);
|
||||
downOne.setY(downOne.getY() - 1);
|
||||
|
||||
if (this.isSolidBlock(actual.getBlock().getType()) || this.isSolidBlock(upOne.getBlock().getType())) {
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
if (this.isSolidBlock(world.getBlockAt(actual).getType()) ||
|
||||
this.isSolidBlock(upOne.getBlock().getType())) {
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here (Actual)? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here (upOne)? (" + upOne.getBlock().getType() + ")[" + this.isSolidBlock(upOne.getBlock().getType()) + "]");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here (downOne)? (" + downOne.getBlock().getType() + ")[" + this.isSolidBlock(downOne.getBlock().getType()) + "]");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -224,4 +225,43 @@ public class LocationManipulation {
|
||||
int z = vector.getZ() < 0 ? vector.getZ() == 0 ? 0 : -1 : 1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,6 +351,11 @@ public class WorldManager implements MVWorldManager {
|
||||
// Force the worlds to be loaded, ie don't just load new worlds.
|
||||
if (forceLoad) {
|
||||
// Remove all world permissions.
|
||||
System.out.println(this.plugin);
|
||||
System.out.println("Server2: " + this.plugin.getServer());
|
||||
System.out.println(this.plugin.getServer().getPluginManager());
|
||||
System.out.println(this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*"));
|
||||
|
||||
Permission allAccess = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
|
||||
Permission allExempt = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*");
|
||||
for (MultiverseWorld w : this.worlds.values()) {
|
||||
@ -420,4 +425,8 @@ public class WorldManager implements MVWorldManager {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public MultiverseWorld getSpawnWorld() {
|
||||
return this.getMVWorld(this.plugin.getServer().getWorlds().get(0));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
/******************************************************************************
|
||||
* 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.test;
|
||||
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.test.utils.MVCoreFactory;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.utils.FileUtils;
|
||||
import junit.framework.Assert;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MultiverseCore.class})
|
||||
public class TestDebugMode {
|
||||
@After
|
||||
public void tearDown() throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException {
|
||||
Field serverField = Bukkit.class.getDeclaredField("server");
|
||||
serverField.setAccessible(true);
|
||||
serverField.set(Class.forName("org.bukkit.Bukkit"), null);
|
||||
if (MVCoreFactory.serverDirectory.exists()) {
|
||||
MVCoreFactory.serverDirectory.delete();
|
||||
FileUtils.deleteFolder(MVCoreFactory.serverDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (!MVCoreFactory.serverDirectory.exists()) {
|
||||
MVCoreFactory.serverDirectory.mkdirs();
|
||||
}
|
||||
if (!MVCoreFactory.pluginDirectory.exists()) {
|
||||
MVCoreFactory.pluginDirectory.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnableDebugMode() {
|
||||
TestInstanceCreator creator = new TestInstanceCreator();
|
||||
Server mockServer = creator.setupDefaultServerInstance();
|
||||
CommandSender mockCommandSender = creator.getCommandSender();
|
||||
// Start actual testing.
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make sure Core is not null
|
||||
Assert.assertNotNull(plugin);
|
||||
|
||||
// Make sure Core is enabled
|
||||
Assert.assertTrue(plugin.isEnabled());
|
||||
|
||||
// Make a fake server folder to fool MV into thinking a world folder exists.
|
||||
File serverDirectory = new File(creator.getCore().getServerFolder(), "world");
|
||||
serverDirectory.mkdirs();
|
||||
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
|
||||
// Assert debug mode is off
|
||||
Assert.assertEquals(0, MultiverseCore.GlobalDebug);
|
||||
|
||||
// Send the debug command.
|
||||
String[] debugArgs = new String[]{"debug", "3"};
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", debugArgs);
|
||||
|
||||
Assert.assertEquals(3, MultiverseCore.GlobalDebug);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.bukkit.World;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class TestMockWorld {
|
||||
private World mockWorld;
|
||||
private World mockNetherWorld;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Initialize a fake world and world_nether.
|
||||
this.mockWorld = mock(World.class);
|
||||
when(this.mockWorld.getName()).thenReturn("world");
|
||||
when(this.mockWorld.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
|
||||
this.mockNetherWorld = mock(World.class);
|
||||
when(this.mockNetherWorld.getName()).thenReturn("world_nether");
|
||||
when(this.mockNetherWorld.getEnvironment()).thenReturn(World.Environment.NETHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldInit() {
|
||||
Assert.assertNotNull(this.mockWorld);
|
||||
Assert.assertNotNull(this.mockNetherWorld);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldNames() {
|
||||
// Test the mock world objects
|
||||
Assert.assertEquals(this.mockWorld.getName(), "world");
|
||||
Assert.assertEquals(this.mockNetherWorld.getName(), "world_nether");
|
||||
verify(this.mockWorld).getName();
|
||||
verify(this.mockNetherWorld).getName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldEnvironments() {
|
||||
// Test the environments
|
||||
Assert.assertEquals(this.mockWorld.getEnvironment(), World.Environment.NORMAL);
|
||||
Assert.assertEquals(this.mockNetherWorld.getEnvironment(), World.Environment.NETHER);
|
||||
verify(this.mockWorld).getEnvironment();
|
||||
verify(this.mockNetherWorld).getEnvironment();
|
||||
}
|
||||
}
|
@ -0,0 +1,182 @@
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.test.utils.MVCoreFactory;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.test.utils.WorldCreatorMatcher;
|
||||
import com.onarandombox.MultiverseCore.utils.FileUtils;
|
||||
import junit.framework.Assert;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.internal.verification.VerificationModeFactory;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class})
|
||||
public class TestWorldImport {
|
||||
|
||||
@After
|
||||
public void tearDown() throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException {
|
||||
Field serverField = Bukkit.class.getDeclaredField("server");
|
||||
serverField.setAccessible(true);
|
||||
serverField.set(Class.forName("org.bukkit.Bukkit"), null);
|
||||
if (MVCoreFactory.serverDirectory.exists()) {
|
||||
MVCoreFactory.serverDirectory.delete();
|
||||
FileUtils.deleteFolder(MVCoreFactory.serverDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (!MVCoreFactory.serverDirectory.exists()) {
|
||||
MVCoreFactory.serverDirectory.mkdirs();
|
||||
}
|
||||
|
||||
if (!MVCoreFactory.pluginDirectory.exists()) {
|
||||
MVCoreFactory.pluginDirectory.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldImportWithNoFolder() {
|
||||
TestInstanceCreator creator = new TestInstanceCreator();
|
||||
Server mockServer = creator.setupDefaultServerInstance();
|
||||
CommandSender mockCommandSender = creator.getCommandSender();
|
||||
|
||||
// Make sure the world directory do NOT exist
|
||||
if (new File(MVCoreFactory.serverDirectory, "world").exists()) {
|
||||
new File(MVCoreFactory.serverDirectory, "world").delete();
|
||||
}
|
||||
|
||||
// Start actual testing.
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make sure Core is not null
|
||||
Assert.assertNotNull(plugin);
|
||||
|
||||
// Make sure Core is enabled
|
||||
Assert.assertTrue(plugin.isEnabled());
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
String[] normalArgs = new String[]{"import", "world", "normal"};
|
||||
|
||||
// Ensure we have a fresh copy of MV, 0 worlds.
|
||||
Assert.assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Import the first world. The world folder does not exist.
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||
verify(mockCommandSender).sendMessage(ChatColor.RED + "FAILED.");
|
||||
verify(mockCommandSender).sendMessage("That world folder does not exist...");
|
||||
|
||||
// We should still have no worlds.
|
||||
Assert.assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldImport() {
|
||||
/*TestInstanceCreator creator = new TestInstanceCreator();
|
||||
Server mockServer = creator.setupDefaultServerInstance();
|
||||
CommandSender mockCommandSender = creator.getCommandSender();
|
||||
// Start actual testing.
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make sure Core is not null
|
||||
Assert.assertNotNull(plugin);
|
||||
|
||||
// Make sure Core is enabled
|
||||
Assert.assertTrue(plugin.isEnabled());
|
||||
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
|
||||
// Ensure that there are no worlds imported. This is a fresh setup.
|
||||
Assert.assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Import the first world.
|
||||
String[] normalArgs = new String[]{"import", "world", "normal"};
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||
|
||||
// We should now have one world imported!
|
||||
Assert.assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Import the second world.
|
||||
String[] netherArgs = new String[]{"import", "world_nether", "nether"};
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", netherArgs);
|
||||
|
||||
// We should now have 2 worlds imported!
|
||||
Assert.assertEquals(2, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Import the third world.
|
||||
String[] skyArgs = new String[]{"import", "world_skylands", "skylands"};
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", skyArgs);
|
||||
|
||||
// We should now have 2 worlds imported!
|
||||
Assert.assertEquals(3, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Verify that the commandSender has been called 3 times.
|
||||
verify(mockCommandSender, VerificationModeFactory.times(3)).sendMessage(ChatColor.AQUA + "Starting world import...");
|
||||
verify(mockCommandSender, VerificationModeFactory.times(3)).sendMessage(ChatColor.GREEN + "Complete!");*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldImportWithSeed() {
|
||||
/*TestInstanceCreator creator = new TestInstanceCreator();
|
||||
Server mockServer = creator.setupDefaultServerInstance();
|
||||
CommandSender mockCommandSender = creator.getCommandSender();
|
||||
// Start actual testing.
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make sure Core is not null
|
||||
Assert.assertNotNull(plugin);
|
||||
|
||||
// Make sure Core is enabled
|
||||
Assert.assertTrue(plugin.isEnabled());
|
||||
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
|
||||
// Ensure that there are no worlds imported. This is a fresh setup.
|
||||
Assert.assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Init a new WorldCreatorMatcher to match our seeded world
|
||||
WorldCreator seedCreator = new WorldCreator("world");
|
||||
seedCreator.environment(World.Environment.NORMAL);
|
||||
WorldCreatorMatcher seedMatcher = new WorldCreatorMatcher(seedCreator);
|
||||
|
||||
// For this case, we're testing a seeded import, so we care about the world seed
|
||||
seedMatcher.careAboutSeeds(true);
|
||||
|
||||
|
||||
|
||||
// Import the first world.
|
||||
String[] normalArgs = new String[]{"import", "world", "normal", "-s", "gargamel"};
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||
|
||||
// We should now have one world imported!
|
||||
Assert.assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Verify that the commandSender has been called 1 time.
|
||||
verify(mockCommandSender, VerificationModeFactory.times(1)).sendMessage(ChatColor.AQUA + "Starting world import...");
|
||||
verify(mockCommandSender, VerificationModeFactory.times(1)).sendMessage(ChatColor.GREEN + "Complete!");*/
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/******************************************************************************
|
||||
* 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.test.utils;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class MVCoreFactory {
|
||||
public static final File pluginDirectory = new File("bin/test/server/plugins/coretest");
|
||||
public static final File serverDirectory = new File("bin/test/server");
|
||||
|
||||
public MultiverseCore getNewCore() {
|
||||
|
||||
MultiverseCore core = PowerMockito.spy(new MultiverseCore());
|
||||
|
||||
// Let's let all MV files go to bin/test
|
||||
|
||||
doReturn(pluginDirectory).when(core).getDataFolder();
|
||||
|
||||
// Return a fake PDF file.
|
||||
PluginDescriptionFile pdf = new PluginDescriptionFile("Multiverse-Core", "2.1-Test", "com.onarandombox.MultiverseCore.MultiverseCore");
|
||||
doReturn(pdf).when(core).getDescription();
|
||||
doReturn(true).when(core).isEnabled();
|
||||
return core;
|
||||
}
|
||||
}
|
@ -0,0 +1,408 @@
|
||||
/******************************************************************************
|
||||
* 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.test.utils;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.*;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class MockBlock implements Block{
|
||||
private Material type;
|
||||
private Location location;
|
||||
|
||||
|
||||
public MockBlock(Location l, Material type) {
|
||||
this.type = type;
|
||||
this.location = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the metadata for this block
|
||||
*
|
||||
* @return block specific metadata
|
||||
*/
|
||||
@Override
|
||||
public byte getData() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @deprecated use {@link #getRelative(org.bukkit.block.BlockFace face)} */
|
||||
@Override
|
||||
public Block getFace(BlockFace face) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @deprecated use {@link #getRelative(org.bukkit.block.BlockFace face, int distance)} */
|
||||
@Override
|
||||
public Block getFace(BlockFace face, int distance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block at the given offsets
|
||||
*
|
||||
* @param modX X-coordinate offset
|
||||
* @param modY Y-coordinate offset
|
||||
* @param modZ Z-coordinate offset
|
||||
*
|
||||
* @return Block at the given offsets
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(int modX, int modY, int modZ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block at the given face<br />
|
||||
* <br />
|
||||
* This method is equal to getRelative(face, 1)
|
||||
*
|
||||
* @param face Face of this block to return
|
||||
*
|
||||
* @return Block at the given face
|
||||
*
|
||||
* @see #getRelative(org.bukkit.block.BlockFace, int)
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(BlockFace face) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block at the given distance of the given face<br />
|
||||
* <br />
|
||||
* For example, the following method places water at 100,102,100; two blocks
|
||||
* above 100,100,100.
|
||||
* <pre>
|
||||
* Block block = world.getBlockAt(100,100,100);
|
||||
* Block shower = block.getFace(BlockFace.UP, 2);
|
||||
* shower.setType(Material.WATER);
|
||||
* </pre>
|
||||
*
|
||||
* @param face Face of this block to return
|
||||
* @param distance Distance to get the block at
|
||||
*
|
||||
* @return Block at the given face
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(BlockFace face, int distance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of this block
|
||||
*
|
||||
* @return block type
|
||||
*/
|
||||
@Override
|
||||
public Material getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type-id of this block
|
||||
*
|
||||
* @return block type-id
|
||||
*/
|
||||
@Override
|
||||
public int getTypeId() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the light level between 0-15
|
||||
*
|
||||
* @return light level
|
||||
*/
|
||||
@Override
|
||||
public byte getLightLevel() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the world which contains this Block
|
||||
*
|
||||
* @return World containing this block
|
||||
*/
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.location.getWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x-coordinate of this block
|
||||
*
|
||||
* @return x-coordinate
|
||||
*/
|
||||
@Override
|
||||
public int getX() {
|
||||
return this.location.getBlockX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y-coordinate of this block
|
||||
*
|
||||
* @return y-coordinate
|
||||
*/
|
||||
@Override
|
||||
public int getY() {
|
||||
return this.location.getBlockY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the z-coordinate of this block
|
||||
*
|
||||
* @return z-coordinate
|
||||
*/
|
||||
@Override
|
||||
public int getZ() {
|
||||
return this.location.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Location of the block
|
||||
*
|
||||
* @return Location of block
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk which contains this block
|
||||
*
|
||||
* @return Containing Chunk
|
||||
*/
|
||||
@Override
|
||||
public Chunk getChunk() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the metadata for this block
|
||||
*
|
||||
* @param data New block specific metadata
|
||||
*/
|
||||
@Override
|
||||
public void setData(byte data) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(byte data, boolean applyPhyiscs) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of this block
|
||||
*
|
||||
* @param type Material to change this block to
|
||||
*/
|
||||
@Override
|
||||
public void setType(Material type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type-id of this block
|
||||
*
|
||||
* @param type Type-Id to change this block to
|
||||
*
|
||||
* @return whether the block was changed
|
||||
*/
|
||||
@Override
|
||||
public boolean setTypeId(int type) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTypeId(int type, boolean applyPhysics) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTypeIdAndData(int type, byte data, boolean applyPhyiscs) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the face relation of this block compared to the given block<br />
|
||||
* <br />
|
||||
* For example:
|
||||
* <pre>
|
||||
* Block current = world.getBlockAt(100, 100, 100);
|
||||
* Block target = world.getBlockAt(100, 101, 100);
|
||||
*
|
||||
* current.getFace(target) == BlockFace.Up;
|
||||
* </pre>
|
||||
* <br />
|
||||
* If the given block is not connected to this block, null may be returned
|
||||
*
|
||||
* @param block Block to compare against this block
|
||||
*
|
||||
* @return BlockFace of this block which has the requested block, or null
|
||||
*/
|
||||
@Override
|
||||
public BlockFace getFace(Block block) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures the current state of this block. You may then cast that state
|
||||
* into any accepted type, such as Furnace or Sign.
|
||||
* <p/>
|
||||
* The returned object will never be updated, and you are not guaranteed that
|
||||
* (for example) a sign is still a sign after you capture its state.
|
||||
*
|
||||
* @return BlockState with the current state of this block.
|
||||
*/
|
||||
@Override
|
||||
public BlockState getState() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the biome that this block resides in
|
||||
*
|
||||
* @return Biome type containing this block
|
||||
*/
|
||||
@Override
|
||||
public Biome getBiome() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block is being powered by Redstone.
|
||||
*
|
||||
* @return True if the block is powered.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockPowered() {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block is being indirectly powered by Redstone.
|
||||
*
|
||||
* @return True if the block is indirectly powered.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockIndirectlyPowered() {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block face is being powered by Redstone.
|
||||
*
|
||||
* @param face The block face
|
||||
*
|
||||
* @return True if the block face is powered.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockFacePowered(BlockFace face) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block face is being indirectly powered by Redstone.
|
||||
*
|
||||
* @param face The block face
|
||||
*
|
||||
* @return True if the block face is indirectly powered.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockFaceIndirectlyPowered(BlockFace face) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the redstone power being provided to this block face
|
||||
*
|
||||
* @param face the face of the block to query or BlockFace.SELF for the block itself
|
||||
*
|
||||
* @return The power level.
|
||||
*/
|
||||
@Override
|
||||
public int getBlockPower(BlockFace face) {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the redstone power being provided to this block
|
||||
*
|
||||
* @return The power level.
|
||||
*/
|
||||
@Override
|
||||
public int getBlockPower() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this block is empty.
|
||||
* <p/>
|
||||
* A block is considered empty when {@link #getType()} returns {@link org.bukkit.Material#AIR}.
|
||||
*
|
||||
* @return true if this block is empty
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.type == Material.AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this block is liquid.
|
||||
* <p/>
|
||||
* A block is considered liquid when {@link #getType()} returns {@link org.bukkit.Material#WATER}, {@link
|
||||
* org.bukkit.Material#STATIONARY_WATER}, {@link org.bukkit.Material#LAVA} or {@link
|
||||
* org.bukkit.Material#STATIONARY_LAVA}.
|
||||
*
|
||||
* @return true if this block is liquid
|
||||
*/
|
||||
@Override
|
||||
public boolean isLiquid() {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the temperature of the biome of this block
|
||||
*
|
||||
* @return Temperature of this block
|
||||
*/
|
||||
@Override
|
||||
public double getTemperature() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the humidity of the biome of this block
|
||||
*
|
||||
* @return Humidity of this block
|
||||
*/
|
||||
@Override
|
||||
public double getHumidity() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reaction of the block when moved by a piston
|
||||
*
|
||||
* @return reaction
|
||||
*/
|
||||
@Override
|
||||
public PistonMoveReaction getPistonMoveReaction() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
@ -5,16 +5,12 @@
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.enums;
|
||||
package com.onarandombox.MultiverseCore.test.utils;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/ // Color == Aliascolor
|
||||
public enum SetProperties {
|
||||
alias, animals, monsters, pvp, scaling, aliascolor, color, respawn,
|
||||
currency, curr, price, scale, spawnmemory, memory, weather, storm,
|
||||
gamemode, mode, hunger, difficulty, diff, hidden, spawn, autoheal,
|
||||
heal, adjustspawn
|
||||
*/
|
||||
public class MockBukkitServer {
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
* 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.test.utils;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Matchers;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class MockServerFactory {
|
||||
public Server getMockServer() {
|
||||
Server server = mock(Server.class);
|
||||
when(server.getName()).thenReturn("FernCraft");
|
||||
Logger logger = Logger.getLogger("Multiverse-Core-Test");
|
||||
when(server.getLogger()).thenReturn(logger);
|
||||
|
||||
return server;
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/******************************************************************************
|
||||
* 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.test.utils;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Matchers;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class MockWorldFactory {
|
||||
|
||||
class LocationMatcher extends ArgumentMatcher<Location> {
|
||||
private Location l;
|
||||
|
||||
public LocationMatcher(Location location) {
|
||||
this.l = location;
|
||||
}
|
||||
|
||||
public boolean matches(Object creator) {
|
||||
return creator.equals(l);
|
||||
}
|
||||
}
|
||||
|
||||
class LocationMatcherAbove extends LocationMatcher {
|
||||
|
||||
public LocationMatcherAbove(Location location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
public boolean matches(Object creator) {
|
||||
System.out.println("Checking above...");
|
||||
if (super.l == null || creator == null) {
|
||||
return false;
|
||||
}
|
||||
boolean equal = ((Location) creator).getBlockY() >= super.l.getBlockY();
|
||||
System.out.println("Checking equals/\\..." + equal);
|
||||
return equal;
|
||||
}
|
||||
}
|
||||
|
||||
class LocationMatcherBelow extends LocationMatcher {
|
||||
|
||||
public LocationMatcherBelow(Location location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
public boolean matches(Object creator) {
|
||||
if (super.l == null || creator == null) {
|
||||
return false;
|
||||
}
|
||||
boolean equal = ((Location) creator).getBlockY() < super.l.getBlockY();
|
||||
System.out.println("Checking equals\\/..." + equal);
|
||||
return equal;
|
||||
}
|
||||
}
|
||||
|
||||
public World makeNewMockWorld(String world, World.Environment env) {
|
||||
World mockWorld = mock(World.class);
|
||||
when(mockWorld.getName()).thenReturn(world);
|
||||
when(mockWorld.getEnvironment()).thenReturn(env);
|
||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 0, 0));
|
||||
LocationMatcherAbove matchWorldAbove = new LocationMatcherAbove(new Location(mockWorld, 0, 0, 0));
|
||||
LocationMatcherBelow matchWorldBelow = new LocationMatcherBelow(new Location(mockWorld, 0, 0, 0));
|
||||
when(mockWorld.getBlockAt(Matchers.argThat(matchWorldAbove))).thenReturn(new MockBlock(new Location(mockWorld, 0, 0, 0), Material.AIR));
|
||||
when(mockWorld.getBlockAt(Matchers.argThat(matchWorldBelow))).thenReturn(new MockBlock(new Location(mockWorld, 0, 0, 0), Material.STONE));
|
||||
return mockWorld;
|
||||
}
|
||||
|
||||
public World makeNewMockWorld(String world, World.Environment env, long seed, ChunkGenerator generator) {
|
||||
World w = this.makeNewMockWorld(world, env);
|
||||
when(w.getGenerator()).thenReturn(generator);
|
||||
when(w.getSeed()).thenReturn(seed);
|
||||
return w;
|
||||
}
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
/******************************************************************************
|
||||
* 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.test.utils;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class TestCommandSender implements CommandSender {
|
||||
|
||||
private Server server;
|
||||
private boolean isOp;
|
||||
|
||||
public TestCommandSender(Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends this sender a message
|
||||
*
|
||||
* @param message Message to be displayed
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
System.out.println(ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server instance that this command is running on
|
||||
*
|
||||
* @return Server instance
|
||||
*/
|
||||
@Override
|
||||
public Server getServer() {
|
||||
return this.server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this command sender
|
||||
*
|
||||
* @return Name of the sender
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CONSOLE";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this object contains an override for the specified permission, by fully qualified name
|
||||
*
|
||||
* @param name Name of the permission
|
||||
*
|
||||
* @return true if the permission is set, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this object contains an override for the specified {@link org.bukkit.permissions.Permission}
|
||||
*
|
||||
* @param perm Permission to check
|
||||
*
|
||||
* @return true if the permission is set, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(Permission perm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the specified permission, if set.
|
||||
* <p/>
|
||||
* If a permission override is not set on this object, the default value of the permission will be returned.
|
||||
*
|
||||
* @param name Name of the permission
|
||||
*
|
||||
* @return Value of the permission
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the specified permission, if set.
|
||||
* <p/>
|
||||
* If a permission override is not set on this object, the default value of the permission will be returned
|
||||
*
|
||||
* @param perm Permission to get
|
||||
*
|
||||
* @return Value of the permission
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(Permission perm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new {@link org.bukkit.permissions.PermissionAttachment} with a single permission by name and value
|
||||
*
|
||||
* @param plugin Plugin responsible for this attachment, may not be null or disabled
|
||||
* @param name Name of the permission to attach
|
||||
* @param value Value of the permission
|
||||
*
|
||||
* @return The PermissionAttachment that was just created
|
||||
*/
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new empty {@link org.bukkit.permissions.PermissionAttachment} to this object
|
||||
*
|
||||
* @param plugin Plugin responsible for this attachment, may not be null or disabled
|
||||
*
|
||||
* @return The PermissionAttachment that was just created
|
||||
*/
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily adds a new {@link org.bukkit.permissions.PermissionAttachment} with a single permission by name and
|
||||
* value
|
||||
*
|
||||
* @param plugin Plugin responsible for this attachment, may not be null or disabled
|
||||
* @param name Name of the permission to attach
|
||||
* @param value Value of the permission
|
||||
* @param ticks Amount of ticks to automatically remove this attachment after
|
||||
*
|
||||
* @return The PermissionAttachment that was just created
|
||||
*/
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily adds a new empty {@link org.bukkit.permissions.PermissionAttachment} to this object
|
||||
*
|
||||
* @param plugin Plugin responsible for this attachment, may not be null or disabled
|
||||
* @param ticks Amount of ticks to automatically remove this attachment after
|
||||
*
|
||||
* @return The PermissionAttachment that was just created
|
||||
*/
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given {@link org.bukkit.permissions.PermissionAttachment} from this object
|
||||
*
|
||||
* @param attachment Attachment to remove
|
||||
*
|
||||
* @throws IllegalArgumentException Thrown when the specified attachment isn't part of this object
|
||||
*/
|
||||
@Override
|
||||
public void removeAttachment(PermissionAttachment attachment) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates the permissions for this object, if the attachments have changed values.
|
||||
* <p/>
|
||||
* This should very rarely need to be called from a plugin.
|
||||
*/
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a set containing all of the permissions currently in effect by this object
|
||||
*
|
||||
* @return Set of currently effective permissions
|
||||
*/
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this object is a server operator
|
||||
*
|
||||
* @return true if this is an operator, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return this.isOp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operator status of this object
|
||||
*
|
||||
* @param value New operator value
|
||||
*/
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
this.isOp = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
/******************************************************************************
|
||||
* 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.test.utils;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.mockito.Matchers;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class TestInstanceCreator {
|
||||
MultiverseCore core;
|
||||
private CommandSender commandSender;
|
||||
|
||||
public Server setupDefaultServerInstance() {
|
||||
|
||||
MockWorldFactory worldFactory = new MockWorldFactory();
|
||||
MVCoreFactory coreFactory = new MVCoreFactory();
|
||||
MockServerFactory serverFactory = new MockServerFactory();
|
||||
core = coreFactory.getNewCore();
|
||||
// Add Core to the list of loaded plugins
|
||||
JavaPlugin[] plugins = new JavaPlugin[]{core};
|
||||
|
||||
// Mock the Plugin Manager
|
||||
PluginManager mockPluginManager = PowerMockito.mock(PluginManager.class);
|
||||
when(mockPluginManager.getPlugins()).thenReturn(plugins);
|
||||
when(mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(core);
|
||||
|
||||
// Make some fake folders to fool the fake MV into thinking these worlds exist
|
||||
new File(core.getServerFolder(), "world").mkdirs();
|
||||
new File(core.getServerFolder(), "world_nether").mkdirs();
|
||||
new File(core.getServerFolder(), "world_skylands").mkdirs();
|
||||
|
||||
// Initialize the Mock Worlds
|
||||
World mockWorld = worldFactory.makeNewMockWorld("world", World.Environment.NORMAL);
|
||||
World mockNetherWorld = worldFactory.makeNewMockWorld("world_nether", World.Environment.NETHER);
|
||||
World mockSkyWorld = worldFactory.makeNewMockWorld("world_skylands", World.Environment.THE_END);
|
||||
|
||||
List<World> worldList = new ArrayList<World>();
|
||||
worldList.add(mockWorld);
|
||||
worldList.add(mockNetherWorld);
|
||||
worldList.add(mockSkyWorld);
|
||||
|
||||
// Initialize the Mock server.
|
||||
Server mockServer = serverFactory.getMockServer();
|
||||
|
||||
// Give the server some worlds
|
||||
when(mockServer.getWorld("world")).thenReturn(mockWorld);
|
||||
when(mockServer.getWorld("world_nether")).thenReturn(mockNetherWorld);
|
||||
when(mockServer.getWorld("world_skylands")).thenReturn(mockNetherWorld);
|
||||
when(mockServer.getWorlds()).thenReturn(worldList);
|
||||
when(mockServer.getPluginManager()).thenReturn(mockPluginManager);
|
||||
|
||||
// Initialize some worldCreatorMatchers (so we can see when a specific creator is called)
|
||||
WorldCreatorMatcher matchWorld = new WorldCreatorMatcher(new WorldCreator("world"));
|
||||
WorldCreator netherCreator = new WorldCreator("world_nether");
|
||||
netherCreator.environment(World.Environment.NETHER);
|
||||
WorldCreatorMatcher matchNetherWorld = new WorldCreatorMatcher(netherCreator);
|
||||
|
||||
WorldCreator skyCreator = new WorldCreator("world_skylands");
|
||||
skyCreator.environment(World.Environment.THE_END);
|
||||
WorldCreatorMatcher matchSkyWorld = new WorldCreatorMatcher(skyCreator);
|
||||
|
||||
// If a specific creator is called, return the appropreate world.
|
||||
when(mockServer.createWorld(Matchers.argThat(matchWorld))).thenReturn(mockWorld);
|
||||
when(mockServer.createWorld(Matchers.argThat(matchNetherWorld))).thenReturn(mockNetherWorld);
|
||||
when(mockServer.createWorld(Matchers.argThat(matchSkyWorld))).thenReturn(mockSkyWorld);
|
||||
|
||||
// Override some methods that bukkit normally provides us with for Core
|
||||
doReturn(mockServer).when(core).getServer();
|
||||
|
||||
// Init our command sender
|
||||
commandSender = spy(new TestCommandSender(mockServer));
|
||||
Bukkit.setServer(mockServer);
|
||||
// Load Multiverse Core
|
||||
core.onLoad();
|
||||
|
||||
// Enable it.
|
||||
core.onEnable();
|
||||
return mockServer;
|
||||
}
|
||||
|
||||
public MultiverseCore getCore() {
|
||||
return this.core;
|
||||
}
|
||||
|
||||
public CommandSender getCommandSender() {
|
||||
return commandSender;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/******************************************************************************
|
||||
* 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.test.utils;
|
||||
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
|
||||
public class WorldCreatorMatcher extends ArgumentMatcher<WorldCreator> {
|
||||
private WorldCreator worldCreator;
|
||||
private boolean careAboutSeeds = false;
|
||||
private boolean careAboutGenerators = false;
|
||||
|
||||
public WorldCreatorMatcher(WorldCreator creator) {
|
||||
System.out.println("Creating NEW world matcher.(" + creator.name() + ")");
|
||||
this.worldCreator = creator;
|
||||
}
|
||||
|
||||
public void careAboutSeeds(boolean doICare) {
|
||||
this.careAboutSeeds = doICare;
|
||||
}
|
||||
|
||||
public void careAboutGenerators(boolean doICare) {
|
||||
this.careAboutGenerators = doICare;
|
||||
}
|
||||
|
||||
public boolean matches(Object creator) {
|
||||
System.out.println("Checking world creators.");
|
||||
if (creator == null) {
|
||||
System.out.println("The given creator was null, but I was checking: " + this.worldCreator.name());
|
||||
return false;
|
||||
}
|
||||
System.out.println("Checking Names...(" + ((WorldCreator) creator).name() + ") vs (" + this.worldCreator.name() + ")");
|
||||
System.out.println("Checking Envs...(" + ((WorldCreator) creator).environment() + ") vs (" + this.worldCreator.environment() + ")");
|
||||
if (!((WorldCreator) creator).name().equals(this.worldCreator.name())) {
|
||||
return false;
|
||||
} else if (!((WorldCreator) creator).environment().equals(this.worldCreator.environment())) {
|
||||
System.out.println("Checking Environments...");
|
||||
return false;
|
||||
} else if (careAboutSeeds && ((WorldCreator) creator).seed() != this.worldCreator.seed()) {
|
||||
System.out.print("Checking Seeds...");
|
||||
return false;
|
||||
} else if (careAboutGenerators && !((WorldCreator) creator).generator().equals(this.worldCreator.generator())) {
|
||||
System.out.print("Checking Gens...");
|
||||
return false;
|
||||
}
|
||||
System.out.println("Creators matched!!!");
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user