mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Rewritten for SerializationConfig
Conflicts: src/main/java/com/onarandombox/MultiverseCore/MVWorld.java src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java
This commit is contained in:
commit
c6feb127de
@ -76,7 +76,10 @@
|
|||||||
<module name="UnusedImports">
|
<module name="UnusedImports">
|
||||||
<property name="processJavadoc" value="true"/>
|
<property name="processJavadoc" value="true"/>
|
||||||
</module>
|
</module>
|
||||||
<module name="MethodLength"/>
|
<module name="MethodLength">
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
<property name="countEmpty" value="false"/>
|
||||||
|
</module>
|
||||||
<module name="ParameterNumber"/>
|
<module name="ParameterNumber"/>
|
||||||
<module name="EmptyForIteratorPad"/>
|
<module name="EmptyForIteratorPad"/>
|
||||||
<module name="MethodParamPad"/>
|
<module name="MethodParamPad"/>
|
||||||
|
2
pom.xml
2
pom.xml
@ -198,7 +198,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.main__.util</groupId>
|
<groupId>me.main__.util</groupId>
|
||||||
<artifactId>SerializationConfig</artifactId>
|
<artifactId>SerializationConfig</artifactId>
|
||||||
<version>1.3</version>
|
<version>1.6</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -27,6 +27,7 @@ import com.onarandombox.MultiverseCore.destination.ExactDestination;
|
|||||||
import com.onarandombox.MultiverseCore.destination.PlayerDestination;
|
import com.onarandombox.MultiverseCore.destination.PlayerDestination;
|
||||||
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
||||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||||
|
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||||
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
|
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
|
||||||
@ -42,6 +43,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -52,7 +54,9 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -171,6 +175,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
// Register our config
|
// Register our config
|
||||||
SerializationConfig.registerAll(MultiverseCoreConfiguration.class);
|
SerializationConfig.registerAll(MultiverseCoreConfiguration.class);
|
||||||
|
// Register our world
|
||||||
|
SerializationConfig.registerAll(MVWorld.class);
|
||||||
// Create our DataFolder
|
// Create our DataFolder
|
||||||
getDataFolder().mkdirs();
|
getDataFolder().mkdirs();
|
||||||
// Setup our Debug Log
|
// Setup our Debug Log
|
||||||
@ -297,6 +303,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
this.multiverseConfig.setDefaults(coreDefaults);
|
this.multiverseConfig.setDefaults(coreDefaults);
|
||||||
this.multiverseConfig.options().copyDefaults(false);
|
this.multiverseConfig.options().copyDefaults(false);
|
||||||
this.multiverseConfig.options().copyHeader(true);
|
this.multiverseConfig.options().copyHeader(true);
|
||||||
|
|
||||||
|
this.migrateWorldConfig();
|
||||||
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
|
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
|
||||||
|
|
||||||
MultiverseCoreConfiguration wantedConfig = null;
|
MultiverseCoreConfiguration wantedConfig = null;
|
||||||
@ -371,6 +379,213 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migrate the worlds.yml to SerializationConfig.
|
||||||
|
*/
|
||||||
|
private void migrateWorldConfig() {
|
||||||
|
FileConfiguration wconf = YamlConfiguration
|
||||||
|
.loadConfiguration(new File(getDataFolder(), "worlds.yml"));
|
||||||
|
|
||||||
|
if (!wconf.isConfigurationSection("worlds")) // empty config
|
||||||
|
return;
|
||||||
|
|
||||||
|
Map<String, Object> values = wconf.getConfigurationSection("worlds").getValues(false);
|
||||||
|
|
||||||
|
boolean wasChanged = false;
|
||||||
|
Map<String, Object> newValues = new LinkedHashMap<String, Object>(values.size());
|
||||||
|
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||||
|
if (entry.getValue() instanceof MVWorld) {
|
||||||
|
// fine
|
||||||
|
newValues.put(entry.getKey(), entry.getValue());
|
||||||
|
} else if (entry.getValue() instanceof ConfigurationSection) {
|
||||||
|
// we have to migrate this
|
||||||
|
MVWorld world = new MVWorld(Collections.EMPTY_MAP);
|
||||||
|
ConfigurationSection section = (ConfigurationSection) entry.getValue();
|
||||||
|
|
||||||
|
// migrate animals and monsters
|
||||||
|
if (section.isConfigurationSection("animals")) {
|
||||||
|
ConfigurationSection animalSection = section.getConfigurationSection("animals");
|
||||||
|
if (animalSection.contains("spawn")) {
|
||||||
|
if (animalSection.isBoolean("spawn"))
|
||||||
|
world.setAllowAnimalSpawn(animalSection.getBoolean("spawn"));
|
||||||
|
else
|
||||||
|
world.setAllowAnimalSpawn(Boolean.parseBoolean(animalSection.getString("spawn")));
|
||||||
|
}
|
||||||
|
if (animalSection.isList("exceptions")) {
|
||||||
|
world.getAnimalList().clear();
|
||||||
|
world.getAnimalList().addAll(animalSection.getStringList("exceptions"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (section.isConfigurationSection("monsters")) {
|
||||||
|
ConfigurationSection monsterSection = section.getConfigurationSection("monsters");
|
||||||
|
if (monsterSection.contains("spawn")) {
|
||||||
|
if (monsterSection.isBoolean("spawn"))
|
||||||
|
world.setAllowMonsterSpawn(monsterSection.getBoolean("spawn"));
|
||||||
|
else
|
||||||
|
world.setAllowMonsterSpawn(Boolean.parseBoolean(monsterSection.getString("spawn")));
|
||||||
|
}
|
||||||
|
if (monsterSection.isList("exceptions")) {
|
||||||
|
world.getMonsterList().clear();
|
||||||
|
world.getMonsterList().addAll(monsterSection.getStringList("exceptions"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate entryfee
|
||||||
|
if (section.isConfigurationSection("entryfee")) {
|
||||||
|
ConfigurationSection feeSection = section.getConfigurationSection("entryfee");
|
||||||
|
if (feeSection.isInt("currency"))
|
||||||
|
world.setCurrency(feeSection.getInt("currency"));
|
||||||
|
|
||||||
|
if (feeSection.isDouble("amount"))
|
||||||
|
world.setPrice(feeSection.getDouble("amount"));
|
||||||
|
else if (feeSection.isInt("amount"))
|
||||||
|
world.setPrice(feeSection.getInt("amount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate pvp
|
||||||
|
if (section.isBoolean("pvp")) {
|
||||||
|
world.setPVPMode(section.getBoolean("pvp"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate alias
|
||||||
|
if (section.isConfigurationSection("alias")) {
|
||||||
|
ConfigurationSection aliasSection = section.getConfigurationSection("alias");
|
||||||
|
if (aliasSection.isString("color"))
|
||||||
|
world.setColor(aliasSection.getString("color"));
|
||||||
|
if (aliasSection.isString("name"))
|
||||||
|
world.setAlias(aliasSection.getString("name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate worldblacklist
|
||||||
|
if (section.isList("worldblacklist")) {
|
||||||
|
world.getWorldBlacklist().clear();
|
||||||
|
world.getWorldBlacklist().addAll(section.getStringList("worldblacklist"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate scale
|
||||||
|
if (section.isDouble("scale")) {
|
||||||
|
world.setScaling(section.getDouble("scale"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate gamemode
|
||||||
|
if (section.isString("gamemode")) {
|
||||||
|
try {
|
||||||
|
world.setPropertyValue("gamemode", section.getString("gamemode"));
|
||||||
|
} catch (PropertyDoesNotExistException e) {
|
||||||
|
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate hunger
|
||||||
|
if (section.isBoolean("hunger")) {
|
||||||
|
world.setHunger(section.getBoolean("hunger"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate hidden
|
||||||
|
if (section.isBoolean("hidden")) {
|
||||||
|
world.setHidden(section.getBoolean("hidden"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate autoheal
|
||||||
|
if (section.isBoolean("autoheal")) {
|
||||||
|
world.setAutoHeal(section.getBoolean("autoheal"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate portalform
|
||||||
|
if (section.isString("portalform")) {
|
||||||
|
try {
|
||||||
|
world.setPropertyValue("portalform", section.getString("portalform"));
|
||||||
|
} catch (PropertyDoesNotExistException e) {
|
||||||
|
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate environment
|
||||||
|
if (section.isString("environment")) {
|
||||||
|
try {
|
||||||
|
world.setPropertyValue("environment", section.getString("environment"));
|
||||||
|
} catch (PropertyDoesNotExistException e) {
|
||||||
|
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate generator
|
||||||
|
if (section.isString("generator")) {
|
||||||
|
world.setGenerator(section.getString("generator"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate seed
|
||||||
|
if (section.isLong("seed")) {
|
||||||
|
world.setSeed(section.getLong("seed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate weather
|
||||||
|
if (section.isBoolean("allowweather")) {
|
||||||
|
world.setEnableWeather(section.getBoolean("allowweather"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate adjustspawn
|
||||||
|
if (section.isBoolean("adjustspawn")) {
|
||||||
|
world.setAdjustSpawn(section.getBoolean("adjustspawn"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate autoload
|
||||||
|
if (section.isBoolean("autoload")) {
|
||||||
|
world.setAutoLoad(section.getBoolean("autoload"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate bedrespawn
|
||||||
|
if (section.isBoolean("bedrespawn")) {
|
||||||
|
world.setBedRespawn(section.getBoolean("bedrespawn"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate spawn
|
||||||
|
if (section.isConfigurationSection("spawn")) {
|
||||||
|
ConfigurationSection spawnSect = section.getConfigurationSection("spawn");
|
||||||
|
Location spawnLoc = world.getSpawnLocation();
|
||||||
|
if (spawnSect.isDouble("yaw"))
|
||||||
|
spawnLoc.setYaw((float) spawnSect.getDouble("yaw"));
|
||||||
|
if (spawnSect.isDouble("pitch"))
|
||||||
|
spawnLoc.setPitch((float) spawnSect.getDouble("pitch"));
|
||||||
|
if (spawnSect.isDouble("x"))
|
||||||
|
spawnLoc.setX(spawnSect.getDouble("x"));
|
||||||
|
if (spawnSect.isDouble("y"))
|
||||||
|
spawnLoc.setY(spawnSect.getDouble("y"));
|
||||||
|
if (spawnSect.isDouble("z"))
|
||||||
|
spawnLoc.setZ(spawnSect.getDouble("z"));
|
||||||
|
|
||||||
|
world.setSpawnLocation(spawnLoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
newValues.put(entry.getKey(), world);
|
||||||
|
wasChanged = true;
|
||||||
|
} else {
|
||||||
|
// huh?
|
||||||
|
this.log(Level.WARNING, "Removing unknown entry in the config: " + entry);
|
||||||
|
// just don't add to newValues
|
||||||
|
wasChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wasChanged) {
|
||||||
|
// clear config
|
||||||
|
wconf.set("worlds", null);
|
||||||
|
|
||||||
|
// and rebuild it
|
||||||
|
ConfigurationSection rootSection = wconf.createSection("worlds");
|
||||||
|
for (Map.Entry<String, Object> entry : newValues.entrySet()) {
|
||||||
|
rootSection.set(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
wconf.save(new File(getDataFolder(), "worlds.yml"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@ -424,6 +639,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
this.saveMVConfigs();
|
||||||
debugLog.close();
|
debugLog.close();
|
||||||
this.banker = null;
|
this.banker = null;
|
||||||
this.bank = null;
|
this.bank = null;
|
||||||
|
@ -4,6 +4,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
|
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
|
||||||
|
|
||||||
|
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
||||||
import me.main__.util.SerializationConfig.Property;
|
import me.main__.util.SerializationConfig.Property;
|
||||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||||
|
|
||||||
@ -80,6 +81,18 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
|||||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean setConfigProperty(String property, String value) {
|
||||||
|
try {
|
||||||
|
return this.setProperty(property, value, true);
|
||||||
|
} catch (NoSuchPropertyException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// And here we go:
|
// And here we go:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +12,7 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
|
|||||||
* @param value The value.
|
* @param value The value.
|
||||||
* @return True on success, false if the operation failed.
|
* @return True on success, false if the operation failed.
|
||||||
*/
|
*/
|
||||||
boolean setProperty(String property, String value);
|
boolean setConfigProperty(String property, String value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets portalCooldown.
|
* Sets portalCooldown.
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
package com.onarandombox.MultiverseCore.api;
|
package com.onarandombox.MultiverseCore.api;
|
||||||
|
|
||||||
import com.onarandombox.MultiverseCore.configuration.MVConfigProperty;
|
|
||||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||||
|
|
||||||
@ -26,7 +25,6 @@ import java.util.List;
|
|||||||
* The API for a Multiverse Handled World.
|
* The API for a Multiverse Handled World.
|
||||||
*/
|
*/
|
||||||
public interface MultiverseWorld {
|
public interface MultiverseWorld {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Bukkit world object that this world describes.
|
* Returns the Bukkit world object that this world describes.
|
||||||
*
|
*
|
||||||
@ -35,79 +33,24 @@ public interface MultiverseWorld {
|
|||||||
World getCBWorld();
|
World getCBWorld();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the property to the given value.
|
* Gets the name of this world. The name cannot be changed.
|
||||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
* <p>
|
||||||
|
* Note for plugin developers: Usually {@link #getAlias()}
|
||||||
|
* is what you want to use instead of this method.
|
||||||
*
|
*
|
||||||
* @param property The name of a world property to set.
|
* @return The name of the world as a String.
|
||||||
* @param value A value in string representation, it will be parsed to the correct type.
|
|
||||||
* @param sender The sender who wants this value to be set.
|
|
||||||
* @return True if the value was set, false if not.
|
|
||||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
|
||||||
*/
|
*/
|
||||||
boolean setProperty(String property, String value, CommandSender sender) throws PropertyDoesNotExistException;
|
String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the actual MVConfigProperty from this world.
|
* Gets the type of this world. As of 1.2 this will be:
|
||||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
* FLAT, NORMAL or VERSION_1_1
|
||||||
|
* <p>
|
||||||
|
* This is <b>not</b> the generator.
|
||||||
*
|
*
|
||||||
* @param property The name of a world property to get.
|
* @return The Type of this world.
|
||||||
* @return A valid MVWorldProperty.
|
|
||||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
|
||||||
* @deprecated Use {@link #getProperty(String, Class)} instead
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
WorldType getWorldType();
|
||||||
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.
|
|
||||||
*/
|
|
||||||
String getPropertyValue(String property) 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.
|
|
||||||
* @param expected The type of the expected property. Use Object.class if this doesn't matter for you.
|
|
||||||
* @param <T> The type of the expected property.
|
|
||||||
*
|
|
||||||
* @return A valid MVWorldProperty.
|
|
||||||
*
|
|
||||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
|
||||||
*/
|
|
||||||
<T> MVConfigProperty<T> getProperty(String property, Class<T> expected) throws PropertyDoesNotExistException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
|
||||||
*
|
|
||||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to clear.
|
|
||||||
* @return True if it was cleared, false if not.
|
|
||||||
*/
|
|
||||||
boolean clearVariable(String property);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a value to the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
|
||||||
*
|
|
||||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to add a value to.
|
|
||||||
* @param value A value in string representation, it will be parsed to the correct type.
|
|
||||||
* @return True if the value was added, false if not.
|
|
||||||
*/
|
|
||||||
boolean addToVariable(String property, String value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a value from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
|
||||||
*
|
|
||||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to remove a value
|
|
||||||
* from.
|
|
||||||
* @param value A value in string representation, it will be parsed to the correct type.
|
|
||||||
* @return True if the value was removed, false if not.
|
|
||||||
*/
|
|
||||||
boolean removeFromVariable(String property, String value);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the environment of this world.
|
* Gets the environment of this world.
|
||||||
@ -125,27 +68,168 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
void setEnvironment(World.Environment environment);
|
void setEnvironment(World.Environment environment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the difficulty of this world.
|
||||||
|
*
|
||||||
|
* @return The difficulty of this world.
|
||||||
|
*/
|
||||||
|
Difficulty getDifficulty();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the difficulty of this world and returns true if success.
|
||||||
|
* Valid string values are either an integer of difficulty(0-3) or
|
||||||
|
* the name that resides in the Bukkit enum, ex. {@code PEACEFUL}
|
||||||
|
*
|
||||||
|
* @param difficulty The difficulty to set the world to as a string.
|
||||||
|
* @return True if success, false if the provided string
|
||||||
|
* could not be translated to a difficulty.
|
||||||
|
* @deprecated Use {@link #setDifficulty(Difficulty)} or, if you have to
|
||||||
|
* pass a string, use {@link #setPropertyValue(String, String)} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
boolean setDifficulty(String difficulty);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the difficulty of this world and returns {@code true} on success.
|
||||||
|
* Valid string values are either an integer of difficulty(0-3) or
|
||||||
|
* the name that resides in the Bukkit enum, ex. PEACEFUL
|
||||||
|
*
|
||||||
|
* @param difficulty The new difficulty.
|
||||||
|
* @return True if success, false if the operation failed... for whatever reason.
|
||||||
|
*/
|
||||||
|
boolean setDifficulty(Difficulty difficulty);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the world seed of this world.
|
* Gets the world seed of this world.
|
||||||
*
|
*
|
||||||
* @return The Long version of the seed.
|
* @return The Long version of the seed.
|
||||||
*/
|
*/
|
||||||
Long getSeed();
|
long getSeed();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the seed of this world.
|
* Sets the seed of this world.
|
||||||
*
|
*
|
||||||
* @param seed A Long that is the seed.
|
* @param seed A Long that is the seed.
|
||||||
*/
|
*/
|
||||||
void setSeed(Long seed);
|
void setSeed(long seed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of this world. This cannot be changed.
|
* Gets the generator of this world.
|
||||||
*
|
*
|
||||||
* @return The name of the world as a String.
|
* @return The name of the generator.
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getGenerator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the generator of this world.
|
||||||
|
*
|
||||||
|
* @param generator The new generator's name.
|
||||||
|
*/
|
||||||
|
void setGenerator(String generator);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the help-message for a property.
|
||||||
|
* @param property The name of the property.
|
||||||
|
* @return The help-message.
|
||||||
|
* @throws PropertyDoesNotExistException Thrown if the property was not found.
|
||||||
|
*/
|
||||||
|
String getPropertyHelp(String property) throws PropertyDoesNotExistException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a property as {@link String}.
|
||||||
|
*
|
||||||
|
* @param property The name of a world property to get.
|
||||||
|
* @return The string-representation of that property.
|
||||||
|
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||||
|
*/
|
||||||
|
String getPropertyValue(String property) throws PropertyDoesNotExistException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a property to a given value.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
boolean setPropertyValue(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.
|
||||||
|
* @param expected The type of the expected property. Use Object.class if this doesn't matter for you.
|
||||||
|
* @param <T> The type of the expected property.
|
||||||
|
*
|
||||||
|
* @return A valid MVWorldProperty.
|
||||||
|
*
|
||||||
|
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||||
|
* @deprecated We don't use {@link com.onarandombox.MultiverseCore.configuration.MVConfigProperty} any longer!
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
<T> com.onarandombox.MultiverseCore.configuration.MVConfigProperty<T> getProperty(String property, Class<T> expected) throws PropertyDoesNotExistException;
|
||||||
|
|
||||||
|
// old config
|
||||||
|
/**
|
||||||
|
* Adds the property to the given value.
|
||||||
|
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* @param sender The sender who wants this value to be set.
|
||||||
|
* @return True if the value was set, false if not.
|
||||||
|
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||||
|
* @deprecated Use {@link #setPropertyValue(String, String)} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
boolean setProperty(String property, String value, CommandSender sender) throws PropertyDoesNotExistException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a value to the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||||
|
*
|
||||||
|
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to add a value to.
|
||||||
|
* @param value A value in string representation, it will be parsed to the correct type.
|
||||||
|
* @return True if the value was added, false if not.
|
||||||
|
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
boolean addToVariable(String property, String value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a value from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||||
|
*
|
||||||
|
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to remove a value
|
||||||
|
* from.
|
||||||
|
* @param value A value in string representation, it will be parsed to the correct type.
|
||||||
|
* @return True if the value was removed, false if not.
|
||||||
|
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
boolean removeFromVariable(String property, String value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||||
|
*
|
||||||
|
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to clear.
|
||||||
|
* @return True if it was cleared, false if not.
|
||||||
|
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
boolean clearVariable(String property);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears a list property (sets it to []).
|
||||||
|
*
|
||||||
|
* @param property The property to clear.
|
||||||
|
* @return True if success, false if fail.
|
||||||
|
* @deprecated We changed the entire world-config-system. This is not compatible any more.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
boolean clearList(String property);
|
||||||
|
// end of old config stuff
|
||||||
|
|
||||||
|
// permission stuff
|
||||||
/**
|
/**
|
||||||
* Gets the lowercased name of the world. This method is required, since the permissables
|
* Gets the lowercased name of the world. This method is required, since the permissables
|
||||||
* lowercase all permissions when recalculating.
|
* lowercase all permissions when recalculating.
|
||||||
@ -158,6 +242,21 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
String getPermissibleName();
|
String getPermissibleName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the permission required to enter this world.
|
||||||
|
*
|
||||||
|
* @return The permission required to be exempt from charges to/from this world.
|
||||||
|
*/
|
||||||
|
Permission getAccessPermission();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the permission required to be exempt when entering.
|
||||||
|
*
|
||||||
|
* @return The permission required to be exempt when entering.
|
||||||
|
*/
|
||||||
|
Permission getExemptPermission();
|
||||||
|
// end of permission stuff
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the alias of this world.
|
* Gets the alias of this world.
|
||||||
* <p>
|
* <p>
|
||||||
@ -174,6 +273,13 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
void setAlias(String alias);
|
void setAlias(String alias);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the color that this world's name/alias will display as.
|
||||||
|
*
|
||||||
|
* @return The color of this world.
|
||||||
|
*/
|
||||||
|
ChatColor getColor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the color that this world's name/alias will display as.
|
* Sets the color that this world's name/alias will display as.
|
||||||
*
|
*
|
||||||
@ -182,19 +288,15 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
boolean setColor(String color);
|
boolean setColor(String color);
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the color that this world's name/alias will display as.
|
|
||||||
*
|
|
||||||
* @return The color of this world.
|
|
||||||
*/
|
|
||||||
ChatColor getColor();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells you if someone entered a valid color.
|
* Tells you if someone entered a valid color.
|
||||||
*
|
*
|
||||||
* @param color A string that may translate to a color.
|
* @param color A string that may translate to a color.
|
||||||
* @return True if it is a color, false if not.
|
* @return True if it is a color, false if not.
|
||||||
|
*
|
||||||
|
* @deprecated This has been moved: {@link com.onarandombox.MultiverseCore.enums.EnglishChatColor#isValidAliasColor(String)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
boolean isValidAliasColor(String color);
|
boolean isValidAliasColor(String color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,6 +306,7 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
String getColoredWorldString();
|
String getColoredWorldString();
|
||||||
|
|
||||||
|
// animals&monster stuff
|
||||||
/**
|
/**
|
||||||
* Gets whether or not animals are allowed to spawn in this world.
|
* Gets whether or not animals are allowed to spawn in this world.
|
||||||
*
|
*
|
||||||
@ -211,6 +314,22 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
boolean canAnimalsSpawn();
|
boolean canAnimalsSpawn();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether or not animals can spawn.
|
||||||
|
* If there are values in {@link #getAnimalList()} and this is false,
|
||||||
|
* those animals become the exceptions, and will spawn
|
||||||
|
*
|
||||||
|
* @param allowAnimalSpawn True to allow spawning of monsters, false to prevent.
|
||||||
|
*/
|
||||||
|
void setAllowAnimalSpawn(boolean allowAnimalSpawn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of animals. This list always negates the {@link #canAnimalsSpawn()} result.
|
||||||
|
*
|
||||||
|
* @return A list of animals that will spawn if {@link #canAnimalsSpawn()} is false.
|
||||||
|
*/
|
||||||
|
List<String> getAnimalList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether or not monsters are allowed to spawn in this world.
|
* Gets whether or not monsters are allowed to spawn in this world.
|
||||||
*
|
*
|
||||||
@ -219,7 +338,31 @@ public interface MultiverseWorld {
|
|||||||
boolean canMonstersSpawn();
|
boolean canMonstersSpawn();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn pvp on or off. This setting is used to set the world's PVP mode, and thus relies on fakePVP
|
* Sets whether or not monsters can spawn.
|
||||||
|
* If there are values in {@link #getMonsterList()} and this is false,
|
||||||
|
* those monsters become the exceptions, and will spawn
|
||||||
|
*
|
||||||
|
* @param allowMonsterSpawn True to allow spawning of monsters, false to prevent.
|
||||||
|
*/
|
||||||
|
void setAllowMonsterSpawn(boolean allowMonsterSpawn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of monsters. This list always negates the {@link #canMonstersSpawn()} result.
|
||||||
|
*
|
||||||
|
* @return A list of monsters that will spawn if {@link #canMonstersSpawn()} is false.
|
||||||
|
*/
|
||||||
|
List<String> getMonsterList();
|
||||||
|
// end of animal&monster stuff
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether or not PVP is enabled in this world in some form (fake or not).
|
||||||
|
*
|
||||||
|
* @return True if players can take damage from other players.
|
||||||
|
*/
|
||||||
|
boolean isPVPEnabled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn pvp on or off. This setting is used to set the world's PVP mode.
|
||||||
*
|
*
|
||||||
* @param pvpMode True to enable PVP damage, false to disable it.
|
* @param pvpMode True to enable PVP damage, false to disable it.
|
||||||
*/
|
*/
|
||||||
@ -234,13 +377,6 @@ public interface MultiverseWorld {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
boolean getFakePVP();
|
boolean getFakePVP();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets whether or not PVP is enabled in this world in some form (fake or not).
|
|
||||||
*
|
|
||||||
* @return True if players can take damage from other players.
|
|
||||||
*/
|
|
||||||
boolean isPVPEnabled();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether or not this world will display in chat, mvw and mvl regardless if a user has the
|
* 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.
|
* access permissions to go to this world.
|
||||||
@ -257,6 +393,13 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
void setHidden(boolean hidden);
|
void setHidden(boolean hidden);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether weather is enabled in this world.
|
||||||
|
*
|
||||||
|
* @return True if weather events will occur, false if not.
|
||||||
|
*/
|
||||||
|
boolean isWeatherEnabled();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not there will be weather events in a given world.
|
* Sets whether or not there will be weather events in a given world.
|
||||||
* If set to false, Multiverse will disable the weather in the world immediately.
|
* If set to false, Multiverse will disable the weather in the world immediately.
|
||||||
@ -266,11 +409,11 @@ public interface MultiverseWorld {
|
|||||||
void setEnableWeather(boolean enableWeather);
|
void setEnableWeather(boolean enableWeather);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether weather is enabled in this world.
|
* Gets whether or not CraftBukkit is keeping the chunks for this world in memory.
|
||||||
*
|
*
|
||||||
* @return True if weather events will occur, false if not.
|
* @return True if CraftBukkit is keeping spawn chunks in memory.
|
||||||
*/
|
*/
|
||||||
boolean isWeatherEnabled();
|
boolean isKeepingSpawnInMemory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true, tells Craftbukkit to keep a worlds spawn chunks loaded in memory (default: true)
|
* If true, tells Craftbukkit to keep a worlds spawn chunks loaded in memory (default: true)
|
||||||
@ -282,29 +425,11 @@ public interface MultiverseWorld {
|
|||||||
void setKeepSpawnInMemory(boolean keepSpawnInMemory);
|
void setKeepSpawnInMemory(boolean keepSpawnInMemory);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether or not CraftBukkit is keeping the chunks for this world in memory.
|
* Gets the spawn location of this world.
|
||||||
*
|
*
|
||||||
* @return True if CraftBukkit is keeping spawn chunks in memory.
|
* @return The spawn location of this world.
|
||||||
*/
|
*/
|
||||||
boolean isKeepingSpawnInMemory();
|
Location getSpawnLocation();
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the difficulty of this world and returns true if success.
|
|
||||||
* Valid string values are either an integer of difficulty(0-3) or
|
|
||||||
* the name that resides in the Bukkit enum, ex. PEACEFUL
|
|
||||||
*
|
|
||||||
* @param difficulty The difficulty to set the world to as a string.
|
|
||||||
* @return True if success, false if the provided string
|
|
||||||
* could not be translated to a difficulty.
|
|
||||||
*/
|
|
||||||
boolean setDifficulty(String difficulty);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the difficulty of this world.
|
|
||||||
*
|
|
||||||
* @return The difficulty of this world.
|
|
||||||
*/
|
|
||||||
Difficulty getDifficulty();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the spawn location for a world.
|
* Sets the spawn location for a world.
|
||||||
@ -314,11 +439,11 @@ public interface MultiverseWorld {
|
|||||||
void setSpawnLocation(Location spawnLocation);
|
void setSpawnLocation(Location spawnLocation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the spawn location of this world.
|
* Gets whether or not the hunger level of players will go down in a world.
|
||||||
*
|
*
|
||||||
* @return The spawn location of this world.
|
* @return True if it will go down, false if it will remain steady.
|
||||||
*/
|
*/
|
||||||
Location getSpawnLocation();
|
boolean getHunger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not the hunger level of players will go down in a world.
|
* Sets whether or not the hunger level of players will go down in a world.
|
||||||
@ -328,22 +453,6 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
void setHunger(boolean hungerEnabled);
|
void setHunger(boolean hungerEnabled);
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets whether or not the hunger level of players will go down in a world.
|
|
||||||
*
|
|
||||||
* @return True if it will go down, false if it will remain steady.
|
|
||||||
*/
|
|
||||||
boolean getHunger();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the game mode of this world.
|
|
||||||
*
|
|
||||||
* @param gameMode A valid game mode string (either
|
|
||||||
* an int ex. 0 or a string ex. creative).
|
|
||||||
* @return True if the game mode was successfully changed, false if not.
|
|
||||||
*/
|
|
||||||
boolean setGameMode(String gameMode);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the GameMode of this world.
|
* Gets the GameMode of this world.
|
||||||
*
|
*
|
||||||
@ -352,18 +461,31 @@ public interface MultiverseWorld {
|
|||||||
GameMode getGameMode();
|
GameMode getGameMode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the permission required to enter this world.
|
* Sets the game mode of this world.
|
||||||
*
|
*
|
||||||
* @return The permission required to be exempt from charges to/from this world.
|
* @param gameMode A valid game mode string (either
|
||||||
|
* an int ex. 0 or a string ex. creative).
|
||||||
|
* @return True if the game mode was successfully changed, false if not.
|
||||||
|
* @deprecated Use {@link #setGameMode(GameMode)} instead. If you have to
|
||||||
|
* pass a string, use {@link #setPropertyValue(String, String)}.
|
||||||
*/
|
*/
|
||||||
Permission getAccessPermission();
|
@Deprecated
|
||||||
|
boolean setGameMode(String gameMode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the permission required to be exempt when entering.
|
* Sets the game mode of this world.
|
||||||
*
|
*
|
||||||
* @return The permission required to be exempt when entering.
|
* @param gameMode The new {@link GameMode}.
|
||||||
|
* @return True if the game mode was successfully changed, false if not.
|
||||||
*/
|
*/
|
||||||
Permission getExemptPermission();
|
boolean setGameMode(GameMode gameMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the amount of currency it requires to enter this world.
|
||||||
|
*
|
||||||
|
* @return The amount it costs to enter this world.
|
||||||
|
*/
|
||||||
|
double getPrice();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the price for entry to this world.
|
* Sets the price for entry to this world.
|
||||||
@ -375,11 +497,11 @@ public interface MultiverseWorld {
|
|||||||
void setPrice(double price);
|
void setPrice(double price);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the amount of currency it requires to enter this world.
|
* Gets the Type of currency that will be used when users enter this world.
|
||||||
*
|
*
|
||||||
* @return The amount it costs to enter this world.
|
* @return The Type of currency that will be used when users enter this world.
|
||||||
*/
|
*/
|
||||||
double getPrice();
|
int getCurrency();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the type of item that will be required given the price is not 0.
|
* Sets the type of item that will be required given the price is not 0.
|
||||||
@ -390,11 +512,11 @@ public interface MultiverseWorld {
|
|||||||
void setCurrency(int item);
|
void setCurrency(int item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Type of currency that will be used when users enter this world.
|
* Gets the world players will respawn in if they die in this one.
|
||||||
*
|
*
|
||||||
* @return The Type of currency that will be used when users enter this world.
|
* @return A world that exists on the server.
|
||||||
*/
|
*/
|
||||||
int getCurrency();
|
World getRespawnToWorld();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the world players will respawn in if they die in this one.
|
* Sets the world players will respawn in if they die in this one.
|
||||||
@ -406,11 +528,12 @@ public interface MultiverseWorld {
|
|||||||
boolean setRespawnToWorld(String respawnWorld);
|
boolean setRespawnToWorld(String respawnWorld);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the world players will respawn in if they die in this one.
|
* Gets the scaling value of this world.Really only has an effect if you use
|
||||||
|
* Multiverse-NetherPortals.
|
||||||
*
|
*
|
||||||
* @return A world that exists on the server.
|
* @return This world's non-negative, non-zero scale.
|
||||||
*/
|
*/
|
||||||
World getRespawnToWorld();
|
double getScaling();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the scale of this world. Really only has an effect if you use
|
* Sets the scale of this world. Really only has an effect if you use
|
||||||
@ -422,60 +545,11 @@ public interface MultiverseWorld {
|
|||||||
boolean setScaling(double scaling);
|
boolean setScaling(double scaling);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the scaling value of this world.Really only has an effect if you use
|
* Gets whether or not a world will auto-heal players if the difficulty is on peaceful.
|
||||||
* Multiverse-NetherPortals.
|
|
||||||
*
|
*
|
||||||
* @return This world's non-negative, non-zero scale.
|
* @return True if the world should heal (default), false if not.
|
||||||
*/
|
*/
|
||||||
double getScaling();
|
boolean getAutoHeal();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a list of all the worlds that players CANNOT travel to from this world,
|
|
||||||
* regardless of their access permissions.
|
|
||||||
*
|
|
||||||
* @return A List of world names.
|
|
||||||
*/
|
|
||||||
List<String> getWorldBlacklist();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of animals. This list always negates the {@link #canAnimalsSpawn()} result.
|
|
||||||
*
|
|
||||||
* @return A list of animals that will spawn if {@link #canAnimalsSpawn()} is false.
|
|
||||||
*/
|
|
||||||
List<String> getAnimalList();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether or not animals can spawn.
|
|
||||||
* If there are values in {@link #getAnimalList()} and this is false,
|
|
||||||
* those animals become the exceptions, and will spawn
|
|
||||||
*
|
|
||||||
* @param allowAnimalSpawn True to allow spawning of monsters, false to prevent.
|
|
||||||
*/
|
|
||||||
void setAllowAnimalSpawn(boolean allowAnimalSpawn);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of monsters. This list always negates the {@link #canMonstersSpawn()} ()} result.
|
|
||||||
*
|
|
||||||
* @return A list of monsters that will spawn if {@link #canMonstersSpawn()} is false.
|
|
||||||
*/
|
|
||||||
List<String> getMonsterList();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether or not monsters can spawn.
|
|
||||||
* If there are values in {@link #getMonsterList()} and this is false,
|
|
||||||
* those monsters become the exceptions, and will spawn
|
|
||||||
*
|
|
||||||
* @param allowMonsterSpawn True to allow spawning of monsters, false to prevent.
|
|
||||||
*/
|
|
||||||
void setAllowMonsterSpawn(boolean allowMonsterSpawn);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears a list property (sets it to []).
|
|
||||||
*
|
|
||||||
* @param property The property to clear.
|
|
||||||
* @return True if success, false if fail.
|
|
||||||
*/
|
|
||||||
boolean clearList(String property);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not a world will auto-heal players if the difficulty is on peaceful.
|
* Sets whether or not a world will auto-heal players if the difficulty is on peaceful.
|
||||||
@ -485,11 +559,11 @@ public interface MultiverseWorld {
|
|||||||
void setAutoHeal(boolean heal);
|
void setAutoHeal(boolean heal);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether or not a world will auto-heal players if the difficulty is on peaceful.
|
* Gets whether or not Multiverse should auto-adjust the spawn for this world.
|
||||||
*
|
*
|
||||||
* @return True if the world should heal (default), false if not.
|
* @return True if Multiverse should adjust the spawn, false if not.
|
||||||
*/
|
*/
|
||||||
boolean getAutoHeal();
|
boolean getAdjustSpawn();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not Multiverse should auto-adjust the spawn for this world.
|
* Sets whether or not Multiverse should auto-adjust the spawn for this world.
|
||||||
@ -499,11 +573,11 @@ public interface MultiverseWorld {
|
|||||||
void setAdjustSpawn(boolean adjust);
|
void setAdjustSpawn(boolean adjust);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether or not Multiverse should auto-adjust the spawn for this world.
|
* Gets whether or not Multiverse should auto-load this world.
|
||||||
*
|
*
|
||||||
* @return True if Multiverse should adjust the spawn, false if not.
|
* @return True if Multiverse should auto-load this world.
|
||||||
*/
|
*/
|
||||||
boolean getAdjustSpawn();
|
boolean getAutoLoad();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not Multiverse should auto-load this world.
|
* Sets whether or not Multiverse should auto-load this world.
|
||||||
@ -515,11 +589,12 @@ public interface MultiverseWorld {
|
|||||||
void setAutoLoad(boolean autoLoad);
|
void setAutoLoad(boolean autoLoad);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether or not Multiverse should auto-load this world.
|
* Gets whether or not a player who dies in this world will respawn in their
|
||||||
|
* bed or follow the normal respawn pattern.
|
||||||
*
|
*
|
||||||
* @return True if Multiverse should auto-load this world.
|
* @return True if players dying in this world should respawn at their bed.
|
||||||
*/
|
*/
|
||||||
boolean getAutoLoad();
|
boolean getBedRespawn();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not a player who dies in this world will respawn in their
|
* Sets whether or not a player who dies in this world will respawn in their
|
||||||
@ -532,19 +607,10 @@ public interface MultiverseWorld {
|
|||||||
void setBedRespawn(boolean autoLoad);
|
void setBedRespawn(boolean autoLoad);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether or not a player who dies in this world will respawn in their
|
* Same as {@link #getTime()}, but returns a string.
|
||||||
* bed or follow the normal respawn pattern.
|
* @return The time as a short string: 12:34pm
|
||||||
*
|
|
||||||
* @return True if players dying in this world should respawn at their bed.
|
|
||||||
*/
|
*/
|
||||||
boolean getBedRespawn();
|
String getTime();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all the names of all properties that can be SET.
|
|
||||||
*
|
|
||||||
* @return All property names, with alternating colors.
|
|
||||||
*/
|
|
||||||
String getAllPropertyNames();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current time in a world.
|
* Sets the current time in a world.
|
||||||
@ -559,22 +625,6 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
boolean setTime(String timeAsString);
|
boolean setTime(String timeAsString);
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as {@link #getTime()}, but returns a string.
|
|
||||||
* @return The time as a short string: 12:34pm
|
|
||||||
*/
|
|
||||||
String getTime();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the type of this world. As of 1.2 this will be:
|
|
||||||
* FLAT, NORMAL or VERSION_1_1
|
|
||||||
* <p>
|
|
||||||
* This is *not* the generator.
|
|
||||||
*
|
|
||||||
* @return The Type of this world.
|
|
||||||
*/
|
|
||||||
WorldType getWorldType();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets The types of portals that are allowed in this world.
|
* Sets The types of portals that are allowed in this world.
|
||||||
*
|
*
|
||||||
@ -589,6 +639,22 @@ public interface MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
AllowedPortalType getAllowedPortals();
|
AllowedPortalType getAllowedPortals();
|
||||||
|
|
||||||
|
// properties that are not "getter+setter" style
|
||||||
|
/**
|
||||||
|
* Gets a list of all the worlds that players CANNOT travel to from this world,
|
||||||
|
* regardless of their access permissions.
|
||||||
|
*
|
||||||
|
* @return A List of world names.
|
||||||
|
*/
|
||||||
|
List<String> getWorldBlacklist();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all the names of all properties that can be SET.
|
||||||
|
*
|
||||||
|
* @return All property names, with alternating colors.
|
||||||
|
*/
|
||||||
|
String getAllPropertyNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether or not flight is allowed in this world.
|
* Gets whether or not flight is allowed in this world.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -51,7 +51,7 @@ public class ConfigCommand extends MultiverseCommand {
|
|||||||
sender.sendMessage(message);
|
sender.sendMessage(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.plugin.getMVConfig().setProperty(args.get(0).toLowerCase(), args.get(1))) {
|
if (!this.plugin.getMVConfig().setConfigProperty(args.get(0).toLowerCase(), args.get(1))) {
|
||||||
sender.sendMessage(String.format("%sSetting '%s' to '%s' failed!", ChatColor.RED, args.get(0).toLowerCase(), args.get(1)));
|
sender.sendMessage(String.format("%sSetting '%s' to '%s' failed!", ChatColor.RED, args.get(0).toLowerCase(), args.get(1)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@ public class ModifyAddCommand extends MultiverseCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO fix this
|
||||||
if (world.addToVariable(property, value)) {
|
if (world.addToVariable(property, value)) {
|
||||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA
|
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA
|
||||||
+ value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property);
|
+ value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property);
|
||||||
|
@ -75,6 +75,7 @@ public class ModifyClearCommand extends MultiverseCommand {
|
|||||||
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/cgB2B");
|
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/cgB2B");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO fix this
|
||||||
if (world.clearList(property)) {
|
if (world.clearList(property)) {
|
||||||
sender.sendMessage(property + " was cleared. It contains 0 values now.");
|
sender.sendMessage(property + " was cleared. It contains 0 values now.");
|
||||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was "
|
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was "
|
||||||
|
@ -81,6 +81,7 @@ public class ModifyRemoveCommand extends MultiverseCommand {
|
|||||||
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/4W8cY");
|
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/4W8cY");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO fix this
|
||||||
if (world.removeFromVariable(property, value)) {
|
if (world.removeFromVariable(property, value)) {
|
||||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE
|
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE
|
||||||
+ " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property);
|
+ " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property);
|
||||||
|
@ -102,22 +102,21 @@ public class ModifySetCommand extends MultiverseCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) && !world.isValidAliasColor(value)) {
|
if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) && !EnglishChatColor.isValidAliasColor(value)) {
|
||||||
sender.sendMessage(value + " is not a valid color. Please pick one of the following:");
|
sender.sendMessage(value + " is not a valid color. Please pick one of the following:");
|
||||||
sender.sendMessage(EnglishChatColor.getAllColors());
|
sender.sendMessage(EnglishChatColor.getAllColors());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (world.setProperty(property, value, sender)) {
|
if (world.setPropertyValue(property, value)) {
|
||||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property
|
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property
|
||||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(world.getProperty(property, Object.class).getHelp());
|
sender.sendMessage(ChatColor.RED + world.getPropertyHelp(property));
|
||||||
}
|
}
|
||||||
} catch (PropertyDoesNotExistException e) {
|
} catch (PropertyDoesNotExistException e) {
|
||||||
sender.sendMessage(ChatColor.RED + "Sorry, You can't set: '" + ChatColor.GRAY + property + ChatColor.RED + "'");
|
sender.sendMessage(ChatColor.RED + "Sorry, You can't set: '" + ChatColor.GRAY + property + ChatColor.RED + "'");
|
||||||
// TODO: Display the list
|
sender.sendMessage("Valid world-properties: " + world.getAllPropertyNames());
|
||||||
sender.sendMessage(ChatColor.GOLD + "For a full list of thingys, see our wiki.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,115 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link String} config-property that will NOT be saved to the config.
|
|
||||||
*/
|
|
||||||
public class ActiveStringConfigProperty implements MVActiveConfigProperty<String> {
|
|
||||||
private String name;
|
|
||||||
private String value;
|
|
||||||
private String method;
|
|
||||||
private String help;
|
|
||||||
|
|
||||||
public ActiveStringConfigProperty(String name, String defaultValue, String help) {
|
|
||||||
this.name = name;
|
|
||||||
this.help = help;
|
|
||||||
this.value = defaultValue;
|
|
||||||
this.parseValue(defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActiveStringConfigProperty(String name, String defaultValue, String help, String method) {
|
|
||||||
this(name, defaultValue, help);
|
|
||||||
this.method = method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getMethod() {
|
|
||||||
return this.method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setMethod(String methodName) {
|
|
||||||
this.method = methodName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Class<?> getPropertyClass() {
|
|
||||||
return String.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean parseValue(String value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.setValue(value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean setValue(String value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.value = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,135 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link Boolean} config-property.
|
|
||||||
*/
|
|
||||||
public class BooleanConfigProperty implements MVActiveConfigProperty<Boolean> {
|
|
||||||
private String name;
|
|
||||||
private Boolean value;
|
|
||||||
private String configNode;
|
|
||||||
private ConfigurationSection section;
|
|
||||||
private String help;
|
|
||||||
private String method;
|
|
||||||
|
|
||||||
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String help) {
|
|
||||||
this(section, name, defaultValue, name, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.value = defaultValue;
|
|
||||||
this.setValue(this.section.getBoolean(this.configNode, defaultValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String configNode, String help, String method) {
|
|
||||||
this(section, name, defaultValue, configNode, help);
|
|
||||||
this.method = method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Boolean getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean setValue(Boolean value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.value = value;
|
|
||||||
this.section.set(configNode, this.value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return this.configNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @return The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getMethod() {
|
|
||||||
return this.method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @param methodName The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setMethod(String methodName) {
|
|
||||||
this.method = methodName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the class of the object we're looking at.
|
|
||||||
*
|
|
||||||
* @return the class of the object we're looking at.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Class<?> getPropertyClass() {
|
|
||||||
return Boolean.class;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,98 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link EnglishChatColor} config-property.
|
|
||||||
*/
|
|
||||||
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(section, name, defaultValue, name, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.value = defaultValue;
|
|
||||||
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public EnglishChatColor getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean setValue(EnglishChatColor value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.value = value;
|
|
||||||
this.section.set(configNode, this.value.getText());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean parseValue(String value) {
|
|
||||||
EnglishChatColor color = EnglishChatColor.fromString(value);
|
|
||||||
if (color == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.setValue(color);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return this.configNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,306 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
|
|
||||||
* 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.AllowedPortalType;
|
|
||||||
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
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String help) {
|
|
||||||
return new BooleanConfigProperty(this.section, name, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String node, String help) {
|
|
||||||
return new BooleanConfigProperty(this.section, name, defaultValue, node, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ActiveBooleanConfigProperty
|
|
||||||
*
|
|
||||||
* This property will execute 'method' after it has been successfully set.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConifgProperty
|
|
||||||
* @param defaultValue The default value.
|
|
||||||
* @param help What string is shown for help.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param method The method that should be executed.
|
|
||||||
* @return The ActiveStringConfigProperty
|
|
||||||
*/
|
|
||||||
public BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String help, String node, String method) {
|
|
||||||
return new BooleanConfigProperty(this.section, name, defaultValue, help, node, method);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Integers
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public IntegerConfigProperty getNewProperty(String name, int defaultValue, String help) {
|
|
||||||
return new IntegerConfigProperty(this.section, name, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public IntegerConfigProperty getNewProperty(String name, int defaultValue, String node, String help) {
|
|
||||||
return new IntegerConfigProperty(this.section, name, defaultValue, node, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Doubles
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public DoubleConfigProperty getNewProperty(String name, double defaultValue, String help) {
|
|
||||||
return new DoubleConfigProperty(this.section, name, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public DoubleConfigProperty getNewProperty(String name, double defaultValue, String node, String help) {
|
|
||||||
return new DoubleConfigProperty(this.section, name, defaultValue, node, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @param method The name of the method that's used to set this property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public DoubleConfigProperty getNewProperty(String name, double defaultValue, String node, String help, String method) {
|
|
||||||
return new DoubleConfigProperty(this.section, name, defaultValue, node, help, method);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strings
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public StringConfigProperty getNewProperty(String name, String defaultValue, String help) {
|
|
||||||
return new StringConfigProperty(this.section, name, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public StringConfigProperty getNewProperty(String name, String defaultValue, String node, String help) {
|
|
||||||
return new StringConfigProperty(this.section, name, defaultValue, node, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Colors
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue, String help) {
|
|
||||||
return new ColorConfigProperty(this.section, name, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue, String node, String help) {
|
|
||||||
return new ColorConfigProperty(this.section, name, defaultValue, node, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Difficulty
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue, String help) {
|
|
||||||
return new DifficultyConfigProperty(this.section, name, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue, String node, String help) {
|
|
||||||
return new DifficultyConfigProperty(this.section, name, defaultValue, node, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GameMode
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public GameModeConfigProperty getNewProperty(String name, GameMode defaultValue, String help) {
|
|
||||||
return new GameModeConfigProperty(this.section, name, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public GameModeConfigProperty getNewProperty(String name, GameMode defaultValue, String node, String help) {
|
|
||||||
return new GameModeConfigProperty(this.section, name, defaultValue, node, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Location
|
|
||||||
/**
|
|
||||||
* Constructs a new LocationConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public LocationConfigProperty getNewProperty(String name, Location defaultValue, String help) {
|
|
||||||
return new LocationConfigProperty(this.section, name, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public LocationConfigProperty getNewProperty(String name, Location defaultValue, String node, String help) {
|
|
||||||
return new LocationConfigProperty(this.section, name, defaultValue, node, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param node The name of the configuration-node this ConfigProperty will be stored as.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @param method The name of the method that's used to set this property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public LocationConfigProperty getNewProperty(String name, Location defaultValue, String node, String help, String method) {
|
|
||||||
return new LocationConfigProperty(this.section, name, defaultValue, node, help, method);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GameMode
|
|
||||||
/**
|
|
||||||
* Constructs a new ConfigProperty.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConfigProperty.
|
|
||||||
* @param defaultValue The default-value.
|
|
||||||
* @param help The text that's displayed when a user failed to set the property.
|
|
||||||
* @return The ConfigProperty.
|
|
||||||
*/
|
|
||||||
public PortalTypeConfigProperty getNewProperty(String name, AllowedPortalType defaultValue, String help) {
|
|
||||||
return new PortalTypeConfigProperty(this.section, name, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ActiveStringConfigProperty
|
|
||||||
*
|
|
||||||
* This property will execute 'method' after it has been successfully set.
|
|
||||||
* This string will NOT be saved to the config file.
|
|
||||||
*
|
|
||||||
* @param name The name of this ConifgProperty
|
|
||||||
* @param defaultValue The default value.
|
|
||||||
* @param help What string is shown for help.
|
|
||||||
* @param method The method that should be executed.
|
|
||||||
* @param saveToConfig Should the variable save to the config?
|
|
||||||
* @return The ActiveStringConfigProperty
|
|
||||||
*/
|
|
||||||
public ActiveStringConfigProperty getNewProperty(String name, String defaultValue, String help, String method, boolean saveToConfig) {
|
|
||||||
return new ActiveStringConfigProperty(name, defaultValue, help, method);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* 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.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link Difficulty} config-property.
|
|
||||||
*/
|
|
||||||
public class DifficultyConfigProperty implements MVActiveConfigProperty<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(section, name, defaultValue, name, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.value = defaultValue;
|
|
||||||
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Difficulty getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean setValue(Difficulty value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.value = value;
|
|
||||||
this.section.set(configNode, this.value.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return this.configNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @return The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getMethod() {
|
|
||||||
return "setActualDifficulty";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @param methodName The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setMethod(String methodName) {
|
|
||||||
// Unused here. This will only ever be setDifficulty.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Class<?> getPropertyClass() {
|
|
||||||
return Difficulty.class;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,133 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link Double} config-property.
|
|
||||||
*/
|
|
||||||
public class DoubleConfigProperty implements MVActiveConfigProperty<Double> {
|
|
||||||
private String name;
|
|
||||||
private Double value;
|
|
||||||
private String configNode;
|
|
||||||
private ConfigurationSection section;
|
|
||||||
private String help;
|
|
||||||
private String method;
|
|
||||||
|
|
||||||
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String help) {
|
|
||||||
this(section, name, defaultValue, name, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.value = defaultValue;
|
|
||||||
this.setValue(this.section.getDouble(this.configNode, defaultValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String configNode, String help, String method) {
|
|
||||||
this(section, name, defaultValue, configNode, help);
|
|
||||||
this.method = method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Double getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean setValue(Double value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.value = value;
|
|
||||||
this.section.set(configNode, this.value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean parseValue(String value) {
|
|
||||||
try {
|
|
||||||
this.setValue(Double.parseDouble(value));
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return this.configNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @return The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getMethod() {
|
|
||||||
return this.method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @param methodName The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setMethod(String methodName) {
|
|
||||||
this.method = methodName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the class of the object we're looking at.
|
|
||||||
*
|
|
||||||
* @return the class of the object we're looking at.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Class<?> getPropertyClass() {
|
|
||||||
return Double.class;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,66 @@
|
|||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import me.main__.util.SerializationConfig.Property;
|
||||||
|
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.serialization.SerializableAs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entryfee-settings.
|
||||||
|
*/
|
||||||
|
@SerializableAs("MVEntryFee")
|
||||||
|
public class EntryFee extends SerializationConfig {
|
||||||
|
@Property
|
||||||
|
private double amount;
|
||||||
|
@Property
|
||||||
|
private int currency;
|
||||||
|
|
||||||
|
public EntryFee() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntryFee(Map<String, Object> values) {
|
||||||
|
super(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void setDefaults() {
|
||||||
|
amount = 0D;
|
||||||
|
currency = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the amount
|
||||||
|
*/
|
||||||
|
public double getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the currency
|
||||||
|
*/
|
||||||
|
public int getCurrency() {
|
||||||
|
return currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the amount.
|
||||||
|
* @param amount The new value.
|
||||||
|
*/
|
||||||
|
public void setAmount(double amount) {
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the currency.
|
||||||
|
* @param currency The new value.
|
||||||
|
*/
|
||||||
|
public void setCurrency(int currency) {
|
||||||
|
this.currency = currency;
|
||||||
|
}
|
||||||
|
}
|
@ -1,129 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* 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.GameMode;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link GameMode} config-property.
|
|
||||||
*/
|
|
||||||
public class GameModeConfigProperty implements MVActiveConfigProperty<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(section, name, defaultValue, name, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.value = defaultValue;
|
|
||||||
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public GameMode getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean setValue(GameMode value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.value = value;
|
|
||||||
this.section.set(configNode, this.value.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return this.configNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @return The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getMethod() {
|
|
||||||
return "setActualGameMode";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @param methodName The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setMethod(String methodName) {
|
|
||||||
// Not required. Gamemode will only ever be one.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Class<?> getPropertyClass() {
|
|
||||||
return GameMode.class;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link Integer} config-property.
|
|
||||||
*/
|
|
||||||
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(section, name, defaultValue, name, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.value = defaultValue;
|
|
||||||
this.setValue(this.section.getInt(this.configNode, defaultValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Integer getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean setValue(Integer value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.value = value;
|
|
||||||
this.section.set(configNode, this.value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean parseValue(String value) {
|
|
||||||
try {
|
|
||||||
this.setValue(Integer.parseInt(value));
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return this.configNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,154 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link Location} config-property.
|
|
||||||
*/
|
|
||||||
public class LocationConfigProperty implements MVActiveConfigProperty<Location> {
|
|
||||||
private String name;
|
|
||||||
private Location value;
|
|
||||||
private String configNode;
|
|
||||||
private ConfigurationSection section;
|
|
||||||
private String help;
|
|
||||||
private String method;
|
|
||||||
|
|
||||||
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String help) {
|
|
||||||
this(section, name, defaultValue, name, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.value = defaultValue;
|
|
||||||
this.setValue(this.getLocationFromConfig(defaultValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode, String help, String method) {
|
|
||||||
this(section, name, defaultValue, configNode, help);
|
|
||||||
this.method = method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Location getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean parseValue(String value) {
|
|
||||||
// TODO: oh my god, what should we do here?
|
|
||||||
Location parsed = LocationManipulation.stringToLocation(value);
|
|
||||||
return this.setValue(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return this.configNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@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(Location defaultValue) {
|
|
||||||
double x = this.section.getDouble(this.configNode + ".x", defaultValue.getX());
|
|
||||||
double y = this.section.getDouble(this.configNode + ".y", defaultValue.getY());
|
|
||||||
double z = this.section.getDouble(this.configNode + ".z", defaultValue.getZ());
|
|
||||||
double pitch = this.section.getDouble(this.configNode + ".pitch", defaultValue.getPitch());
|
|
||||||
double yaw = this.section.getDouble(this.configNode + ".yaw", defaultValue.getYaw());
|
|
||||||
String w = this.section.getString(this.configNode + ".world", defaultValue.getWorld().getName());
|
|
||||||
Location found = LocationManipulation.stringToLocation(w + ":" + x + "," + y + "," + z + ":" + yaw + ":" + pitch);
|
|
||||||
// TODO: oh my god, what should we do here?
|
|
||||||
if (found != null) {
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
// TODO: oh my god, what should we do here?
|
|
||||||
return LocationManipulation.strCoordsRaw(this.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @return The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getMethod() {
|
|
||||||
return this.method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the method that will be executed.
|
|
||||||
*
|
|
||||||
* @param methodName The name of the method in MVWorld to be called.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setMethod(String methodName) {
|
|
||||||
this.method = methodName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the class of the object we're looking at.
|
|
||||||
*
|
|
||||||
* @return the class of the object we're looking at.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Class<?> getPropertyClass() {
|
|
||||||
return Location.class;
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,8 +10,10 @@ package com.onarandombox.MultiverseCore.configuration;
|
|||||||
/**
|
/**
|
||||||
* An "active" {@link MVConfigProperty} that uses the specified method to be "actually" set.
|
* An "active" {@link MVConfigProperty} that uses the specified method to be "actually" set.
|
||||||
* @param <T> The type of the config-property.
|
* @param <T> The type of the config-property.
|
||||||
|
* @deprecated This is deprecated.
|
||||||
* @see MVConfigProperty
|
* @see MVConfigProperty
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface MVActiveConfigProperty<T> extends MVConfigProperty<T> {
|
public interface MVActiveConfigProperty<T> extends MVConfigProperty<T> {
|
||||||
/**
|
/**
|
||||||
* Gets the method that will be executed.
|
* Gets the method that will be executed.
|
||||||
|
@ -11,7 +11,9 @@ package com.onarandombox.MultiverseCore.configuration;
|
|||||||
* A generic config-property.
|
* A generic config-property.
|
||||||
*
|
*
|
||||||
* @param <T> The type of the config-property.
|
* @param <T> The type of the config-property.
|
||||||
|
* @deprecated This is deprecated.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface MVConfigProperty<T> {
|
public interface MVConfigProperty<T> {
|
||||||
/**
|
/**
|
||||||
* Gets the name of this property.
|
* Gets the name of this property.
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
|
|
||||||
* 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.AllowedPortalType;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link AllowedPortalType} config-property.
|
|
||||||
*/
|
|
||||||
public class PortalTypeConfigProperty implements MVConfigProperty<AllowedPortalType> {
|
|
||||||
private String name;
|
|
||||||
private AllowedPortalType value;
|
|
||||||
private String configNode;
|
|
||||||
private ConfigurationSection section;
|
|
||||||
private String help;
|
|
||||||
|
|
||||||
public PortalTypeConfigProperty(ConfigurationSection section, String name, AllowedPortalType defaultValue, String help) {
|
|
||||||
this(section, name, defaultValue, name, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PortalTypeConfigProperty(ConfigurationSection section, String name, AllowedPortalType defaultValue, String configNode, String help) {
|
|
||||||
this.name = name;
|
|
||||||
this.configNode = configNode;
|
|
||||||
this.section = section;
|
|
||||||
this.help = help;
|
|
||||||
this.value = defaultValue;
|
|
||||||
this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public AllowedPortalType getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean setValue(AllowedPortalType value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.value = value;
|
|
||||||
this.section.set(configNode, this.value.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean parseValue(String value) {
|
|
||||||
try {
|
|
||||||
return this.setValue(AllowedPortalType.valueOf(value.toUpperCase()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return this.configNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,98 @@
|
|||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import java.lang.ref.Reference;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
import org.bukkit.configuration.serialization.SerializableAs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just like a regular {@link Location}, however {@code world} is usually {@code null}
|
||||||
|
* or just a weak reference and it implements {@link ConfigurationSerializable}.
|
||||||
|
*/
|
||||||
|
@SerializableAs("MVSpawnLocation")
|
||||||
|
public class SpawnLocation extends Location implements ConfigurationSerializable {
|
||||||
|
private Reference<World> worldRef;
|
||||||
|
|
||||||
|
public SpawnLocation(double x, double y, double z) {
|
||||||
|
super(null, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnLocation(double x, double y, double z, float yaw, float pitch) {
|
||||||
|
super(null, x, y, z, yaw, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnLocation(Location loc) {
|
||||||
|
this(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public World getWorld() {
|
||||||
|
return (this.worldRef != null) ? this.worldRef.get() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setWorld(World world) {
|
||||||
|
this.worldRef = new WeakReference<World>(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Chunk getChunk() {
|
||||||
|
if ((this.worldRef != null) && (this.worldRef.get() != null))
|
||||||
|
return this.worldRef.get().getChunkAt(this);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Block getBlock() {
|
||||||
|
if ((this.worldRef != null) && (this.worldRef.get() != null))
|
||||||
|
return this.worldRef.get().getBlockAt(this);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> serialized = new HashMap<String, Object>(5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||||
|
serialized.put("x", this.getX());
|
||||||
|
serialized.put("y", this.getY());
|
||||||
|
serialized.put("z", this.getZ());
|
||||||
|
serialized.put("pitch", this.getPitch());
|
||||||
|
serialized.put("yaw", this.getYaw());
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Let Bukkit be able to deserialize this.
|
||||||
|
* @param args The map.
|
||||||
|
* @return The deserialized object.
|
||||||
|
*/
|
||||||
|
public static SpawnLocation deserialize(Map<String, Object> args) {
|
||||||
|
double x = ((Number) args.get("x")).doubleValue();
|
||||||
|
double y = ((Number) args.get("y")).doubleValue();
|
||||||
|
double z = ((Number) args.get("z")).doubleValue();
|
||||||
|
float pitch = ((Number) args.get("pitch")).floatValue();
|
||||||
|
float yaw = ((Number) args.get("yaw")).floatValue();
|
||||||
|
return new SpawnLocation(x, y, z, yaw, pitch);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import me.main__.util.SerializationConfig.Property;
|
||||||
|
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.serialization.SerializableAs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spawning-Settings.
|
||||||
|
*/
|
||||||
|
@SerializableAs("MVSpawnSettings")
|
||||||
|
public class SpawnSettings extends SerializationConfig {
|
||||||
|
@Property
|
||||||
|
private SubSpawnSettings animals;
|
||||||
|
@Property
|
||||||
|
private SubSpawnSettings monsters;
|
||||||
|
|
||||||
|
public SpawnSettings() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnSettings(Map<String, Object> values) {
|
||||||
|
super(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setDefaults() {
|
||||||
|
animals = new SubSpawnSettings();
|
||||||
|
monsters = new SubSpawnSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the animal-settings
|
||||||
|
*/
|
||||||
|
public SubSpawnSettings getAnimalSettings() {
|
||||||
|
return animals;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the monster-settings
|
||||||
|
*/
|
||||||
|
public SubSpawnSettings getMonsterSettings() {
|
||||||
|
return monsters;
|
||||||
|
}
|
||||||
|
}
|
@ -1,96 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link String} config-property.
|
|
||||||
*/
|
|
||||||
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(section, name, defaultValue, defaultValue, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.value = defaultValue;
|
|
||||||
this.parseValue(this.section.getString(this.configNode, defaultValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean parseValue(String value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.setValue(value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getConfigNode() {
|
|
||||||
return this.configNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHelp() {
|
|
||||||
return this.help;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean setValue(String value) {
|
|
||||||
if (value == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.value = value;
|
|
||||||
this.section.set(configNode, this.value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import me.main__.util.SerializationConfig.Property;
|
||||||
|
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.serialization.SerializableAs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpawnSubSettings.
|
||||||
|
*/
|
||||||
|
@SerializableAs("MVSpawnSubSettings")
|
||||||
|
public class SubSpawnSettings extends SerializationConfig {
|
||||||
|
@Property
|
||||||
|
private boolean spawn;
|
||||||
|
@Property
|
||||||
|
private List<String> exceptions;
|
||||||
|
|
||||||
|
public SubSpawnSettings() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubSpawnSettings(Map<String, Object> values) {
|
||||||
|
super(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setDefaults() {
|
||||||
|
spawn = true;
|
||||||
|
exceptions = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return spawn
|
||||||
|
*/
|
||||||
|
public boolean doSpawn() {
|
||||||
|
return spawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param spawn The new value.
|
||||||
|
*/
|
||||||
|
public void setSpawn(boolean spawn) {
|
||||||
|
this.spawn = spawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the exceptions
|
||||||
|
*/
|
||||||
|
public List<String> getExceptions() {
|
||||||
|
return exceptions;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.MVWorld;
|
||||||
|
import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent;
|
||||||
|
|
||||||
|
import me.main__.util.SerializationConfig.ChangeDeniedException;
|
||||||
|
import me.main__.util.SerializationConfig.ObjectUsingValidator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates world-property-changes.
|
||||||
|
* @param <T> The type of the property that should be validated.
|
||||||
|
*/
|
||||||
|
public class WorldPropertyValidator<T> extends ObjectUsingValidator<T, MVWorld> {
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public T validateChange(String property, T newValue, T oldValue, MVWorld object) throws ChangeDeniedException {
|
||||||
|
MVWorldPropertyChangeEvent<T> event = new MVWorldPropertyChangeEvent<T>(object, null, property, newValue);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled())
|
||||||
|
throw new ChangeDeniedException();
|
||||||
|
return event.getTheNewValue();
|
||||||
|
}
|
||||||
|
}
|
@ -99,4 +99,13 @@ public enum EnglishChatColor {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Looks if the given-color name is a valid color.
|
||||||
|
* @param aliasColor A color-name.
|
||||||
|
* @return True if the name is a valid color, false if it isn't.
|
||||||
|
*/
|
||||||
|
public static boolean isValidAliasColor(String aliasColor) {
|
||||||
|
return (EnglishChatColor.fromString(aliasColor) != null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,16 +19,18 @@ import org.bukkit.event.HandlerList;
|
|||||||
* If it is cancelled, no change will happen.
|
* If it is cancelled, no change will happen.
|
||||||
* <p>
|
* <p>
|
||||||
* If you want to get the values of the world before the change, query the world.
|
* If you want to get the values of the world before the change, query the world.
|
||||||
* If you want to get the value being changed, use getProperty()
|
* To get the name of the property that was changed, use {@link #getPropertyName()}.
|
||||||
|
* To get the new value, use {@link #getTheNewValue()}. To change it, use {@link #setTheNewValue(Object)}.
|
||||||
|
* @param <T> The type of the property that was set.
|
||||||
*/
|
*/
|
||||||
public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
|
public class MVWorldPropertyChangeEvent<T> extends Event implements Cancellable {
|
||||||
private MultiverseWorld world;
|
private MultiverseWorld world;
|
||||||
private CommandSender changer;
|
private CommandSender changer;
|
||||||
private boolean isCancelled = false;
|
private boolean isCancelled = false;
|
||||||
private String value;
|
|
||||||
private String name;
|
private String name;
|
||||||
|
private T value;
|
||||||
|
|
||||||
public MVWorldPropertyChangeEvent(MultiverseWorld world, CommandSender changer, String name, String value) {
|
public MVWorldPropertyChangeEvent(MultiverseWorld world, CommandSender changer, String name, T value) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.changer = changer;
|
this.changer = changer;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -64,16 +66,38 @@ public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
|
|||||||
/**
|
/**
|
||||||
* Gets the new value.
|
* Gets the new value.
|
||||||
* @return The new value.
|
* @return The new value.
|
||||||
|
* @deprecated Use {@link #getTheNewValue()} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public String getNewValue() {
|
public String getNewValue() {
|
||||||
|
return this.value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the new value.
|
||||||
|
* @return The new value.
|
||||||
|
*/
|
||||||
|
public T getTheNewValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the new value.
|
* Sets the new value.
|
||||||
|
* <p>
|
||||||
|
* This method is only a stub, it'll <b>always</b> throw an {@link UnsupportedOperationException}!
|
||||||
* @param value The new new value.
|
* @param value The new new value.
|
||||||
|
* @deprecated Use {@link #setTheNewValue(Object)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setNewValue(String value) {
|
public void setNewValue(String value) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the new value.
|
||||||
|
* @param value The new value.
|
||||||
|
*/
|
||||||
|
public void setTheNewValue(T value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +112,8 @@ public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the person (or console) who was responsible for the change.
|
* Gets the person (or console) who was responsible for the change.
|
||||||
|
* <p>
|
||||||
|
* This may be null!
|
||||||
*
|
*
|
||||||
* @return The person (or console) who was responsible for the change.
|
* @return The person (or console) who was responsible for the change.
|
||||||
*/
|
*/
|
||||||
|
@ -14,4 +14,8 @@ public class PropertyDoesNotExistException extends Exception {
|
|||||||
public PropertyDoesNotExistException(String name) {
|
public PropertyDoesNotExistException(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PropertyDoesNotExistException(String name, Throwable cause) {
|
||||||
|
super(name, cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,6 +299,7 @@ public class MVPlayerListener implements Listener {
|
|||||||
// Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
|
// Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
|
||||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation());
|
player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation());
|
||||||
}
|
}
|
||||||
@ -329,6 +330,7 @@ public class MVPlayerListener implements Listener {
|
|||||||
this.plugin.log(Level.FINE, "Handeling gamemode for player: " + player.getName());
|
this.plugin.log(Level.FINE, "Handeling gamemode for player: " + player.getName());
|
||||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
||||||
if (player.getWorld() == world.getCBWorld()) {
|
if (player.getWorld() == world.getCBWorld()) {
|
||||||
@ -359,6 +361,7 @@ public class MVPlayerListener implements Listener {
|
|||||||
this.plugin.log(Level.FINE, "Handeling flight for player: " + player.getName());
|
this.plugin.log(Level.FINE, "Handeling flight for player: " + player.getName());
|
||||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
||||||
if (player.getWorld() == world.getCBWorld()) {
|
if (player.getWorld() == world.getCBWorld()) {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
package com.onarandombox.MultiverseCore.utils;
|
package com.onarandombox.MultiverseCore.utils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -54,6 +55,7 @@ public class UpdateChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkUpdate() {
|
public void checkUpdate() {
|
||||||
|
BufferedReader rd = null;
|
||||||
try {
|
try {
|
||||||
URL url = new URL("http://bukkit.onarandombox.com/multiverse/version.php?n=" + URLEncoder.encode(this.name, "UTF-8") + "&v=" + this.cversion);
|
URL url = new URL("http://bukkit.onarandombox.com/multiverse/version.php?n=" + URLEncoder.encode(this.name, "UTF-8") + "&v=" + this.cversion);
|
||||||
URLConnection conn = url.openConnection();
|
URLConnection conn = url.openConnection();
|
||||||
@ -65,7 +67,7 @@ public class UpdateChecker {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
String line;
|
String line;
|
||||||
String version = null;
|
String version = null;
|
||||||
|
|
||||||
@ -76,7 +78,6 @@ public class UpdateChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
rd.close();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,6 +93,12 @@ public class UpdateChecker {
|
|||||||
rd.close();
|
rd.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// No need to alert the user of any error here... it's not important.
|
// No need to alert the user of any error here... it's not important.
|
||||||
|
} finally {
|
||||||
|
if (rd != null) {
|
||||||
|
try {
|
||||||
|
rd.close();
|
||||||
|
} catch (IOException ignore) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
|||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||||
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
|
|
||||||
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
|
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.WorldCreator;
|
import org.bukkit.WorldCreator;
|
||||||
import org.bukkit.WorldType;
|
import org.bukkit.WorldType;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -36,6 +36,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,16 +45,16 @@ import java.util.logging.Level;
|
|||||||
public class WorldManager implements MVWorldManager {
|
public class WorldManager implements MVWorldManager {
|
||||||
private MultiverseCore plugin;
|
private MultiverseCore plugin;
|
||||||
private WorldPurger worldPurger;
|
private WorldPurger worldPurger;
|
||||||
|
private Map<String, MVWorld> worldsFromTheConfig;
|
||||||
private Map<String, MultiverseWorld> worlds;
|
private Map<String, MultiverseWorld> worlds;
|
||||||
private List<String> unloadedWorlds;
|
|
||||||
private FileConfiguration configWorlds = null;
|
private FileConfiguration configWorlds = null;
|
||||||
private Map<String, String> defaultGens;
|
private Map<String, String> defaultGens;
|
||||||
private String firstSpawn;
|
private String firstSpawn;
|
||||||
|
|
||||||
public WorldManager(MultiverseCore core) {
|
public WorldManager(MultiverseCore core) {
|
||||||
this.plugin = core;
|
this.plugin = core;
|
||||||
|
this.worldsFromTheConfig = new HashMap<String, MVWorld>();
|
||||||
this.worlds = new HashMap<String, MultiverseWorld>();
|
this.worlds = new HashMap<String, MultiverseWorld>();
|
||||||
this.unloadedWorlds = new ArrayList<String>();
|
|
||||||
this.worldPurger = new SimpleWorldPurger(plugin);
|
this.worldPurger = new SimpleWorldPurger(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +121,10 @@ public class WorldManager implements MVWorldManager {
|
|||||||
c.generateStructures(generateStructures);
|
c.generateStructures(generateStructures);
|
||||||
}
|
}
|
||||||
|
|
||||||
World world;
|
// Important: doLoad() needs the MVWorld-object in worldsFromTheConfig
|
||||||
|
if (!worldsFromTheConfig.containsKey(name))
|
||||||
|
worldsFromTheConfig.put(name, new MVWorld(useSpawnAdjust));
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("Loading World & Settings - '").append(name).append("'");
|
builder.append("Loading World & Settings - '").append(name).append("'");
|
||||||
builder.append(" - Env: ").append(env);
|
builder.append(" - Env: ").append(env);
|
||||||
@ -133,27 +137,15 @@ public class WorldManager implements MVWorldManager {
|
|||||||
}
|
}
|
||||||
this.plugin.log(Level.INFO, builder.toString());
|
this.plugin.log(Level.INFO, builder.toString());
|
||||||
|
|
||||||
try {
|
if (!doLoad(c)) {
|
||||||
world = c.createWorld();
|
|
||||||
} catch (Exception e) {
|
|
||||||
this.plugin.log(Level.SEVERE, "The world '" + name + "' could NOT be loaded because it contains errors!");
|
|
||||||
this.plugin.log(Level.SEVERE, "Try using Chukster to repair your world! '" + name + "'");
|
|
||||||
this.plugin.log(Level.SEVERE, "http://forums.bukkit.org/threads/admin-chunkster.8186/");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world == null) {
|
|
||||||
this.plugin.log(Level.SEVERE, "Failed to Create/Load the world '" + name + "'");
|
this.plugin.log(Level.SEVERE, "Failed to Create/Load the world '" + name + "'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiverseWorld mvworld = new MVWorld(world, this.configWorlds, this.plugin,
|
// set generator (special case because we can't read it from org.bukkit.World)
|
||||||
this.plugin.getServer().getWorld(name).getSeed(), generator, useSpawnAdjust);
|
this.worlds.get(name).setGenerator(generator);
|
||||||
this.worldPurger.purgeWorld(mvworld);
|
|
||||||
this.worlds.put(name, mvworld);
|
this.saveWorldsConfig();
|
||||||
if (this.unloadedWorlds.contains(name)) {
|
|
||||||
this.unloadedWorlds.remove(name);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,15 +174,11 @@ public class WorldManager implements MVWorldManager {
|
|||||||
if (!unloadWorld(name)) {
|
if (!unloadWorld(name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.configWorlds.get("worlds." + name) != null) {
|
if (this.worldsFromTheConfig.containsKey(name)) {
|
||||||
|
this.worldsFromTheConfig.remove(name);
|
||||||
this.plugin.log(Level.INFO, "World '" + name + "' was removed from config.yml");
|
this.plugin.log(Level.INFO, "World '" + name + "' was removed from config.yml");
|
||||||
this.configWorlds.set("worlds." + name, null);
|
|
||||||
|
|
||||||
this.saveWorldsConfig();
|
this.saveWorldsConfig();
|
||||||
// Remove it from the list of unloaded worlds.
|
|
||||||
if (this.unloadedWorlds.contains(name)) {
|
|
||||||
this.unloadedWorlds.remove(name);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
this.plugin.log(Level.INFO, "World '" + name + "' was already removed from config.yml");
|
this.plugin.log(Level.INFO, "World '" + name + "' was already removed from config.yml");
|
||||||
@ -238,15 +226,17 @@ public class WorldManager implements MVWorldManager {
|
|||||||
if (this.unloadWorldFromBukkit(name, true)) {
|
if (this.unloadWorldFromBukkit(name, true)) {
|
||||||
this.worlds.remove(name);
|
this.worlds.remove(name);
|
||||||
this.plugin.log(Level.INFO, "World '" + name + "' was unloaded from memory.");
|
this.plugin.log(Level.INFO, "World '" + name + "' was unloaded from memory.");
|
||||||
this.unloadedWorlds.add(name);
|
|
||||||
|
this.worldsFromTheConfig.get(name).tearDown();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
this.plugin.log(Level.WARNING, "World '" + name + "' could not be unloaded. Is it a default world?");
|
this.plugin.log(Level.WARNING, "World '" + name + "' could not be unloaded. Is it a default world?");
|
||||||
}
|
}
|
||||||
} else if (this.plugin.getServer().getWorld(name) != null) {
|
} else if (this.plugin.getServer().getWorld(name) != null) {
|
||||||
this.plugin.log(Level.WARNING, "Hmm Multiverse does not know about this world but it's loaded in memory.");
|
this.plugin.log(Level.WARNING, "Hmm Multiverse does not know about this world but it's loaded in memory.");
|
||||||
this.plugin.log(Level.WARNING, "To unload it using multiverse, use:");
|
this.plugin.log(Level.WARNING, "To let Multiverse know about it, use:");
|
||||||
this.plugin.log(Level.WARNING, "/mv import " + name + " " + this.plugin.getServer().getWorld(name).getEnvironment().toString());
|
this.plugin.log(Level.WARNING, String.format("/mv import %s %s", name, this.plugin.getServer().getWorld(name).getEnvironment().toString()));
|
||||||
} else {
|
} else {
|
||||||
this.plugin.log(Level.INFO, "Multiverse does not know about " + name + " and it's not loaded by Bukkit.");
|
this.plugin.log(Level.INFO, "Multiverse does not know about " + name + " and it's not loaded by Bukkit.");
|
||||||
}
|
}
|
||||||
@ -260,36 +250,58 @@ public class WorldManager implements MVWorldManager {
|
|||||||
public boolean loadWorld(String name) {
|
public boolean loadWorld(String name) {
|
||||||
// Check if the World is already loaded
|
// Check if the World is already loaded
|
||||||
if (this.worlds.containsKey(name)) {
|
if (this.worlds.containsKey(name)) {
|
||||||
// Ensure it's not unloaded, since it IS loaded.
|
|
||||||
if (this.unloadedWorlds.contains(name)) {
|
|
||||||
this.unloadedWorlds.remove(name);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab all the Worlds from the Config.
|
// Check that the world is in the config
|
||||||
Set<String> worldKeys = this.configWorlds.getConfigurationSection("worlds").getKeys(false);
|
if (worldsFromTheConfig.containsKey(name)) {
|
||||||
|
return doLoad(name);
|
||||||
// Check that the list is not null and that the config contains the world
|
|
||||||
if ((worldKeys != null) && (worldKeys.contains(name))) {
|
|
||||||
// Grab the initial values from the config file.
|
|
||||||
String environment = this.configWorlds.getString("worlds." + name + ".environment", "NORMAL"); // Grab the Environment as a String.
|
|
||||||
String type = this.configWorlds.getString("worlds." + name + ".type", "NORMAL");
|
|
||||||
String seedString = this.configWorlds.getString("worlds." + name + ".seed", "");
|
|
||||||
String generatorString = this.configWorlds.getString("worlds." + name + ".generator");
|
|
||||||
boolean generateStructures = this.configWorlds.getBoolean("worlds." + name + ".generatestructures", true);
|
|
||||||
|
|
||||||
this.addWorld(name, EnvironmentCommand.getEnvFromString(environment), seedString,
|
|
||||||
EnvironmentCommand.getWorldTypeFromString(type), generateStructures, generatorString);
|
|
||||||
if (this.unloadedWorlds.contains(name)) {
|
|
||||||
this.unloadedWorlds.remove(name);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void brokenWorld(String name) {
|
||||||
|
this.plugin.log(Level.SEVERE, "The world '" + name + "' could NOT be loaded because it contains errors!");
|
||||||
|
this.plugin.log(Level.SEVERE, "Try using Chukster to repair your world! '" + name + "'");
|
||||||
|
this.plugin.log(Level.SEVERE, "http://forums.bukkit.org/threads/admin-chunkster.8186/");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean doLoad(String name) {
|
||||||
|
if (!worldsFromTheConfig.containsKey(name))
|
||||||
|
throw new IllegalArgumentException("That world doesn't exist!");
|
||||||
|
|
||||||
|
MVWorld world = worldsFromTheConfig.get(name);
|
||||||
|
WorldCreator creator = WorldCreator.name(name);
|
||||||
|
|
||||||
|
creator.environment(world.getEnvironment()).seed(world.getSeed());
|
||||||
|
if ((world.getGenerator() != null) && (!world.getGenerator().equals("null")))
|
||||||
|
creator.generator(world.getGenerator());
|
||||||
|
|
||||||
|
return doLoad(creator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean doLoad(WorldCreator creator) {
|
||||||
|
String worldName = creator.name();
|
||||||
|
if (!worldsFromTheConfig.containsKey(worldName))
|
||||||
|
throw new IllegalArgumentException("That world doesn't exist!");
|
||||||
|
if (worlds.containsKey(worldName))
|
||||||
|
throw new IllegalArgumentException("That world is already loaded!");
|
||||||
|
MVWorld mvworld = worldsFromTheConfig.get(worldName);
|
||||||
|
World cbworld;
|
||||||
|
try {
|
||||||
|
cbworld = creator.createWorld();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
brokenWorld(worldName);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mvworld.init(cbworld, plugin);
|
||||||
|
this.worldPurger.purgeWorld(mvworld);
|
||||||
|
this.worlds.put(worldName, mvworld);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@ -461,30 +473,22 @@ public class WorldManager implements MVWorldManager {
|
|||||||
public void loadDefaultWorlds() {
|
public void loadDefaultWorlds() {
|
||||||
this.ensureConfigIsPrepared();
|
this.ensureConfigIsPrepared();
|
||||||
List<World> myWorlds = this.plugin.getServer().getWorlds();
|
List<World> myWorlds = this.plugin.getServer().getWorlds();
|
||||||
Set<String> worldStrings = this.configWorlds.getConfigurationSection("worlds").getKeys(false);
|
|
||||||
for (World w : myWorlds) {
|
for (World w : myWorlds) {
|
||||||
String name = w.getName();
|
String name = w.getName();
|
||||||
if (!worldStrings.contains(name)) {
|
if (!worldsFromTheConfig.containsKey(name)) {
|
||||||
|
String generator = null;
|
||||||
if (this.defaultGens.containsKey(name)) {
|
if (this.defaultGens.containsKey(name)) {
|
||||||
this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(),
|
generator = this.defaultGens.get(name);
|
||||||
w.canGenerateStructures(), this.defaultGens.get(name));
|
|
||||||
} else {
|
|
||||||
this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(),
|
|
||||||
w.canGenerateStructures(), null);
|
|
||||||
}
|
}
|
||||||
|
this.addWorld(name, w.getEnvironment(), String.valueOf(w.getSeed()), w.getWorldType(), w.canGenerateStructures(), generator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureConfigIsPrepared() {
|
private void ensureConfigIsPrepared() {
|
||||||
|
this.configWorlds.options().pathSeparator(SEPARATOR);
|
||||||
if (this.configWorlds.getConfigurationSection("worlds") == null) {
|
if (this.configWorlds.getConfigurationSection("worlds") == null) {
|
||||||
this.configWorlds.createSection("worlds");
|
this.configWorlds.createSection("worlds");
|
||||||
try {
|
|
||||||
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
|
|
||||||
} catch (IOException e) {
|
|
||||||
this.plugin.log(Level.SEVERE, "Failed to save worlds.yml. Please check your file permissions.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,13 +501,10 @@ public class WorldManager implements MVWorldManager {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
this.ensureConfigIsPrepared();
|
this.ensureConfigIsPrepared();
|
||||||
this.ensureSecondNamespaceIsPrepared();
|
this.ensureSecondNamespaceIsPrepared();
|
||||||
// Grab all the Worlds from the Config.
|
|
||||||
Set<String> worldKeys = this.configWorlds.getConfigurationSection("worlds").getKeys(false);
|
|
||||||
|
|
||||||
// Force the worlds to be loaded, ie don't just load new worlds.
|
// Force the worlds to be loaded, ie don't just load new worlds.
|
||||||
if (forceLoad) {
|
if (forceLoad) {
|
||||||
// Remove all world permissions.
|
// Remove all world permissions.
|
||||||
|
|
||||||
Permission allAccess = 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.*");
|
Permission allExempt = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*");
|
||||||
for (MultiverseWorld w : this.worlds.values()) {
|
for (MultiverseWorld w : this.worlds.values()) {
|
||||||
@ -525,45 +526,19 @@ public class WorldManager implements MVWorldManager {
|
|||||||
this.worlds.clear();
|
this.worlds.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the list is not null.
|
for (Map.Entry<String, MVWorld> entry : worldsFromTheConfig.entrySet()) {
|
||||||
if (worldKeys != null) {
|
if (worlds.containsKey(entry.getKey()))
|
||||||
for (String worldKey : worldKeys) {
|
|
||||||
// Check if the World is already loaded within the Plugin.
|
|
||||||
if (this.worlds.containsKey(worldKey)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
if (!entry.getValue().getAutoLoad())
|
||||||
|
|
||||||
// If autoload was set to false, don't load this one.
|
|
||||||
if (!this.configWorlds.getBoolean("worlds." + worldKey + ".autoload", true)) {
|
|
||||||
if (!this.unloadedWorlds.contains(worldKey)) {
|
|
||||||
this.unloadedWorlds.add(worldKey);
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
// Grab the initial values from the config file.
|
|
||||||
String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL");
|
|
||||||
String type = this.configWorlds.getString("worlds." + worldKey + ".type", "NORMAL");
|
|
||||||
String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", null);
|
|
||||||
boolean generateStructures = this.configWorlds.getBoolean("worlds." + worldKey + ".generatestructures", true);
|
|
||||||
if (seedString == null) {
|
|
||||||
seedString = this.configWorlds.getLong("worlds." + worldKey + ".seed") + "";
|
|
||||||
}
|
|
||||||
|
|
||||||
String generatorString = this.configWorlds.getString("worlds." + worldKey + ".generator");
|
if (doLoad(entry.getKey()))
|
||||||
if (environment.equalsIgnoreCase("skylands")) {
|
|
||||||
this.plugin.log(Level.WARNING, "Found SKYLANDS world. Not importing automatically, as it won't work atm :(");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
addWorld(worldKey, EnvironmentCommand.getEnvFromString(environment), seedString,
|
|
||||||
EnvironmentCommand.getWorldTypeFromString(type), generateStructures, generatorString);
|
|
||||||
|
|
||||||
// Increment the world count
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Simple Output to the Console to show how many Worlds were loaded.
|
// Simple Output to the Console to show how many Worlds were loaded.
|
||||||
this.plugin.log(Level.INFO, count + " - World(s) loaded.");
|
this.plugin.log(Level.INFO, count + " - World(s) loaded.");
|
||||||
|
this.saveWorldsConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureSecondNamespaceIsPrepared() {
|
private void ensureSecondNamespaceIsPrepared() {
|
||||||
@ -592,15 +567,54 @@ public class WorldManager implements MVWorldManager {
|
|||||||
return worldPurger;
|
return worldPurger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final char SEPARATOR = '\uF8FF';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the config from a file.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @param file The file to load.
|
|
||||||
* @return A loaded configuration.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FileConfiguration loadWorldConfig(File file) {
|
public FileConfiguration loadWorldConfig(File file) {
|
||||||
this.configWorlds = YamlConfiguration.loadConfiguration(file);
|
this.configWorlds = YamlConfiguration.loadConfiguration(file);
|
||||||
|
this.ensureConfigIsPrepared();
|
||||||
|
try {
|
||||||
|
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// load world-objects
|
||||||
|
Stack<String> worldKeys = new Stack<String>();
|
||||||
|
worldKeys.addAll(this.configWorlds.getConfigurationSection("worlds").getKeys(false));
|
||||||
|
Map<String, MVWorld> newWorldsFromTheConfig = new HashMap<String, MVWorld>();
|
||||||
|
while (!worldKeys.isEmpty()) {
|
||||||
|
String key = worldKeys.pop();
|
||||||
|
String path = "worlds" + SEPARATOR + key;
|
||||||
|
Object obj = this.configWorlds.get(path);
|
||||||
|
if ((obj != null) && (obj instanceof MVWorld)) {
|
||||||
|
String worldName = key.replaceAll(String.valueOf(SEPARATOR), ".");
|
||||||
|
if (this.worldsFromTheConfig.containsKey(worldName)) {
|
||||||
|
// Object-Recycling :D
|
||||||
|
MVWorld oldMVWorld = (MVWorld) this.worlds.get(worldName);
|
||||||
|
oldMVWorld.copyValues((MVWorld) obj);
|
||||||
|
newWorldsFromTheConfig.put(worldName, oldMVWorld);
|
||||||
|
} else {
|
||||||
|
// we have to use a new one
|
||||||
|
World cbworld = this.plugin.getServer().getWorld(worldName);
|
||||||
|
MVWorld mvworld = (MVWorld) obj;
|
||||||
|
if (cbworld != null)
|
||||||
|
mvworld.init(cbworld, this.plugin);
|
||||||
|
newWorldsFromTheConfig.put(worldName, mvworld);
|
||||||
|
}
|
||||||
|
} else if (this.configWorlds.isConfigurationSection(path)) {
|
||||||
|
ConfigurationSection section = this.configWorlds.getConfigurationSection(path);
|
||||||
|
Set<String> subkeys = section.getKeys(false);
|
||||||
|
for (String subkey : subkeys) {
|
||||||
|
worldKeys.push(key + SEPARATOR + subkey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.worldsFromTheConfig = newWorldsFromTheConfig;
|
||||||
|
this.worlds.keySet().retainAll(this.worldsFromTheConfig.keySet());
|
||||||
return this.configWorlds;
|
return this.configWorlds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,6 +624,11 @@ public class WorldManager implements MVWorldManager {
|
|||||||
@Override
|
@Override
|
||||||
public boolean saveWorldsConfig() {
|
public boolean saveWorldsConfig() {
|
||||||
try {
|
try {
|
||||||
|
this.configWorlds.options().pathSeparator(SEPARATOR);
|
||||||
|
this.configWorlds.set("worlds", null);
|
||||||
|
for (Map.Entry<String, ? extends MultiverseWorld> entry : worldsFromTheConfig.entrySet()) {
|
||||||
|
this.configWorlds.set("worlds" + SEPARATOR + entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
|
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -631,7 +650,9 @@ public class WorldManager implements MVWorldManager {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<String> getUnloadedWorlds() {
|
public List<String> getUnloadedWorlds() {
|
||||||
return this.unloadedWorlds;
|
List<String> allNames = new ArrayList<String>(this.worldsFromTheConfig.keySet());
|
||||||
|
allNames.removeAll(worlds.keySet());
|
||||||
|
return allNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,16 +26,25 @@ public abstract class HttpAPIClient {
|
|||||||
* @throws IOException When the I/O-operation failed.
|
* @throws IOException When the I/O-operation failed.
|
||||||
*/
|
*/
|
||||||
protected final String exec(Object... args) throws IOException {
|
protected final String exec(Object... args) throws IOException {
|
||||||
|
|
||||||
URLConnection conn = new URL(String.format(this.urlFormat, args)).openConnection();
|
URLConnection conn = new URL(String.format(this.urlFormat, args)).openConnection();
|
||||||
conn.connect();
|
conn.connect();
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
StringBuilder ret = new StringBuilder();
|
||||||
|
BufferedReader reader = null;
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
while (!reader.ready()); // wait until reader is ready, may not be necessary, SUPPRESS CHECKSTYLE: EmptyStatement
|
while (!reader.ready()); // wait until reader is ready, may not be necessary, SUPPRESS CHECKSTYLE: EmptyStatement
|
||||||
|
|
||||||
StringBuilder ret = new StringBuilder();
|
|
||||||
while (reader.ready()) {
|
while (reader.ready()) {
|
||||||
ret.append(reader.readLine()).append('\n');
|
ret.append(reader.readLine()).append('\n');
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
if (reader != null) {
|
||||||
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
|
} catch (IOException ignore) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
return ret.toString();
|
return ret.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@ -54,24 +55,35 @@ public class PastebinPasteService implements PasteService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String postData(String encodedData, URL url) throws PasteFailedException {
|
public String postData(String encodedData, URL url) throws PasteFailedException {
|
||||||
|
OutputStreamWriter wr = null;
|
||||||
|
BufferedReader rd = null;
|
||||||
try {
|
try {
|
||||||
URLConnection conn = url.openConnection();
|
URLConnection conn = url.openConnection();
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
|
wr = new OutputStreamWriter(conn.getOutputStream());
|
||||||
wr.write(encodedData);
|
wr.write(encodedData);
|
||||||
wr.flush();
|
wr.flush();
|
||||||
|
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
String line;
|
String line;
|
||||||
String pastebinUrl = "";
|
String pastebinUrl = "";
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
pastebinUrl = line;
|
pastebinUrl = line;
|
||||||
}
|
}
|
||||||
wr.close();
|
|
||||||
rd.close();
|
|
||||||
return pastebinUrl;
|
return pastebinUrl;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new PasteFailedException(e);
|
throw new PasteFailedException(e);
|
||||||
|
} finally {
|
||||||
|
if (wr != null) {
|
||||||
|
try {
|
||||||
|
wr.close();
|
||||||
|
} catch (IOException ignore) { }
|
||||||
|
}
|
||||||
|
if (rd != null) {
|
||||||
|
try {
|
||||||
|
rd.close();
|
||||||
|
} catch (IOException ignore) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@ -55,14 +56,16 @@ public class PastiePasteService implements PasteService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String postData(String encodedData, URL url) throws PasteFailedException {
|
public String postData(String encodedData, URL url) throws PasteFailedException {
|
||||||
|
OutputStreamWriter wr = null;
|
||||||
|
BufferedReader rd = null;
|
||||||
try {
|
try {
|
||||||
URLConnection conn = url.openConnection();
|
URLConnection conn = url.openConnection();
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
|
wr = new OutputStreamWriter(conn.getOutputStream());
|
||||||
wr.write(encodedData);
|
wr.write(encodedData);
|
||||||
wr.flush();
|
wr.flush();
|
||||||
|
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
String line;
|
String line;
|
||||||
String pastieUrl = "";
|
String pastieUrl = "";
|
||||||
Pattern pastiePattern = this.getURLMatchingPattern();
|
Pattern pastiePattern = this.getURLMatchingPattern();
|
||||||
@ -73,11 +76,20 @@ public class PastiePasteService implements PasteService {
|
|||||||
pastieUrl = this.formatURL(pastieID);
|
pastieUrl = this.formatURL(pastieID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wr.close();
|
|
||||||
rd.close();
|
|
||||||
return pastieUrl;
|
return pastieUrl;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new PasteFailedException(e);
|
throw new PasteFailedException(e);
|
||||||
|
} finally {
|
||||||
|
if (wr != null) {
|
||||||
|
try {
|
||||||
|
wr.close();
|
||||||
|
} catch (IOException ignore) { }
|
||||||
|
}
|
||||||
|
if (rd != null) {
|
||||||
|
try {
|
||||||
|
rd.close();
|
||||||
|
} catch (IOException ignore) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.onarandombox.MultiverseCore.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.World.Environment;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
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 com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
|
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||||
|
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
||||||
|
public class TestModifyCommand {
|
||||||
|
TestInstanceCreator creator;
|
||||||
|
Server mockServer;
|
||||||
|
MultiverseCore core;
|
||||||
|
CommandSender mockCommandSender;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
creator = new TestInstanceCreator();
|
||||||
|
assertTrue(creator.setUp());
|
||||||
|
mockServer = creator.getServer();
|
||||||
|
mockCommandSender = creator.getCommandSender();
|
||||||
|
core = creator.getCore();
|
||||||
|
|
||||||
|
// create world
|
||||||
|
assertTrue(core.getMVWorldManager().addWorld("world", Environment.NORMAL, null, null, null, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
creator.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetHidden() {
|
||||||
|
Command cmd = mock(Command.class);
|
||||||
|
when(cmd.getName()).thenReturn("mv");
|
||||||
|
|
||||||
|
MultiverseWorld world = core.getMVWorldManager().getMVWorld("world");
|
||||||
|
assertNotNull(world);
|
||||||
|
|
||||||
|
assertFalse(world.isHidden()); // ensure it's not hidden now
|
||||||
|
assertTrue(core.onCommand(mockCommandSender, cmd, "", // run the command
|
||||||
|
new String[] { "modify", "set", "hidden", "true", "world" }));
|
||||||
|
assertTrue(world.isHidden()); // test if it worked
|
||||||
|
}
|
||||||
|
}
|
@ -86,9 +86,6 @@ public class TestWorldCreation {
|
|||||||
assertNotNull(worldsSection);
|
assertNotNull(worldsSection);
|
||||||
assertEquals(2, worldsSection.getKeys(false).size());
|
assertEquals(2, worldsSection.getKeys(false).size());
|
||||||
assertTrue(worldsSection.getKeys(false).contains("world2"));
|
assertTrue(worldsSection.getKeys(false).contains("world2"));
|
||||||
// TODO: Uncomment once this is fixed!!!
|
assertTrue(worldsSection.getKeys(false).contains("fish.world"));
|
||||||
//assertTrue(worldsSection.getKeys(false).contains("'fish.world'"));
|
|
||||||
|
|
||||||
// Worlds with .s are a special case, verify that they work.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,14 +12,16 @@ import static org.mockito.Matchers.any;
|
|||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Difficulty;
|
import org.bukkit.Difficulty;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||||
@ -42,9 +44,11 @@ import org.powermock.api.mockito.PowerMockito;
|
|||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.MVWorld;
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
|
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
|
||||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||||
|
|
||||||
@ -89,7 +93,7 @@ public class TestWorldProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() throws Exception {
|
||||||
// Initialize a fake command
|
// Initialize a fake command
|
||||||
Command mockCommand = mock(Command.class);
|
Command mockCommand = mock(Command.class);
|
||||||
when(mockCommand.getName()).thenReturn("mv");
|
when(mockCommand.getName()).thenReturn("mv");
|
||||||
@ -127,12 +131,9 @@ public class TestWorldProperties {
|
|||||||
assertEquals(mvWorld.getName(), mvWorld.getAlias());
|
assertEquals(mvWorld.getName(), mvWorld.getAlias());
|
||||||
assertEquals(ChatColor.WHITE, mvWorld.getColor());
|
assertEquals(ChatColor.WHITE, mvWorld.getColor());
|
||||||
assertTrue(mvWorld.isPVPEnabled());
|
assertTrue(mvWorld.isPVPEnabled());
|
||||||
assertEquals((Object) 1D, (Object) mvWorld.getScaling()); // we're casting this to objects to use
|
assertEquals(1D, mvWorld.getScaling(), 0);
|
||||||
// assertEquals(Object,Object) instead of assertEquals(double,double)
|
|
||||||
assertNull(mvWorld.getRespawnToWorld());
|
assertNull(mvWorld.getRespawnToWorld());
|
||||||
assertTrue(mvWorld.isWeatherEnabled());
|
assertTrue(mvWorld.isWeatherEnabled());
|
||||||
World cbWorld = mvWorld.getCBWorld();
|
|
||||||
when(cbWorld.getDifficulty()).thenReturn(Difficulty.NORMAL);
|
|
||||||
assertEquals(Difficulty.NORMAL, mvWorld.getDifficulty());
|
assertEquals(Difficulty.NORMAL, mvWorld.getDifficulty());
|
||||||
assertTrue(mvWorld.canAnimalsSpawn());
|
assertTrue(mvWorld.canAnimalsSpawn());
|
||||||
assertTrue(mvWorld.canMonstersSpawn());
|
assertTrue(mvWorld.canMonstersSpawn());
|
||||||
@ -145,7 +146,7 @@ public class TestWorldProperties {
|
|||||||
assertTrue(mvWorld.isKeepingSpawnInMemory());
|
assertTrue(mvWorld.isKeepingSpawnInMemory());
|
||||||
assertTrue(mvWorld.getBedRespawn());
|
assertTrue(mvWorld.getBedRespawn());
|
||||||
assertTrue(mvWorld.getAutoLoad());
|
assertTrue(mvWorld.getAutoLoad());
|
||||||
assertEquals(new Location(mvWorld.getCBWorld(), 0, 64, 0), mvWorld.getSpawnLocation());
|
assertEquals(new SpawnLocation(0, 64, 0), mvWorld.getSpawnLocation());
|
||||||
|
|
||||||
/* ****************************************** *
|
/* ****************************************** *
|
||||||
* Call some events and verify behavior
|
* Call some events and verify behavior
|
||||||
@ -199,24 +200,21 @@ public class TestWorldProperties {
|
|||||||
mvWorld.setAlias("alias");
|
mvWorld.setAlias("alias");
|
||||||
assertEquals("alias", mvWorld.getAlias());
|
assertEquals("alias", mvWorld.getAlias());
|
||||||
assertTrue(mvWorld.setColor("BLACK"));
|
assertTrue(mvWorld.setColor("BLACK"));
|
||||||
ChatColor oldColor = mvWorld.getColor();
|
|
||||||
assertFalse(mvWorld.setColor("INVALID COLOR"));
|
assertFalse(mvWorld.setColor("INVALID COLOR"));
|
||||||
assertEquals(oldColor, mvWorld.getColor());
|
assertEquals(ChatColor.BLACK, mvWorld.getColor());
|
||||||
assertEquals(oldColor.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
|
assertEquals(ChatColor.BLACK.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
|
||||||
mvWorld.setPVPMode(false);
|
mvWorld.setPVPMode(false);
|
||||||
assertEquals(false, mvWorld.isPVPEnabled());
|
assertEquals(false, mvWorld.isPVPEnabled());
|
||||||
assertTrue(mvWorld.setScaling(2D));
|
assertTrue(mvWorld.setScaling(2D));
|
||||||
assertEquals((Object) 2D, (Object) mvWorld.getScaling());
|
assertEquals(2D, mvWorld.getScaling(), 0);
|
||||||
assertFalse(mvWorld.setRespawnToWorld("INVALID WORLD"));
|
assertFalse(mvWorld.setRespawnToWorld("INVALID WORLD"));
|
||||||
assertTrue(mvWorld.setRespawnToWorld("world_nether"));
|
assertTrue(mvWorld.setRespawnToWorld("world_nether"));
|
||||||
assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
|
assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
|
||||||
mvWorld.getRespawnToWorld());
|
mvWorld.getRespawnToWorld());
|
||||||
mvWorld.setEnableWeather(false);
|
mvWorld.setEnableWeather(false);
|
||||||
assertEquals(false, mvWorld.isWeatherEnabled());
|
assertEquals(false, mvWorld.isWeatherEnabled());
|
||||||
assertTrue(mvWorld.setDifficulty("PEACEFUL"));
|
assertTrue(mvWorld.setDifficulty(Difficulty.PEACEFUL));
|
||||||
Difficulty oldDifficulty = mvWorld.getDifficulty();
|
assertEquals(Difficulty.PEACEFUL, mvWorld.getDifficulty());
|
||||||
assertFalse(mvWorld.setDifficulty("INVALID DIFFICULTY"));
|
|
||||||
assertEquals(oldDifficulty, mvWorld.getDifficulty());
|
|
||||||
mvWorld.setAllowAnimalSpawn(false);
|
mvWorld.setAllowAnimalSpawn(false);
|
||||||
assertEquals(false, mvWorld.canAnimalsSpawn());
|
assertEquals(false, mvWorld.canAnimalsSpawn());
|
||||||
mvWorld.setAllowMonsterSpawn(false);
|
mvWorld.setAllowMonsterSpawn(false);
|
||||||
@ -224,17 +222,15 @@ public class TestWorldProperties {
|
|||||||
mvWorld.setCurrency(1);
|
mvWorld.setCurrency(1);
|
||||||
assertEquals(1, mvWorld.getCurrency());
|
assertEquals(1, mvWorld.getCurrency());
|
||||||
mvWorld.setPrice(1D);
|
mvWorld.setPrice(1D);
|
||||||
assertEquals((Object) 1D, (Object) mvWorld.getPrice());
|
assertEquals(1D, mvWorld.getPrice(), 0);
|
||||||
mvWorld.setHunger(false);
|
mvWorld.setHunger(false);
|
||||||
assertEquals(false, mvWorld.getHunger());
|
assertEquals(false, mvWorld.getHunger());
|
||||||
mvWorld.setAutoHeal(false);
|
mvWorld.setAutoHeal(false);
|
||||||
assertEquals(false, mvWorld.getAutoHeal());
|
assertEquals(false, mvWorld.getAutoHeal());
|
||||||
mvWorld.setAdjustSpawn(false);
|
mvWorld.setAdjustSpawn(false);
|
||||||
assertEquals(false, mvWorld.getAdjustSpawn());
|
assertEquals(false, mvWorld.getAdjustSpawn());
|
||||||
assertTrue(mvWorld.setGameMode("CREATIVE"));
|
assertTrue(mvWorld.setGameMode(GameMode.CREATIVE));
|
||||||
GameMode oldGamemode = mvWorld.getGameMode();
|
assertEquals(GameMode.CREATIVE, mvWorld.getGameMode());
|
||||||
assertFalse(mvWorld.setGameMode("INVALID GAMEMODE"));
|
|
||||||
assertEquals(oldGamemode, mvWorld.getGameMode());
|
|
||||||
mvWorld.setKeepSpawnInMemory(false);
|
mvWorld.setKeepSpawnInMemory(false);
|
||||||
assertEquals(false, mvWorld.isKeepingSpawnInMemory());
|
assertEquals(false, mvWorld.isKeepingSpawnInMemory());
|
||||||
mvWorld.setBedRespawn(false);
|
mvWorld.setBedRespawn(false);
|
||||||
@ -242,7 +238,8 @@ public class TestWorldProperties {
|
|||||||
mvWorld.setAutoLoad(false);
|
mvWorld.setAutoLoad(false);
|
||||||
assertEquals(false, mvWorld.getAutoLoad());
|
assertEquals(false, mvWorld.getAutoLoad());
|
||||||
mvWorld.setSpawnLocation(new Location(mvWorld.getCBWorld(), 1, 1, 1));
|
mvWorld.setSpawnLocation(new Location(mvWorld.getCBWorld(), 1, 1, 1));
|
||||||
assertEquals(new Location(mvWorld.getCBWorld(), 1, 1, 1), mvWorld.getSpawnLocation());
|
assertEquals(new SpawnLocation(1, 1, 1), mvWorld.getSpawnLocation());
|
||||||
|
|
||||||
|
|
||||||
/* ****************************************** *
|
/* ****************************************** *
|
||||||
* Call some events and verify behavior
|
* Call some events and verify behavior
|
||||||
@ -274,12 +271,13 @@ public class TestWorldProperties {
|
|||||||
core.getMVConfig().setPrefixChat(false);
|
core.getMVConfig().setPrefixChat(false);
|
||||||
core.getPlayerListener().playerChat(playerChatEvent);
|
core.getPlayerListener().playerChat(playerChatEvent);
|
||||||
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
|
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
|
||||||
|
mvWorld.setHidden(true); // reset hidden-state
|
||||||
|
|
||||||
// call player join events
|
// call player join events
|
||||||
core.getPlayerListener().playerJoin(playerJoinEvent);
|
core.getPlayerListener().playerJoin(playerJoinEvent);
|
||||||
verify(mockPlayer, never()).teleport(any(Location.class));
|
verify(mockPlayer, never()).teleport(any(Location.class));
|
||||||
core.getPlayerListener().playerJoin(playerNewJoinEvent);
|
core.getPlayerListener().playerJoin(playerNewJoinEvent);
|
||||||
verify(mockNewPlayer).teleport(new Location(mvWorld.getCBWorld(), 1, 1, 1));
|
verify(mockNewPlayer).teleport(new SpawnLocation(1, 1, 1));
|
||||||
|
|
||||||
// call player respawn events
|
// call player respawn events
|
||||||
core.getPlayerListener().playerRespawn(playerRespawnBed);
|
core.getPlayerListener().playerRespawn(playerRespawnBed);
|
||||||
@ -292,6 +290,44 @@ public class TestWorldProperties {
|
|||||||
core.getEntityListener().entityRegainHealth(entityRegainHealthEvent);
|
core.getEntityListener().entityRegainHealth(entityRegainHealthEvent);
|
||||||
// autoheal is off so something should happen
|
// autoheal is off so something should happen
|
||||||
verify(entityRegainHealthEvent).setCancelled(true);
|
verify(entityRegainHealthEvent).setCancelled(true);
|
||||||
|
|
||||||
|
|
||||||
|
/* ****************************************** *
|
||||||
|
* Test saving/loading
|
||||||
|
* ****************************************** */
|
||||||
|
assertTrue(core.saveMVConfigs());
|
||||||
|
// change a value here
|
||||||
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(core.getDataFolder(), "worlds.yml"));
|
||||||
|
MVWorld worldObj = (MVWorld) config.get("worlds.world");
|
||||||
|
assertTrue(worldObj.setColor("GREEN"));
|
||||||
|
config.set("worlds.world", worldObj);
|
||||||
|
config.save(new File(core.getDataFolder(), "worlds.yml"));
|
||||||
|
// load
|
||||||
|
core.loadConfigs();
|
||||||
|
|
||||||
|
mvWorld = worldManager.getMVWorld("world");
|
||||||
|
assertEquals(true, mvWorld.isHidden());
|
||||||
|
assertEquals("alias", mvWorld.getAlias());
|
||||||
|
assertEquals(ChatColor.GREEN, mvWorld.getColor());
|
||||||
|
assertEquals(ChatColor.GREEN.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
|
||||||
|
assertEquals(false, mvWorld.isPVPEnabled());
|
||||||
|
assertEquals(2D, mvWorld.getScaling(), 0);
|
||||||
|
assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
|
||||||
|
mvWorld.getRespawnToWorld());
|
||||||
|
assertEquals(false, mvWorld.isWeatherEnabled());
|
||||||
|
assertEquals(Difficulty.PEACEFUL, mvWorld.getDifficulty());
|
||||||
|
assertEquals(false, mvWorld.canAnimalsSpawn());
|
||||||
|
assertEquals(false, mvWorld.canMonstersSpawn());
|
||||||
|
assertEquals(1, mvWorld.getCurrency());
|
||||||
|
assertEquals(1D, mvWorld.getPrice(), 0);
|
||||||
|
assertEquals(false, mvWorld.getHunger());
|
||||||
|
assertEquals(false, mvWorld.getAutoHeal());
|
||||||
|
assertEquals(false, mvWorld.getAdjustSpawn());
|
||||||
|
assertEquals(GameMode.CREATIVE, mvWorld.getGameMode());
|
||||||
|
assertEquals(false, mvWorld.isKeepingSpawnInMemory());
|
||||||
|
assertEquals(false, mvWorld.getBedRespawn());
|
||||||
|
assertEquals(false, mvWorld.getAutoLoad());
|
||||||
|
assertEquals(new SpawnLocation(1, 1, 1), mvWorld.getSpawnLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createEvents(MultiverseWorld mvWorld) {
|
public void createEvents(MultiverseWorld mvWorld) {
|
||||||
|
@ -235,7 +235,7 @@ public class TestWorldStuff {
|
|||||||
// Now fail one.
|
// Now fail one.
|
||||||
plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "mode", "fish", "world" });
|
plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "mode", "fish", "world" });
|
||||||
try {
|
try {
|
||||||
verify(mockCommandSender).sendMessage(mainWorld.getProperty("mode", Object.class).getHelp());
|
verify(mockCommandSender).sendMessage(ChatColor.RED + mainWorld.getPropertyHelp("mode"));
|
||||||
} catch (PropertyDoesNotExistException e) {
|
} catch (PropertyDoesNotExistException e) {
|
||||||
fail("Mode property did not exist.");
|
fail("Mode property did not exist.");
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
import org.bukkit.Difficulty;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -28,6 +30,10 @@ public class MockWorldFactory {
|
|||||||
|
|
||||||
private static final Map<String, World> createdWorlds = new HashMap<String, World>();
|
private static final Map<String, World> createdWorlds = new HashMap<String, World>();
|
||||||
|
|
||||||
|
private static final Map<World, Boolean> pvpStates = new WeakHashMap<World, Boolean>();
|
||||||
|
private static final Map<World, Boolean> keepSpawnInMemoryStates = new WeakHashMap<World, Boolean>();
|
||||||
|
private static final Map<World, Difficulty> difficultyStates = new WeakHashMap<World, Difficulty>();
|
||||||
|
|
||||||
private MockWorldFactory() {
|
private MockWorldFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,10 +44,59 @@ public class MockWorldFactory {
|
|||||||
private static World basics(String world, World.Environment env, WorldType type) {
|
private static World basics(String world, World.Environment env, WorldType type) {
|
||||||
World mockWorld = mock(World.class);
|
World mockWorld = mock(World.class);
|
||||||
when(mockWorld.getName()).thenReturn(world);
|
when(mockWorld.getName()).thenReturn(world);
|
||||||
|
when(mockWorld.getPVP()).thenAnswer(new Answer<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
World w = (World) invocation.getMock();
|
||||||
|
if (!pvpStates.containsKey(w))
|
||||||
|
pvpStates.put(w, true); // default value
|
||||||
|
return pvpStates.get(w);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
doAnswer(new Answer<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
pvpStates.put((World) invocation.getMock(), (Boolean) invocation.getArguments()[0]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).when(mockWorld).setPVP(anyBoolean());
|
||||||
|
when(mockWorld.getKeepSpawnInMemory()).thenAnswer(new Answer<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
World w = (World) invocation.getMock();
|
||||||
|
if (!keepSpawnInMemoryStates.containsKey(w))
|
||||||
|
keepSpawnInMemoryStates.put(w, true); // default value
|
||||||
|
return keepSpawnInMemoryStates.get(w);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
doAnswer(new Answer<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
keepSpawnInMemoryStates.put((World) invocation.getMock(), (Boolean) invocation.getArguments()[0]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).when(mockWorld).setKeepSpawnInMemory(anyBoolean());
|
||||||
|
when(mockWorld.getDifficulty()).thenAnswer(new Answer<Difficulty>() {
|
||||||
|
@Override
|
||||||
|
public Difficulty answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
World w = (World) invocation.getMock();
|
||||||
|
if (!difficultyStates.containsKey(w))
|
||||||
|
difficultyStates.put(w, Difficulty.NORMAL); // default value
|
||||||
|
return difficultyStates.get(w);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
doAnswer(new Answer<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
difficultyStates.put((World) invocation.getMock(), (Difficulty) invocation.getArguments()[0]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).when(mockWorld).setDifficulty(any(Difficulty.class));
|
||||||
when(mockWorld.getEnvironment()).thenReturn(env);
|
when(mockWorld.getEnvironment()).thenReturn(env);
|
||||||
when(mockWorld.getWorldType()).thenReturn(type);
|
when(mockWorld.getWorldType()).thenReturn(type);
|
||||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
||||||
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||||
|
@Override
|
||||||
public File answer(InvocationOnMock invocation) throws Throwable {
|
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||||
if (!(invocation.getMock() instanceof World))
|
if (!(invocation.getMock() instanceof World))
|
||||||
return null;
|
return null;
|
||||||
@ -51,6 +106,7 @@ public class MockWorldFactory {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||||
|
@Override
|
||||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||||
Location loc;
|
Location loc;
|
||||||
try {
|
try {
|
||||||
@ -85,6 +141,7 @@ public class MockWorldFactory {
|
|||||||
when(mockWorld.getWorldType()).thenReturn(type);
|
when(mockWorld.getWorldType()).thenReturn(type);
|
||||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
||||||
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||||
|
@Override
|
||||||
public File answer(InvocationOnMock invocation) throws Throwable {
|
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||||
if (!(invocation.getMock() instanceof World))
|
if (!(invocation.getMock() instanceof World))
|
||||||
return null;
|
return null;
|
||||||
@ -94,6 +151,7 @@ public class MockWorldFactory {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||||
|
@Override
|
||||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||||
Location loc;
|
Location loc;
|
||||||
try {
|
try {
|
||||||
|
@ -103,6 +103,7 @@ public class TestInstanceCreator {
|
|||||||
|
|
||||||
// Give the server some worlds
|
// Give the server some worlds
|
||||||
when(mockServer.getWorld(anyString())).thenAnswer(new Answer<World>() {
|
when(mockServer.getWorld(anyString())).thenAnswer(new Answer<World>() {
|
||||||
|
@Override
|
||||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||||
String arg;
|
String arg;
|
||||||
try {
|
try {
|
||||||
@ -115,6 +116,7 @@ public class TestInstanceCreator {
|
|||||||
});
|
});
|
||||||
|
|
||||||
when(mockServer.getWorlds()).thenAnswer(new Answer<List<World>>() {
|
when(mockServer.getWorlds()).thenAnswer(new Answer<List<World>>() {
|
||||||
|
@Override
|
||||||
public List<World> answer(InvocationOnMock invocation) throws Throwable {
|
public List<World> answer(InvocationOnMock invocation) throws Throwable {
|
||||||
return MockWorldFactory.getWorlds();
|
return MockWorldFactory.getWorlds();
|
||||||
}
|
}
|
||||||
@ -124,6 +126,7 @@ public class TestInstanceCreator {
|
|||||||
|
|
||||||
when(mockServer.createWorld(Matchers.isA(WorldCreator.class))).thenAnswer(
|
when(mockServer.createWorld(Matchers.isA(WorldCreator.class))).thenAnswer(
|
||||||
new Answer<World>() {
|
new Answer<World>() {
|
||||||
|
@Override
|
||||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||||
WorldCreator arg;
|
WorldCreator arg;
|
||||||
try {
|
try {
|
||||||
@ -146,6 +149,7 @@ public class TestInstanceCreator {
|
|||||||
BukkitScheduler mockScheduler = mock(BukkitScheduler.class);
|
BukkitScheduler mockScheduler = mock(BukkitScheduler.class);
|
||||||
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class), anyLong())).
|
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class), anyLong())).
|
||||||
thenAnswer(new Answer<Integer>() {
|
thenAnswer(new Answer<Integer>() {
|
||||||
|
@Override
|
||||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||||
Runnable arg;
|
Runnable arg;
|
||||||
try {
|
try {
|
||||||
@ -158,6 +162,7 @@ public class TestInstanceCreator {
|
|||||||
}});
|
}});
|
||||||
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class))).
|
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class))).
|
||||||
thenAnswer(new Answer<Integer>() {
|
thenAnswer(new Answer<Integer>() {
|
||||||
|
@Override
|
||||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||||
Runnable arg;
|
Runnable arg;
|
||||||
try {
|
try {
|
||||||
@ -204,6 +209,7 @@ public class TestInstanceCreator {
|
|||||||
commandSenderLogger.setParent(Util.logger);
|
commandSenderLogger.setParent(Util.logger);
|
||||||
commandSender = mock(CommandSender.class);
|
commandSender = mock(CommandSender.class);
|
||||||
doAnswer(new Answer<Void>() {
|
doAnswer(new Answer<Void>() {
|
||||||
|
@Override
|
||||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
commandSenderLogger.info(ChatColor.stripColor((String) invocation.getArguments()[0]));
|
commandSenderLogger.info(ChatColor.stripColor((String) invocation.getArguments()[0]));
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user