Merge branch 'master' of github.com:Multiverse/Multiverse-Core into new-tests

Conflicts:
	src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java
This commit is contained in:
main() 2012-01-07 16:10:18 +01:00
commit 814725a2ba
121 changed files with 2954 additions and 648 deletions

View File

@ -5,7 +5,9 @@
~ with this project. ~ ~ with this project. ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<!DOCTYPE module SYSTEM "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> <!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<!-- Future reference: valid severity values are 'ignore', 'info', 'warning', 'error' --> <!-- Future reference: valid severity values are 'ignore', 'info', 'warning', 'error' -->
<module name="Checker"> <module name="Checker">
<module name="JavadocPackage"> <module name="JavadocPackage">
@ -23,7 +25,19 @@
<property name="message" value="Line has trailing spaces."/> <property name="message" value="Line has trailing spaces."/>
<property name="format" value="\s+$"/> <property name="format" value="\s+$"/>
</module> </module>
<module name="SuppressWithNearbyCommentFilter"/> <module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="SUPPRESS CHECKSTYLE: (\w+)"/>
<property name="checkFormat" value="$1"/>
</module>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="BEGIN CHECKSTYLE-SUPPRESSION\: (\w+)"/>
<property name="onCommentFormat" value="END CHECKSTYLE-SUPPRESSION\: (\w+)"/>
<property name="checkFormat" value="$1"/>
</module>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="BEGIN CHECKSTYLE-SUPPRESSION\: ALL"/>
<property name="onCommentFormat" value="END CHECKSTYLE-SUPPRESSION\: ALL"/>
</module>
<module name="TreeWalker"> <module name="TreeWalker">
<!-- Make suppression possible --> <!-- Make suppression possible -->
<module name="FileContentsHolder"/> <module name="FileContentsHolder"/>
@ -61,12 +75,16 @@
</module> </module>
<module name="IllegalImport"/> <module name="IllegalImport"/>
<module name="RedundantImport"/> <module name="RedundantImport"/>
<module name="UnusedImports"/> <module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>
<module name="MethodLength"/> <module name="MethodLength"/>
<module name="ParameterNumber"/> <module name="ParameterNumber"/>
<module name="EmptyForIteratorPad"/> <module name="EmptyForIteratorPad"/>
<module name="MethodParamPad"/> <module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/> <module name="NoWhitespaceAfter">
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS"/>
</module>
<module name="NoWhitespaceBefore"/> <module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/> <module name="OperatorWrap"/>
<module name="ParenPad"/> <module name="ParenPad"/>
@ -93,7 +111,9 @@
</module> </module>
<module name="IllegalInstantiation"/> <module name="IllegalInstantiation"/>
<module name="InnerAssignment"/> <module name="InnerAssignment"/>
<module name="MagicNumber"/> <module name="MagicNumber">
<property name="ignoreNumbers" value="-1, 0, 0.5, 1, 2, 3"/>
</module>
<module name="MissingSwitchDefault"/> <module name="MissingSwitchDefault"/>
<module name="RedundantThrows"/> <module name="RedundantThrows"/>
<module name="SimplifyBooleanExpression"/> <module name="SimplifyBooleanExpression"/>
@ -115,5 +135,8 @@
<property name="severity" value="info"/> <property name="severity" value="info"/>
</module> </module>
<module name="UpperEll"/> <module name="UpperEll"/>
<module name="Indentation"/>
<module name="MissingDeprecated"/>
<module name="MissingOverride"/>
</module> </module>
</module> </module>

View File

@ -8,14 +8,15 @@
package com.onarandombox.MultiverseCore; package com.onarandombox.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.configuration.*; import com.onarandombox.MultiverseCore.configuration.ConfigPropertyFactory;
import com.onarandombox.MultiverseCore.configuration.MVActiveConfigProperty;
import com.onarandombox.MultiverseCore.configuration.MVConfigProperty;
import com.onarandombox.MultiverseCore.enums.EnglishChatColor; import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent; import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException; import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import com.onarandombox.MultiverseCore.utils.BlockSafety; import com.onarandombox.MultiverseCore.utils.BlockSafety;
import com.onarandombox.MultiverseCore.utils.LocationManipulation; import com.onarandombox.MultiverseCore.utils.LocationManipulation;
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter; import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Difficulty; import org.bukkit.Difficulty;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -31,11 +32,16 @@ import org.bukkit.permissions.PermissionDefault;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
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.logging.Level; import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* The implementation of a Multiverse handled world. * The implementation of a Multiverse handled world.
@ -53,7 +59,6 @@ public class MVWorld implements MultiverseWorld {
private Map<String, List<String>> masterList; private Map<String, List<String>> masterList;
private Map<String, MVConfigProperty<?>> propertyList; private Map<String, MVConfigProperty<?>> propertyList;
private String generator;
private Permission permission; private Permission permission;
private Permission exempt; private Permission exempt;
@ -62,6 +67,20 @@ public class MVWorld implements MultiverseWorld {
private Map<String, String> propertyAliases; private Map<String, String> propertyAliases;
private Permission ignoreperm; private Permission ignoreperm;
private static final Map<String, String> TIME_ALIASES;
static {
Map<String, String> staticTimes = new HashMap<String, String>();
staticTimes.put("morning", "8:00");
staticTimes.put("day", "12:00");
staticTimes.put("noon", "12:00");
staticTimes.put("midnight", "0:00");
staticTimes.put("night", "20:00");
// now set TIME_ALIASES to a "frozen" map
TIME_ALIASES = Collections.unmodifiableMap(staticTimes);
}
public MVWorld(World world, FileConfiguration config, MultiverseCore instance, Long seed, String generatorString, boolean fixSpawn) { public MVWorld(World world, FileConfiguration config, MultiverseCore instance, Long seed, String generatorString, boolean fixSpawn) {
this.config = config; this.config = config;
this.plugin = instance; this.plugin = instance;
@ -97,29 +116,57 @@ public class MVWorld implements MultiverseWorld {
// getNewProperty(name, defaultValue, yamlConfigNode, helpText) // getNewProperty(name, defaultValue, yamlConfigNode, helpText)
// //
// If the first type is used, name is used as the yamlConfigNode // If the first type is used, name is used as the yamlConfigNode
this.propertyList.put("hidden", fac.getNewProperty("hidden", false, "Sorry, 'hidden' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); this.propertyList.put("hidden", fac.getNewProperty("hidden", false,
this.propertyList.put("alias", fac.getNewProperty("alias", "", "alias.name", "Alias must be a valid string.")); "Sorry, 'hidden' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
this.propertyList.put("color", fac.getNewProperty("color", EnglishChatColor.WHITE, "alias.color", "Sorry, 'color' must either one of: " + EnglishChatColor.getAllColors())); this.propertyList.put("alias", fac.getNewProperty("alias", "", "alias.name",
this.propertyList.put("pvp", fac.getNewProperty("pvp", true, "Sorry, 'pvp' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); "Alias must be a valid string."));
this.propertyList.put("scale", fac.getNewProperty("scale", this.getDefaultScale(this.environment), "Scale must be a positive double value. ex: " + ChatColor.GOLD + "2.3")); this.propertyList.put("color", fac.getNewProperty("color", EnglishChatColor.WHITE, "alias.color",
this.propertyList.put("respawn", fac.getNewProperty("respawn", "", "respawnworld", "You must set this to the " + ChatColor.GOLD + " NAME" + ChatColor.RED + " not alias of a world.")); "Sorry, 'color' must either one of: " + EnglishChatColor.getAllColors()));
this.propertyList.put("weather", fac.getNewProperty("weather", true, "allowweather", "Sorry, 'weather' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); this.propertyList.put("pvp", fac.getNewProperty("pvp", true, "pvp",
this.propertyList.put("difficulty", fac.getNewProperty("difficulty", Difficulty.EASY, "Difficulty must be set as one of the following: " + ChatColor.GREEN + "peaceful " + ChatColor.AQUA + "easy " + ChatColor.GOLD + "normal " + ChatColor.RED + "hard")); "Sorry, 'pvp' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE
this.propertyList.put("animals", fac.getNewProperty("animals", true, "animals.spawn", "Sorry, 'animals' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".", "setActualPVP"));
this.propertyList.put("monsters", fac.getNewProperty("monsters", true, "monsters.spawn", "Sorry, 'monsters' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); this.propertyList.put("scale", fac.getNewProperty("scale", this.getDefaultScale(this.environment), "scale",
this.propertyList.put("currency", fac.getNewProperty("currency", -1, "entryfee.currency", "Currency must be an integer between -1 and the highest Minecraft item ID.")); "Scale must be a positive double value. ex: " + ChatColor.GOLD + "2.3", "verifyScaleSetProperly"));
this.propertyList.put("price", fac.getNewProperty("price", 0.0, "entryfee.price", "Price must be a double value. ex: " + ChatColor.GOLD + "1.2" + ChatColor.WHITE + ". Set to a negative value to give players money for entering this world.")); this.propertyList.put("respawn", fac.getNewProperty("respawn", "", "respawnworld",
this.propertyList.put("hunger", fac.getNewProperty("hunger", true, "Sorry, 'hunger' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); "You must set this to the " + ChatColor.GOLD + " NAME" + ChatColor.RED + " not alias of a world."));
this.propertyList.put("autoheal", fac.getNewProperty("autoheal", true, "Sorry, 'autoheal' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); this.propertyList.put("weather", fac.getNewProperty("weather", true, "allowweather",
this.propertyList.put("adjustspawn", fac.getNewProperty("adjustspawn", true, "Sorry, 'adjustspawn' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); "Sorry, 'weather' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE
+ "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".", "setActualWeather"));
this.propertyList.put("difficulty", fac.getNewProperty("difficulty", Difficulty.EASY,
"Difficulty must be set as one of the following: " + ChatColor.GREEN + "peaceful "
+ ChatColor.AQUA + "easy " + ChatColor.GOLD + "normal " + ChatColor.RED + "hard"));
this.propertyList.put("animals", fac.getNewProperty("animals", true, "animals.spawn",
"Sorry, 'animals' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE
+ "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".", "syncMobs"));
this.propertyList.put("monsters", fac.getNewProperty("monsters", true, "monsters.spawn",
"Sorry, 'monsters' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE
+ "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".", "syncMobs"));
this.propertyList.put("currency", fac.getNewProperty("currency", -1, "entryfee.currency",
"Currency must be an integer between -1 and the highest Minecraft item ID."));
this.propertyList.put("price", fac.getNewProperty("price", 0.0, "entryfee.price",
"Price must be a double value. ex: " + ChatColor.GOLD + "1.2" + ChatColor.WHITE
+ ". Set to a negative value to give players money for entering this world."));
this.propertyList.put("hunger", fac.getNewProperty("hunger", true,
"Sorry, 'hunger' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
this.propertyList.put("autoheal", fac.getNewProperty("autoheal", true,
"Sorry, 'autoheal' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
this.propertyList.put("adjustspawn", fac.getNewProperty("adjustspawn", true,
"Sorry, 'adjustspawn' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE
+ "or" + ChatColor.RED + " false" + ChatColor.WHITE + "."));
if (!fixSpawn) { if (!fixSpawn) {
this.setAdjustSpawn(false); this.setAdjustSpawn(false);
} }
this.propertyList.put("gamemode", fac.getNewProperty("gamemode", GameMode.SURVIVAL, "GameMode must be set as one of the following: " + ChatColor.RED + "survival " + ChatColor.GREEN + "creative ")); this.propertyList.put("gamemode", fac.getNewProperty("gamemode", GameMode.SURVIVAL,
this.propertyList.put("memory", fac.getNewProperty("keepspawninmemory", true, "keepspawninmemory", "Sorry, 'memory' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); "GameMode must be set as one of the following: " + ChatColor.RED + "survival " + ChatColor.GREEN + "creative "));
this.propertyList.put("spawn", fac.getNewProperty("spawn", this.world.getSpawnLocation(), "There is no help available for this variable. Go bug Rigby90 about it.")); this.propertyList.put("memory", fac.getNewProperty("keepspawninmemory", true, "keepspawninmemory",
this.propertyList.put("autoload", fac.getNewProperty("autoload", true, "Set this to false ONLY if you don't want this world to load itself on server restart.")); "Sorry, 'memory' must either be:" + ChatColor.GREEN + " true "
+ ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".", "setActualKeepSpawnInMemory"));
this.propertyList.put("spawn", fac.getNewProperty("spawn", this.world.getSpawnLocation(), "spawn",
"There is no help available for this variable. Go bug Rigby90 about it.", "setActualKeepSpawnInMemory"));
this.propertyList.put("autoload", fac.getNewProperty("autoload", true,
"Set this to false ONLY if you don't want this world to load itself on server restart."));
this.propertyList.put("bedrespawn", fac.getNewProperty("bedrespawn", true, "If a player dies in this world, shoudld they go to their bed?")); this.propertyList.put("bedrespawn", fac.getNewProperty("bedrespawn", true, "If a player dies in this world, shoudld they go to their bed?"));
this.propertyList.put("time", fac.getNewProperty("time", "", "Set the time to whatever you want! (Will NOT freeze time)", "setActualTime", true));
this.getKnownProperty("spawn", Location.class).setValue(this.readSpawnFromConfig(this.getCBWorld())); this.getKnownProperty("spawn", Location.class).setValue(this.readSpawnFromConfig(this.getCBWorld()));
@ -144,9 +191,11 @@ public class MVWorld implements MultiverseWorld {
this.permission = new Permission("multiverse.access." + this.getName(), "Allows access to " + this.getName(), PermissionDefault.OP); this.permission = new Permission("multiverse.access." + this.getName(), "Allows access to " + this.getName(), PermissionDefault.OP);
// This guy is special. He shouldn't be added to any parent perms. // This guy is special. He shouldn't be added to any parent perms.
this.ignoreperm = new Permission("mv.bypass.gamemode." + this.getName(), "Allows players with this permission to ignore gamemode changes.", PermissionDefault.FALSE); this.ignoreperm = new Permission("mv.bypass.gamemode." + this.getName(),
"Allows players with this permission to ignore gamemode changes.", PermissionDefault.FALSE);
this.exempt = new Permission("multiverse.exempt." + this.getName(), "A player who has this does not pay to enter this world, or use any MV portals in it " + this.getName(), PermissionDefault.OP); this.exempt = new Permission("multiverse.exempt." + this.getName(),
"A player who has this does not pay to enter this world, or use any MV portals in it " + this.getName(), PermissionDefault.OP);
try { try {
this.plugin.getServer().getPluginManager().addPermission(this.permission); this.plugin.getServer().getPluginManager().addPermission(this.permission);
this.plugin.getServer().getPluginManager().addPermission(this.exempt); this.plugin.getServer().getPluginManager().addPermission(this.exempt);
@ -158,51 +207,53 @@ public class MVWorld implements MultiverseWorld {
} }
/** /**
* Applies all settings to the Bukkit-{@link World}. * Used by the active PVP-property to set the "actual" PVP-property.
* @return True if the property was successfully set.
*/ */
public void changeActiveEffects() { public boolean setActualPVP() {
// Disable any current weather
if (!this.getKnownProperty("weather", Boolean.class).getValue()) {
this.getCBWorld().setStorm(false);
this.getCBWorld().setThundering(false);
}
// Set the spawn location
Location spawnLocation = this.getKnownProperty("spawn", Location.class).getValue();
this.getCBWorld().setSpawnLocation(spawnLocation.getBlockX(), spawnLocation.getBlockY(), spawnLocation.getBlockZ());
// Synchronize all Mob settings
this.syncMobs();
// Ensure the memory setting is correct
this.world.setKeepSpawnInMemory(this.getKnownProperty("memory", Boolean.class).getValue());
// Set the PVP mode // Set the PVP mode
this.world.setPVP(this.getKnownProperty("pvp", Boolean.class).getValue()); this.world.setPVP(this.getKnownProperty("pvp", Boolean.class).getValue());
return true;
}
/**
* Used by the active scale-property to set the "actual" scale-property.
* @return True if the property was successfully set.
*/
public boolean verifyScaleSetProperly() {
// Ensure the scale is above 0 // Ensure the scale is above 0
if (this.getKnownProperty("scale", Double.class).getValue() <= 0) { if (this.getKnownProperty("scale", Double.class).getValue() <= 0) {
// Disallow negative or 0 scalings. // Disallow negative or 0 scalings.
this.getKnownProperty("scale", Double.class).setValue(1.0); this.getKnownProperty("scale", Double.class).setValue(1.0);
this.plugin.log(Level.WARNING, "Someone tried to set a scale <= 0, defaulting to 1."); this.plugin.log(Level.WARNING, "Someone tried to set a scale <= 0, defaulting to 1.");
} }
return true;
// Set the gamemode
// TODO: Move this to a per world gamemode
if (MultiverseCore.EnforceGameModes) {
for (Player p : this.plugin.getServer().getWorld(this.getName()).getPlayers()) {
this.plugin.log(Level.FINER, "Setting " + p.getName() + "'s GameMode to " + this.getKnownProperty("mode", GameMode.class).getValue().toString());
this.plugin.getPlayerListener().handleGameMode(p, this);
}
} }
// Set the difficulty /**
this.getCBWorld().setDifficulty(this.getKnownProperty("diff", Difficulty.class).getValue()); * Used by the active keepSpawnInMemory-property to set the "actual" property.
* @return True if the property was successfully set.
*/
public boolean setActualKeepSpawnInMemory() {
// Ensure the memory setting is correct
this.world.setKeepSpawnInMemory(this.getKnownProperty("memory", Boolean.class).getValue());
return true;
}
/**
* Used by the active spawn-property to set the "actual" property.
* @return True if the property was successfully set.
*/
public boolean setActualSpawn() {
// Set the spawn location
Location spawnLocation = this.getKnownProperty("spawn", Location.class).getValue();
this.getCBWorld().setSpawnLocation(spawnLocation.getBlockX(), spawnLocation.getBlockY(), spawnLocation.getBlockZ());
return true;
} }
private double getDefaultScale(Environment environment) { private double getDefaultScale(Environment environment) {
if (environment == Environment.NETHER) { if (environment == Environment.NETHER) {
return 8.0; return 8.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck
} }
return 1.0; return 1.0;
} }
@ -342,7 +393,12 @@ public class MVWorld implements MultiverseWorld {
return false; return false;
} }
private void syncMobs() { /**
* Ensure that the value of the animals and monsters config
* properties are set in accordance with the current animals
* and monsters in the world, respectively.
*/
public void syncMobs() {
if (this.getAnimalList().isEmpty()) { if (this.getAnimalList().isEmpty()) {
this.world.setSpawnFlags(this.world.getAllowMonsters(), this.getKnownProperty("animals", Boolean.class).getValue()); this.world.setSpawnFlags(this.world.getAllowMonsters(), this.getKnownProperty("animals", Boolean.class).getValue());
@ -396,6 +452,8 @@ public class MVWorld implements MultiverseWorld {
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @deprecated Use {@link #getProperty(String, Class)} instead
*/ */
@Override @Override
@Deprecated @Deprecated
@ -464,12 +522,40 @@ public class MVWorld implements MultiverseWorld {
value = propertyChangeEvent.getNewValue(); value = propertyChangeEvent.getNewValue();
} }
if (property.parseValue(value)) { if (property.parseValue(value)) {
if (property instanceof MVActiveConfigProperty) {
return this.setActiveProperty((MVActiveConfigProperty<?>) property);
}
this.saveConfig(); this.saveConfig();
return true; return true;
} }
return false; return false;
} }
private boolean setActiveProperty(MVActiveConfigProperty<?> property) {
try {
if (property.getMethod() == null) {
// This property did not have a method.
return true;
}
Method method = this.getClass().getMethod(property.getMethod());
Object returnVal = method.invoke(this);
if (returnVal instanceof Boolean) {
return (Boolean) returnVal;
} else {
return true;
}
} catch (NoSuchMethodException e) {
System.out.println(e);
return false;
} catch (IllegalAccessException e) {
System.out.println(e);
return false;
} catch (InvocationTargetException e) {
System.out.println(e);
return false;
}
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -681,6 +767,8 @@ public class MVWorld implements MultiverseWorld {
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @deprecated This is deprecated.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -756,7 +844,6 @@ public class MVWorld implements MultiverseWorld {
private void saveConfig() { private void saveConfig() {
if (this.canSave) { if (this.canSave) {
try { try {
this.changeActiveEffects();
this.config.save(new File(this.plugin.getDataFolder(), "worlds.yml")); this.config.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
} catch (IOException e) { } catch (IOException e) {
this.plugin.log(Level.SEVERE, "Could not save worlds.yml. Please check your filesystem permissions."); this.plugin.log(Level.SEVERE, "Could not save worlds.yml. Please check your filesystem permissions.");
@ -769,7 +856,25 @@ public class MVWorld implements MultiverseWorld {
*/ */
@Override @Override
public boolean setGameMode(String gameMode) { public boolean setGameMode(String gameMode) {
return this.setKnownProperty("mode", gameMode + "", null); return this.setKnownProperty("mode", gameMode, null);
}
/**
* Sets the actual gamemode by iterating through players.
*
* gameMode is not used, but it's in the reflection template.
*
* Needs a bit o' refactoring.
*
* @return True if the gamemodes of players were set successfully. (always)
*/
public boolean setActualGameMode() {
for (Player p : this.plugin.getServer().getWorld(this.getName()).getPlayers()) {
this.plugin.log(Level.FINER, String.format("Setting %s's GameMode to %s",
p.getName(), this.getKnownProperty("mode", GameMode.class).getValue().toString()));
this.plugin.getPlayerListener().handleGameMode(p, this);
}
return true;
} }
/** /**
@ -788,6 +893,19 @@ public class MVWorld implements MultiverseWorld {
this.setKnownProperty("weather", weather + "", null); this.setKnownProperty("weather", weather + "", null);
} }
/**
* Used by the active weather-property to set the "actual" property.
* @return True if the property was successfully set.
*/
public boolean setActualWeather() {
// Disable any current weather
if (!this.getKnownProperty("weather", Boolean.class).getValue()) {
this.getCBWorld().setStorm(false);
this.getCBWorld().setThundering(false);
}
return true;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -830,6 +948,9 @@ public class MVWorld implements MultiverseWorld {
this.saveConfig(); this.saveConfig();
} }
private static final int SPAWN_LOCATION_SEARCH_TOLERANCE = 16;
private static final int SPAWN_LOCATION_SEARCH_RADIUS = 16;
private Location readSpawnFromConfig(World w) { private Location readSpawnFromConfig(World w) {
Location spawnLocation = w.getSpawnLocation(); Location spawnLocation = w.getSpawnLocation();
Location configLocation = this.getSpawnLocation(); Location configLocation = this.getSpawnLocation();
@ -850,7 +971,8 @@ public class MVWorld implements MultiverseWorld {
// If it's not, find a better one. // If it's not, find a better one.
this.plugin.log(Level.WARNING, "Spawn location from world.dat file was unsafe. Adjusting..."); this.plugin.log(Level.WARNING, "Spawn location from world.dat file was unsafe. Adjusting...");
this.plugin.log(Level.WARNING, "Original Location: " + LocationManipulation.strCoordsRaw(spawnLocation)); this.plugin.log(Level.WARNING, "Original Location: " + LocationManipulation.strCoordsRaw(spawnLocation));
Location newSpawn = teleporter.getSafeLocation(spawnLocation, 16, 16); Location newSpawn = teleporter.getSafeLocation(spawnLocation,
SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS);
// I think we could also do this, as I think this is what Notch does. // I think we could also do this, as I think this is what Notch does.
// Not sure how it will work in the nether... // Not sure how it will work in the nether...
//Location newSpawn = this.spawnLocation.getWorld().getHighestBlockAt(this.spawnLocation).getLocation(); //Location newSpawn = this.spawnLocation.getWorld().getHighestBlockAt(this.spawnLocation).getLocation();
@ -865,7 +987,8 @@ public class MVWorld implements MultiverseWorld {
if (newerSpawn != null) { if (newerSpawn != null) {
this.setSpawnLocation(newerSpawn); this.setSpawnLocation(newerSpawn);
configLocation = this.getSpawnLocation(); configLocation = this.getSpawnLocation();
this.plugin.log(Level.INFO, "New Spawn for '" + this.getName() + "' is Located at: " + LocationManipulation.locationToString(configLocation)); this.plugin.log(Level.INFO, "New Spawn for '" + this.getName()
+ "' is Located at: " + LocationManipulation.locationToString(configLocation));
} else { } else {
this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!"); this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!");
} }
@ -897,7 +1020,12 @@ public class MVWorld implements MultiverseWorld {
*/ */
@Override @Override
public boolean setDifficulty(String difficulty) { public boolean setDifficulty(String difficulty) {
return this.setKnownProperty("diff", difficulty, null); if (this.setKnownProperty("diff", difficulty, null)) {
// Set the difficulty
this.getCBWorld().setDifficulty(this.getKnownProperty("diff", Difficulty.class).getValue());
return true;
}
return false;
} }
/** /**
@ -978,6 +1106,87 @@ public class MVWorld implements MultiverseWorld {
return result; return result;
} }
/**
* {@inheritDoc}
*/
@Override
public String getTime() {
long time = this.getCBWorld().getTime();
// I'm tired, so they get time in 24 hour for now.
// Someone else can add 12 hr format if they want :P
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
int hours = (int) ((time / 1000 + 8) % 24);
int minutes = (int) (60 * (time % 1000) / 1000);
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
return String.format("%d:%02d", hours, minutes);
}
/**
* Used by the active time-property to set the "actual" property.
* @return True if the property was successfully set.
*/
public boolean setActualTime() {
return this.setTime(this.getKnownProperty("time", String.class).toString());
}
/**
* {@inheritDoc}
*/
@Override
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
public boolean setTime(String timeAsString) {
if (TIME_ALIASES.containsKey(timeAsString.toLowerCase())) {
return this.setTime(TIME_ALIASES.get(timeAsString.toLowerCase()));
}
// Regex that extracts a time in the following formats:
// 11:11pm, 11:11, 23:11, 1111, 1111p, and the aliases at the top of this file.
String timeRegex = "(\\d\\d?):?(\\d\\d)(a|p)?m?";
Pattern pattern = Pattern.compile(timeRegex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(timeAsString);
matcher.find();
int hour = 0;
double minute = 0;
int count = matcher.groupCount();
if (count >= 2) {
hour = Integer.parseInt(matcher.group(1));
minute = Integer.parseInt(matcher.group(2));
}
// If there were 4 matches (all, hour, min, ampm)
if (count == 4) {
// We want 24 hour time for calcs, but if they
// added a p[m], turn it into a 24 hr one.
if (matcher.group(3).equals("p")) {
hour += 12;
}
}
// Translate 24th hour to 0th hour.
if (hour == 24) { // SUPPRESS CHECKSTYLE MagicNumberCheck
hour = 0;
}
// Clamp the hour
if (hour > 23 || hour < 0) {
return false;
}
// Clamp the minute
if (minute > 59 || minute < 0) {
return false;
}
// 60 seconds in a minute, time needs to be in hrs * 1000, per
// the bukkit docs.
double totaltime = (hour + (minute / 60.0)) * 1000;
// Somehow there's an 8 hour offset...
totaltime -= 8000;
if (totaltime < 0) {
totaltime = 24000 + totaltime;
}
this.getCBWorld().setTime((long) totaltime);
return true;
}
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
@Override @Override
public String toString() { public String toString() {
StringBuilder toStringBuilder = new StringBuilder(); StringBuilder toStringBuilder = new StringBuilder();

View File

@ -14,12 +14,27 @@ import com.onarandombox.MultiverseCore.api.MVPlugin;
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.commands.*; import com.onarandombox.MultiverseCore.commands.*;
import com.onarandombox.MultiverseCore.destination.*; import com.onarandombox.MultiverseCore.destination.AnchorDestination;
import com.onarandombox.MultiverseCore.destination.BedDestination;
import com.onarandombox.MultiverseCore.destination.CannonDestination;
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
import com.onarandombox.MultiverseCore.destination.ExactDestination;
import com.onarandombox.MultiverseCore.destination.PlayerDestination;
import com.onarandombox.MultiverseCore.destination.WorldDestination;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
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;
import com.onarandombox.MultiverseCore.listeners.MVPortalAdjustListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.utils.*; import com.onarandombox.MultiverseCore.utils.AnchorManager;
import com.onarandombox.MultiverseCore.utils.DebugLog;
import com.onarandombox.MultiverseCore.utils.MVMessaging;
import com.onarandombox.MultiverseCore.utils.MVPermissions;
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
import com.onarandombox.MultiverseCore.utils.SpoutInterface;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import com.pneumaticraft.commandhandler.CommandHandler; import com.pneumaticraft.commandhandler.CommandHandler;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -50,17 +65,20 @@ import java.util.logging.Logger;
* The implementation of the Multiverse-{@link Core}. * The implementation of the Multiverse-{@link Core}.
*/ */
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private final static int Protocol = 10; private static final int PROTOCOL = 10;
// Global Multiverse config variable, states whether or not // Global Multiverse config variable, states whether or not
// Multiverse should stop other plugins from teleporting players // Multiverse should stop other plugins from teleporting players
// to worlds. // to worlds.
// TODO This is REALLY bad style! We have to change this!
// No, I'm NOT going to suppress these warnings because we HAVE TO CHANGE THIS!
public static boolean EnforceAccess; public static boolean EnforceAccess;
public static boolean EnforceGameModes;
public static boolean PrefixChat; public static boolean PrefixChat;
public static boolean DisplayPermErrors; public static boolean DisplayPermErrors;
public static boolean TeleportIntercept; public static boolean TeleportIntercept;
public static boolean FirstSpawnOverride; public static boolean FirstSpawnOverride;
public static Map<String, String> teleportQueue = new HashMap<String, String>(); public static Map<String, String> teleportQueue = new HashMap<String, String>();
public static int GlobalDebug = 0;
private AnchorManager anchorManager = new AnchorManager(this); private AnchorManager anchorManager = new AnchorManager(this);
/** /**
@ -77,6 +95,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
return null; return null;
} }
/**
* This method is used to add a teleportation to the teleportQueue.
*
* @param teleporter The name of the player that initiated the teleportation.
* @param teleportee The name of the player that was teleported.
*/
public static void addPlayerToTeleportQueue(String teleporter, String teleportee) { public static void addPlayerToTeleportQueue(String teleporter, String teleportee) {
staticLog(Level.FINEST, "Adding mapping '" + teleporter + "' => '" + teleportee + "' to teleport queue"); staticLog(Level.FINEST, "Adding mapping '" + teleporter + "' => '" + teleportee + "' to teleport queue");
teleportQueue.put(teleportee, teleporter); teleportQueue.put(teleportee, teleporter);
@ -87,9 +111,14 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
return "The Multiverse-Core Plugin"; return "The Multiverse-Core Plugin";
} }
/**
* {@inheritDoc}
* @deprecated This is now deprecated, nobody needs it any longer.
* All version info-dumping is now done with {@link MVVersionEvent}.
*/
@Override @Override
@Deprecated
public String dumpVersionInfo(String buffer) { public String dumpVersionInfo(String buffer) {
// I'm kinda cheating on this one, since we call the init event.
return buffer; return buffer;
} }
@ -106,18 +135,17 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
@Override @Override
public int getProtocolVersion() { public int getProtocolVersion() {
return MultiverseCore.Protocol; return MultiverseCore.PROTOCOL;
} }
// Useless stuff to keep us going. // Useless stuff to keep us going.
private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger LOGGER = Logger.getLogger("Minecraft");
private static DebugLog debugLog; private static DebugLog debugLog;
public static boolean MobsDisabledInDefaultWorld = false;
// Setup our Map for our Commands using the CommandHandler. // Setup our Map for our Commands using the CommandHandler.
private CommandHandler commandHandler; private CommandHandler commandHandler;
private final static String tag = "[Multiverse-Core]"; private static final String LOG_TAG = "[Multiverse-Core]";
// Multiverse Permissions Handler // Multiverse Permissions Handler
private MVPermissions ph; private MVPermissions ph;
@ -129,23 +157,22 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Setup the block/player/entity listener. // Setup the block/player/entity listener.
private MVPlayerListener playerListener = new MVPlayerListener(this); private MVPlayerListener playerListener = new MVPlayerListener(this);
private MVPortalAdjustListener portalAdjustListener = new MVPortalAdjustListener(this);
private MVEntityListener entityListener = new MVEntityListener(this); private MVEntityListener entityListener = new MVEntityListener(this);
private MVPluginListener pluginListener = new MVPluginListener(this); private MVPluginListener pluginListener = new MVPluginListener(this);
private MVWeatherListener weatherListener = new MVWeatherListener(this); private MVWeatherListener weatherListener = new MVWeatherListener(this);
public UpdateChecker updateCheck; //public UpdateChecker updateCheck;
public static int GlobalDebug = 0;
// HashMap to contain information relating to the Players. // HashMap to contain information relating to the Players.
private HashMap<String, MVPlayerSession> playerSessions; private HashMap<String, MVPlayerSession> playerSessions;
private GenericBank bank = null; private GenericBank bank = null;
private AllPay banker; private AllPay banker;
protected int pluginCount; private int pluginCount;
private DestinationFactory destFactory; private DestinationFactory destFactory;
private SpoutInterface spoutInterface = null; private SpoutInterface spoutInterface = null;
private double allpayversion = 3; private static final double ALLPAY_VERSION = 3;
private double chversion = 4; private static final double CH_VERSION = 4;
private MVMessaging messaging; private MVMessaging messaging;
private File serverFolder = new File(System.getProperty("user.dir")); private File serverFolder = new File(System.getProperty("user.dir"));
@ -185,9 +212,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.getServer().getPluginManager().disablePlugin(this); this.getServer().getPluginManager().disablePlugin(this);
return; return;
} }
this.banker = new AllPay(this, tag + " "); this.messaging = new MVMessaging();
this.banker = new AllPay(this, LOG_TAG + " ");
// Output a little snippet to show it's enabled. // Output a little snippet to show it's enabled.
this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " (API v" + Protocol + ") Enabled - By " + getAuthors()); this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " (API v" + PROTOCOL + ") Enabled - By " + getAuthors());
// Load the defaultWorldGenerators // Load the defaultWorldGenerators
this.worldManager.getDefaultWorldGenerators(); this.worldManager.getDefaultWorldGenerators();
@ -244,44 +272,34 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private boolean validateAllpay() { private boolean validateAllpay() {
try { try {
this.banker = new AllPay(this, "Verify"); this.banker = new AllPay(this, "Verify");
if (this.banker.getVersion() >= allpayversion) { if (this.banker.getVersion() >= ALLPAY_VERSION) {
return true; return true;
} else {
log.info(tag + " - Version " + this.getDescription().getVersion() + " was NOT ENABLED!!!");
log.info(tag + " A plugin that has loaded before " + this.getDescription().getName() + " has an incompatible version of AllPay!");
log.info(tag + " The Following Plugins MAY out of date!");
log.info(tag + " This plugin needs AllPay v" + allpayversion + " or higher and another plugin has loaded v" + this.banker.getVersion() + "!");
log.info(tag + AllPay.pluginsThatUseUs.toString());
return false;
} }
} catch (Throwable t) { } catch (Throwable t) {
} }
log.info(tag + " - Version " + this.getDescription().getVersion() + " was NOT ENABLED!!!"); LOGGER.info(String.format("%s - Version %s was NOT ENABLED!!!", LOG_TAG, this.getDescription().getVersion()));
log.info(tag + " A plugin that has loaded before " + this.getDescription().getName() + " has an incompatible version of AllPay!"); LOGGER.info(String.format("%s A plugin that has loaded before %s has an incompatible version of AllPay (an internal library)!",
log.info(tag + " Check the logs for [AllPay] - Version ... for PLUGIN NAME to find the culprit! Then Yell at that dev!"); LOG_TAG, this.getDescription().getName()));
log.info(tag + " Or update that plugin :P"); LOGGER.info(String.format("%s The Following Plugins MAY out of date: %s", LOG_TAG, AllPay.pluginsThatUseUs.toString()));
log.info(tag + " This plugin needs AllPay v" + allpayversion + " or higher!"); LOGGER.info(String.format("%s This plugin needs AllPay v%f or higher and another plugin has loaded v%f!",
LOG_TAG, ALLPAY_VERSION, this.banker.getVersion()));
return false; return false;
} }
private boolean validateCH() { private boolean validateCH() {
try { try {
this.commandHandler = new CommandHandler(this, null); this.commandHandler = new CommandHandler(this, null);
if (this.commandHandler.getVersion() >= chversion) { if (this.commandHandler.getVersion() >= CH_VERSION) {
return true; return true;
} else {
log.info(tag + " - Version " + this.getDescription().getVersion() + " was NOT ENABLED!!!");
log.info(tag + " A plugin that has loaded before " + this.getDescription().getName() + " has an incompatible version of CommandHandler (an internal library)!");
log.info(tag + " Please contact this plugin author!!!!!!!");
log.info(tag + " This plugin needs CommandHandler v" + chversion + " or higher and another plugin has loaded v" + this.commandHandler.getVersion() + "!");
return false;
} }
} catch (Throwable t) { } catch (Throwable t) {
} }
log.info(tag + " - Version " + this.getDescription().getVersion() + " was NOT ENABLED!!!"); LOGGER.info(String.format("%s - Version %s was NOT ENABLED!!!", LOG_TAG, this.getDescription().getVersion()));
log.info(tag + " A plugin that has loaded before " + this.getDescription().getName() + " has an incompatible version of CommandHandler (an internal library)!"); LOGGER.info(String.format("%s A plugin that has loaded before %s has an incompatible version of CommandHandler (an internal library)!",
log.info(tag + " Please contact this plugin author!!!!!!!"); LOG_TAG, this.getDescription().getName()));
log.info(tag + " This plugin needs CommandHandler v" + chversion + " or higher!"); LOGGER.info(String.format("%s Please contact this plugin author!!!", LOG_TAG));
LOGGER.info(String.format("%s This plugin needs CommandHandler v%f or higher and another plugin has loaded v%f!",
LOG_TAG, CH_VERSION, this.commandHandler.getVersion()));
return false; return false;
} }
@ -307,7 +325,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight. pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight.
pm.registerEvent(Event.Type.PLAYER_LOGIN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight. pm.registerEvent(Event.Type.PLAYER_LOGIN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight.
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); // To prepend the world name pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); // To prepend the world name
pm.registerEvent(Event.Type.PLAYER_PORTAL, this.playerListener, Priority.Lowest, this); // To switch gamemode pm.registerEvent(Event.Type.PLAYER_PORTAL, this.playerListener, Priority.High, this);
// We want this high to have it go last, so it can cancel if needbe.
pm.registerEvent(Event.Type.PLAYER_PORTAL, this.portalAdjustListener, Priority.Lowest, this); // To handle portal correction
pm.registerEvent(Event.Type.PLAYER_CHANGED_WORLD, this.playerListener, Priority.Monitor, this); // To switch gamemode pm.registerEvent(Event.Type.PLAYER_CHANGED_WORLD, this.playerListener, Priority.Monitor, this); // To switch gamemode
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this);
@ -340,7 +361,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
GlobalDebug = this.multiverseConfig.getInt("debug", 0); GlobalDebug = this.multiverseConfig.getInt("debug", 0);
// Lets cache these values due to the fact that they will be accessed many times. // Lets cache these values due to the fact that they will be accessed many times.
EnforceAccess = this.multiverseConfig.getBoolean("enforceaccess", false); EnforceAccess = this.multiverseConfig.getBoolean("enforceaccess", false);
EnforceGameModes = this.multiverseConfig.getBoolean("enforcegamemodes", true);
PrefixChat = this.multiverseConfig.getBoolean("worldnameprefix", true); PrefixChat = this.multiverseConfig.getBoolean("worldnameprefix", true);
// Should MV Intercept teleports by other plugins? // Should MV Intercept teleports by other plugins?
TeleportIntercept = this.multiverseConfig.getBoolean("teleportintercept", true); TeleportIntercept = this.multiverseConfig.getBoolean("teleportintercept", true);
@ -348,13 +368,21 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
FirstSpawnOverride = this.multiverseConfig.getBoolean("firstspawnoverride", true); FirstSpawnOverride = this.multiverseConfig.getBoolean("firstspawnoverride", true);
// Should permissions errors display to users? // Should permissions errors display to users?
DisplayPermErrors = this.multiverseConfig.getBoolean("displaypermerrors", true); DisplayPermErrors = this.multiverseConfig.getBoolean("displaypermerrors", true);
this.messaging = new MVMessaging(this);
this.messaging.setCooldown(this.multiverseConfig.getInt("messagecooldown", 5000)); this.messaging.setCooldown(this.multiverseConfig.getInt("messagecooldown", 5000)); // SUPPRESS CHECKSTYLE: MagicNumberCheck
// Update the version of the config!
this.multiverseConfig.set("version", coreDefaults.get("version"));
// Remove old values.
this.multiverseConfig.set("enforcegamemodes", null);
this.multiverseConfig.set("bedrespawn", null);
this.multiverseConfig.set("opfallback", null);
this.saveMVConfigs(); this.saveMVConfigs();
} }
/** /**
* Safely return a world name * Safely return a world name.
* (The tests call this with no worlds loaded) * (The tests call this with no worlds loaded)
* *
* @return The default world name. * @return The default world name.
@ -476,6 +504,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
staticLog(level, msg); staticLog(level, msg);
} }
/**
* Logs a message at the specified level.
*
* @param level The Log-{@link Level}.
* @param msg The message to log.
*/
public static void staticLog(Level level, String msg) { public static void staticLog(Level level, String msg) {
if (level == Level.FINE && GlobalDebug >= 1) { if (level == Level.FINE && GlobalDebug >= 1) {
staticDebugLog(Level.INFO, msg); staticDebugLog(Level.INFO, msg);
@ -487,8 +521,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
staticDebugLog(Level.INFO, msg); staticDebugLog(Level.INFO, msg);
return; return;
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) { } else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
log.log(level, tag + " " + msg); LOGGER.log(level, String.format("%s %s", LOG_TAG, msg));
debugLog.log(level, tag + " " + msg); debugLog.log(level, String.format("%s %s", LOG_TAG, msg));
} }
} }
@ -500,7 +534,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
* @param msg The message * @param msg The message
*/ */
public static void staticDebugLog(Level level, String msg) { public static void staticDebugLog(Level level, String msg) {
log.log(level, "[MVCore-Debug] " + msg); LOGGER.log(level, "[MVCore-Debug] " + msg);
debugLog.log(level, "[MVCore-Debug] " + msg); debugLog.log(level, "[MVCore-Debug] " + msg);
} }
@ -544,7 +578,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
*/ */
// TODO this should be static! // TODO this should be static!
public String getTag() { public String getTag() {
return MultiverseCore.tag; return MultiverseCore.LOG_TAG;
} }
// TODO This code should get moved somewhere more appropriate, but for now, it's here. // TODO This code should get moved somewhere more appropriate, but for now, it's here.
@ -585,6 +619,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
sender.sendMessage("Type " + ChatColor.DARK_AQUA + "/mv import ?" + ChatColor.WHITE + " for help!"); sender.sendMessage("Type " + ChatColor.DARK_AQUA + "/mv import ?" + ChatColor.WHITE + " for help!");
} }
/**
* Removes a player-session.
*
* @param player The {@link Player} that owned the session.
*/
public void removePlayerSession(Player player) { public void removePlayerSession(Player player) {
if (this.playerSessions.containsKey(player.getName())) { if (this.playerSessions.containsKey(player.getName())) {
this.playerSessions.remove(player.getName()); this.playerSessions.remove(player.getName());
@ -672,6 +711,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.serverFolder = newServerFolder; this.serverFolder = newServerFolder;
} }
/**
* Initializes Spout.
*/
public void setSpout() { public void setSpout() {
this.spoutInterface = new SpoutInterface(); this.spoutInterface = new SpoutInterface();
this.commandHandler.registerCommand(new SpoutCommand(this)); this.commandHandler.registerCommand(new SpoutCommand(this));
@ -686,6 +728,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
} }
} }
/**
* Gets our {@link SpoutInterface}.
*
* @return The {@link SpoutInterface} we're using.
*/
public SpoutInterface getSpout() { public SpoutInterface getSpout() {
return this.spoutInterface; return this.spoutInterface;
} }

View File

@ -7,11 +7,14 @@
package com.onarandombox.MultiverseCore.api; package com.onarandombox.MultiverseCore.api;
/**
* A fancy text.
*/
public interface FancyText { public interface FancyText {
/** /**
* TODO: Write something useful here. * Gets the {@link String}-representation of this {@link FancyText}.
* *
* @return And Here. * @return The {@link String}-representation of this {@link FancyText}.
*/ */
String getFancyText(); String getFancyText();
} }

View File

@ -8,7 +8,11 @@
package com.onarandombox.MultiverseCore.api; package com.onarandombox.MultiverseCore.api;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
/**
* This interface is implemented by every official Multiverse-plugin.
*/
public interface MVPlugin extends LoggablePlugin { public interface MVPlugin extends LoggablePlugin {
/** /**
* Adds This plugin's version information to the buffer and returns the new string. * Adds This plugin's version information to the buffer and returns the new string.
@ -16,7 +20,11 @@ public interface MVPlugin extends LoggablePlugin {
* @param buffer The string that contains Core and all other MV plugins' versions. * @param buffer The string that contains Core and all other MV plugins' versions.
* *
* @return A modified buffer that contains this MVPlugin's version information. * @return A modified buffer that contains this MVPlugin's version information.
*
* @deprecated This is now deprecated, nobody needs it any longer.
* All version info-dumping is now done with {@link MVVersionEvent}.
*/ */
@Deprecated
String dumpVersionInfo(String buffer); String dumpVersionInfo(String buffer);
/** /**

View File

@ -35,7 +35,7 @@ public interface MVWorldManager {
* @param generator The Custom generator plugin to use. * @param generator The Custom generator plugin to use.
* @return True if the world is added, false if not. * @return True if the world is added, false if not.
*/ */
public boolean addWorld(String name, Environment env, String seedString, String generator); boolean addWorld(String name, Environment env, String seedString, String generator);
/** /**
* Add a new World to the Multiverse Setup. * Add a new World to the Multiverse Setup.
@ -49,7 +49,7 @@ public interface MVWorldManager {
* @param useSpawnAdjust If true, multiverse will search for a safe spawn. If not, It will not modify the level.dat. * @param useSpawnAdjust If true, multiverse will search for a safe spawn. If not, It will not modify the level.dat.
* @return True if the world is added, false if not. * @return True if the world is added, false if not.
*/ */
public boolean addWorld(String name, Environment env, String seedString, String generator, boolean useSpawnAdjust); boolean addWorld(String name, Environment env, String seedString, String generator, boolean useSpawnAdjust);
/** /**
* Remove the world from the Multiverse list, from the * Remove the world from the Multiverse list, from the
@ -58,7 +58,7 @@ public interface MVWorldManager {
* @param name The name of the world to remove * @param name The name of the world to remove
* @return True if success, false if failure. * @return True if success, false if failure.
*/ */
public Boolean deleteWorld(String name); boolean deleteWorld(String name);
/** /**
* Remove the world from the Multiverse list, from the * Remove the world from the Multiverse list, from the
@ -69,7 +69,7 @@ public interface MVWorldManager {
* config. If false, they'll stay and the world may come back. * config. If false, they'll stay and the world may come back.
* @return True if success, false if failure. * @return True if success, false if failure.
*/ */
public Boolean deleteWorld(String name, boolean removeConfig); boolean deleteWorld(String name, boolean removeConfig);
/** /**
* Unload a world from Multiverse. * Unload a world from Multiverse.
@ -77,7 +77,7 @@ public interface MVWorldManager {
* @param name Name of the world to unload * @param name Name of the world to unload
* @return True if the world was unloaded, false if not. * @return True if the world was unloaded, false if not.
*/ */
public boolean unloadWorld(String name); boolean unloadWorld(String name);
/** /**
* Loads the world. Only use this if the world has been * Loads the world. Only use this if the world has been
@ -86,14 +86,14 @@ public interface MVWorldManager {
* @param name The name of the world to load * @param name The name of the world to load
* @return True if success, false if failure. * @return True if success, false if failure.
*/ */
public boolean loadWorld(String name); boolean loadWorld(String name);
/** /**
* Removes all players from the specified world. * Removes all players from the specified world.
* *
* @param name World to remove players from. * @param name World to remove players from.
*/ */
public void removePlayersFromWorld(String name); void removePlayersFromWorld(String name);
/** /**
* Test if a given chunk generator is valid. * Test if a given chunk generator is valid.
@ -103,14 +103,14 @@ public interface MVWorldManager {
* @param worldName The worldName to use as the default. * @param worldName The worldName to use as the default.
* @return A {@link ChunkGenerator} or null * @return A {@link ChunkGenerator} or null
*/ */
public ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName); ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName);
/** /**
* Returns a list of all the worlds Multiverse knows about. * Returns a list of all the worlds Multiverse knows about.
* *
* @return A list of {@link MultiverseWorld}. * @return A list of {@link MultiverseWorld}.
*/ */
public Collection<MultiverseWorld> getMVWorlds(); Collection<MultiverseWorld> getMVWorlds();
/** /**
@ -120,7 +120,7 @@ public interface MVWorldManager {
* @param name The name or alias of the world to get. * @param name The name or alias of the world to get.
* @return A {@link MultiverseWorld} or null. * @return A {@link MultiverseWorld} or null.
*/ */
public MultiverseWorld getMVWorld(String name); MultiverseWorld getMVWorld(String name);
/** /**
* Returns a {@link MultiverseWorld} if it exists, and null if it does not. * Returns a {@link MultiverseWorld} if it exists, and null if it does not.
@ -128,7 +128,7 @@ public interface MVWorldManager {
* @param world The Bukkit world to check. * @param world The Bukkit world to check.
* @return A {@link MultiverseWorld} or null. * @return A {@link MultiverseWorld} or null.
*/ */
public MultiverseWorld getMVWorld(World world); MultiverseWorld getMVWorld(World world);
/** /**
* Checks to see if the given name is a valid {@link MultiverseWorld}. * Checks to see if the given name is a valid {@link MultiverseWorld}.
@ -136,7 +136,7 @@ public interface MVWorldManager {
* @param name The name or alias of the world to check. * @param name The name or alias of the world to check.
* @return True if the world exists, false if not. * @return True if the world exists, false if not.
*/ */
public boolean isMVWorld(String name); boolean isMVWorld(String name);
/** /**
* Checks to see if the given world is a valid {@link MultiverseWorld}. * Checks to see if the given world is a valid {@link MultiverseWorld}.
@ -144,7 +144,7 @@ public interface MVWorldManager {
* @param world The Bukkit world to check. * @param world The Bukkit world to check.
* @return True if the world has been loaded into MV2, false if not. * @return True if the world has been loaded into MV2, false if not.
*/ */
public boolean isMVWorld(World world); boolean isMVWorld(World world);
/** /**
* Load the Worlds & Settings from the configuration file. * Load the Worlds & Settings from the configuration file.
@ -152,21 +152,21 @@ public interface MVWorldManager {
* @param forceLoad If set to true, this will perform a total * @param forceLoad If set to true, this will perform a total
* reset and not just load new worlds. * reset and not just load new worlds.
*/ */
public void loadWorlds(boolean forceLoad); void loadWorlds(boolean forceLoad);
/** /**
* Loads the Worlds & Settings for any worlds that bukkit loaded before us. * Loads the Worlds & Settings for any worlds that bukkit loaded before us.
* <p> * <p>
* This way people will _always_ have some worlds in the list. * This way people will _always_ have some worlds in the list.
*/ */
public void loadDefaultWorlds(); void loadDefaultWorlds();
/** /**
* Return the World Purger. * Return the World Purger.
* *
* @return A valid {@link PurgeWorlds}. * @return A valid {@link PurgeWorlds}.
*/ */
public PurgeWorlds getWorldPurger(); PurgeWorlds getWorldPurger();
/** /**
* Gets the world players will spawn in on first join. * Gets the world players will spawn in on first join.
@ -174,19 +174,19 @@ public interface MVWorldManager {
* *
* @return A Multiverse world that players will spawn in or null if no MV world has been set. * @return A Multiverse world that players will spawn in or null if no MV world has been set.
*/ */
public MultiverseWorld getSpawnWorld(); MultiverseWorld getSpawnWorld();
/** /**
* Gets the list of worlds in the config, but unloaded. * Gets the list of worlds in the config, but unloaded.
* *
* @return A List of worlds as strings. * @return A List of worlds as strings.
*/ */
public List<String> getUnloadedWorlds(); List<String> getUnloadedWorlds();
/** /**
* This method populates an internal list and needs to be called after multiverse initialization. * This method populates an internal list and needs to be called after multiverse initialization.
*/ */
public void getDefaultWorldGenerators(); void getDefaultWorldGenerators();
/** /**
* Load the config from a file. * Load the config from a file.
@ -194,14 +194,14 @@ public interface MVWorldManager {
* @param file The file to load. * @param file The file to load.
* @return A loaded configuration. * @return A loaded configuration.
*/ */
public FileConfiguration loadWorldConfig(File file); FileConfiguration loadWorldConfig(File file);
/** /**
* Saves the world config to disk. * Saves the world config to disk.
* *
* @return True if success, false if fail. * @return True if success, false if fail.
*/ */
public boolean saveWorldsConfig(); boolean saveWorldsConfig();
/** /**
* Remove the world from the Multiverse list and from the config. * Remove the world from the Multiverse list and from the config.
@ -209,19 +209,19 @@ public interface MVWorldManager {
* @param name The name of the world to remove * @param name The name of the world to remove
* @return True if success, false if failure. * @return True if success, false if failure.
*/ */
public boolean removeWorldFromConfig(String name); boolean removeWorldFromConfig(String name);
/** /**
* Sets the initial spawn world for new players. * Sets the initial spawn world for new players.
* *
* @param world The World new players should spawn in. * @param world The World new players should spawn in.
*/ */
public void setFirstSpawnWorld(String world); void setFirstSpawnWorld(String world);
/** /**
* Gets the world players should spawn in first. * Gets the world players should spawn in first.
* *
* @return The {@link MultiverseWorld} new players should spawn in. * @return The {@link MultiverseWorld} new players should spawn in.
*/ */
public MultiverseWorld getFirstSpawnWorld(); MultiverseWorld getFirstSpawnWorld();
} }

View File

@ -217,6 +217,7 @@ public interface MultiverseWorld {
* Turn pvp on or off. This setting is used to set the world's PVP mode, and thus relies on fakePVP * Turn pvp on or off. This setting is used to set the world's PVP mode, and thus relies on fakePVP
* *
* @return True if this world has fakepvp on * @return True if this world has fakepvp on
* @deprecated This is deprecated.
*/ */
@Deprecated @Deprecated
boolean getFakePVP(); boolean getFakePVP();
@ -532,4 +533,23 @@ public interface MultiverseWorld {
* @return All property names, with alternating colors. * @return All property names, with alternating colors.
*/ */
String getAllPropertyNames(); String getAllPropertyNames();
/**
* Sets the current time in a world.
*
* This method will take the following formats:
* 11:37am
* 4:30p
* day(morning), night, noon, midnight
*
* @param timeAsString The formatted time to set the world to.
* @return True if the time was set, false if not.
*/
boolean setTime(String timeAsString);
/**
* Same as {@link #getTime()}, but returns a string.
* @return The time as a short string: 12:34pm
*/
String getTime();
} }

View File

@ -0,0 +1,5 @@
/**
* The Multiverse-API, containing lots of interfaces that can be quite useful for other
* plugins when interacting with Multiverse.
*/
package com.onarandombox.MultiverseCore.api;

View File

@ -16,6 +16,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Allows management of Anchor Destinations.
*/
public class AnchorCommand extends PaginatedCoreCommand<String> { public class AnchorCommand extends PaginatedCoreCommand<String> {
public AnchorCommand(MultiverseCore plugin) { public AnchorCommand(MultiverseCore plugin) {
@ -32,7 +35,7 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d"); this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d");
this.addCommandExample("/mv anchors "); this.addCommandExample("/mv anchors ");
this.setPermission("multiverse.core.anchor", "Allows management of Anchor Destinations.", PermissionDefault.OP); this.setPermission("multiverse.core.anchor", "Allows management of Anchor Destinations.", PermissionDefault.OP);
this.setItemsPerPage(8); this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck
} }
private List<String> getFancyAnchorList(Player p) { private List<String> getFancyAnchorList(Player p) {
@ -59,7 +62,8 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
if (filterObject.getFilter().length() > 0) { if (filterObject.getFilter().length() > 0) {
availableAnchors = this.getFilteredItems(availableAnchors, filterObject.getFilter()); availableAnchors = this.getFilteredItems(availableAnchors, filterObject.getFilter());
if (availableAnchors.size() == 0) { if (availableAnchors.size() == 0) {
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No anchors matched your filter: " + ChatColor.AQUA + filterObject.getFilter()); sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
+ "No anchors matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
return; return;
} }
} else { } else {

View File

@ -17,7 +17,9 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Checks to see if a player can go to a destination.
*/
public class CheckCommand extends MultiverseCommand { public class CheckCommand extends MultiverseCommand {
public CheckCommand(MultiverseCore plugin) { public CheckCommand(MultiverseCore plugin) {

View File

@ -8,7 +8,6 @@
package com.onarandombox.MultiverseCore.commands; package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.enums.ConfigProperty; import com.onarandombox.MultiverseCore.enums.ConfigProperty;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -16,9 +15,10 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Allows you to set Global MV Variables.
*/
public class ConfigCommand extends MultiverseCommand { public class ConfigCommand extends MultiverseCommand {
private MVWorldManager worldManager;
public ConfigCommand(MultiverseCore plugin) { public ConfigCommand(MultiverseCore plugin) {
super(plugin); super(plugin);
this.setName("Configuration"); this.setName("Configuration");
@ -33,7 +33,6 @@ public class ConfigCommand extends MultiverseCommand {
this.addCommandExample("/mv config " + ChatColor.GREEN + "debug" + ChatColor.AQUA + " 3"); this.addCommandExample("/mv config " + ChatColor.GREEN + "debug" + ChatColor.AQUA + " 3");
this.addCommandExample("/mv config " + ChatColor.GREEN + "enforceaccess" + ChatColor.AQUA + " false"); this.addCommandExample("/mv config " + ChatColor.GREEN + "enforceaccess" + ChatColor.AQUA + " false");
this.setPermission("multiverse.core.config", "Allows you to set Global MV Variables.", PermissionDefault.OP); this.setPermission("multiverse.core.config", "Allows you to set Global MV Variables.", PermissionDefault.OP);
this.worldManager = this.plugin.getMVWorldManager();
} }
@Override @Override
@ -58,7 +57,8 @@ public class ConfigCommand extends MultiverseCommand {
this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), args.get(1)); this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), args.get(1));
// Don't forget to set the world! // Don't forget to set the world!
this.plugin.getMVWorldManager().setFirstSpawnWorld(args.get(1)); this.plugin.getMVWorldManager().setFirstSpawnWorld(args.get(1));
} else if (args.get(0).equalsIgnoreCase("messagecooldown") || args.get(0).equalsIgnoreCase("teleportcooldown") || args.get(0).equalsIgnoreCase("debug")) { } else if (args.get(0).equalsIgnoreCase("messagecooldown") || args.get(0).equalsIgnoreCase("teleportcooldown")
|| args.get(0).equalsIgnoreCase("debug")) {
try { try {
this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), Integer.parseInt(args.get(1))); this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), Integer.parseInt(args.get(1)));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
@ -70,7 +70,8 @@ public class ConfigCommand extends MultiverseCommand {
try { try {
property = ConfigProperty.valueOf(args.get(0).toLowerCase()); property = ConfigProperty.valueOf(args.get(0).toLowerCase());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " you can't set " + ChatColor.AQUA + args.get(0)); sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA
+ args.get(0) + ChatColor.WHITE + " you can't set " + ChatColor.AQUA + args.get(0));
sender.sendMessage(ChatColor.GREEN + "Valid values are:"); sender.sendMessage(ChatColor.GREEN + "Valid values are:");
sender.sendMessage(ConfigProperty.getAllValues()); sender.sendMessage(ConfigProperty.getAllValues());
return; return;

View File

@ -13,6 +13,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Confirms actions.
*/
public class ConfirmCommand extends MultiverseCommand { public class ConfirmCommand extends MultiverseCommand {
public ConfirmCommand(MultiverseCore plugin) { public ConfirmCommand(MultiverseCore plugin) {

View File

@ -21,6 +21,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.List; import java.util.List;
/**
* Returns detailed information on the Players where abouts.
*/
public class CoordCommand extends MultiverseCommand { public class CoordCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;

View File

@ -19,6 +19,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
/**
* Creates a new world and loads it.
*/
public class CreateCommand extends MultiverseCommand { public class CreateCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;
@ -26,7 +29,7 @@ public class CreateCommand extends MultiverseCommand {
super(plugin); super(plugin);
this.setName("Create World"); this.setName("Create World");
this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] [-n]"); this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] [-n]");
this.setArgRange(2, 7); this.setArgRange(2, 7); // SUPPRESS CHECKSTYLE: MagicNumberCheck
this.addKey("mvcreate"); this.addKey("mvcreate");
this.addKey("mvc"); this.addKey("mvc");
this.addKey("mv create"); this.addKey("mv create");

View File

@ -15,6 +15,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Enables debug-information.
*/
public class DebugCommand extends MultiverseCommand { public class DebugCommand extends MultiverseCommand {
public DebugCommand(MultiverseCore plugin) { public DebugCommand(MultiverseCore plugin) {
@ -42,7 +45,8 @@ public class DebugCommand extends MultiverseCommand {
} }
MultiverseCore.GlobalDebug = debugLevel; MultiverseCore.GlobalDebug = debugLevel;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE + " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)"); sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE
+ " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)");
} }
} }

View File

@ -15,6 +15,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Deletes worlds.
*/
public class DeleteCommand extends MultiverseCommand { public class DeleteCommand extends MultiverseCommand {
public DeleteCommand(MultiverseCore plugin) { public DeleteCommand(MultiverseCore plugin) {
@ -30,8 +33,9 @@ public class DeleteCommand extends MultiverseCommand {
@Override @Override
public void runCommand(CommandSender sender, List<String> args) { public void runCommand(CommandSender sender, List<String> args) {
Class<?> paramTypes[] = {String.class}; Class<?>[] paramTypes = {String.class};
List<Object> objectArgs = new ArrayList<Object>(args); List<Object> objectArgs = new ArrayList<Object>(args);
this.plugin.getCommandHandler().queueCommand(sender, "mvdelete", "deleteWorld", objectArgs, paramTypes, ChatColor.GREEN + "World Deleted!", ChatColor.RED + "World could NOT be deleted!"); this.plugin.getCommandHandler().queueCommand(sender, "mvdelete", "deleteWorld", objectArgs,
paramTypes, ChatColor.GREEN + "World Deleted!", ChatColor.RED + "World could NOT be deleted!");
} }
} }

View File

@ -14,6 +14,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Lists valid known environments.
*/
public class EnvironmentCommand extends MultiverseCommand { public class EnvironmentCommand extends MultiverseCommand {
public EnvironmentCommand(MultiverseCore plugin) { public EnvironmentCommand(MultiverseCore plugin) {
@ -29,6 +32,11 @@ public class EnvironmentCommand extends MultiverseCommand {
this.setPermission("multiverse.core.list.environments", "Lists valid known environments.", PermissionDefault.OP); this.setPermission("multiverse.core.list.environments", "Lists valid known environments.", PermissionDefault.OP);
} }
/**
* Shows all valid known environments to a {@link CommandSender}.
*
* @param sender The {@link CommandSender}.
*/
public static void showEnvironments(CommandSender sender) { public static void showEnvironments(CommandSender sender) {
sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:"); sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:");
sender.sendMessage(ChatColor.GREEN + "NORMAL"); sender.sendMessage(ChatColor.GREEN + "NORMAL");

View File

@ -17,6 +17,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Returns a list of loaded generator plugins.
*/
public class GeneratorCommand extends MultiverseCommand { public class GeneratorCommand extends MultiverseCommand {
public GeneratorCommand(MultiverseCore plugin) { public GeneratorCommand(MultiverseCore plugin) {

View File

@ -5,6 +5,7 @@
* with this project. * * with this project. *
******************************************************************************/ ******************************************************************************/
// TODO maybe remove this comment...?
// This file is no longer licensed under that silly CC license. I have blanked it out and will start implementaiton of my own in a few days. For now there is no help. // This file is no longer licensed under that silly CC license. I have blanked it out and will start implementaiton of my own in a few days. For now there is no help.
package com.onarandombox.MultiverseCore.commands; package com.onarandombox.MultiverseCore.commands;
@ -18,6 +19,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Displays a nice help menu.
*/
public class HelpCommand extends PaginatedCoreCommand<Command> { public class HelpCommand extends PaginatedCoreCommand<Command> {
public HelpCommand(MultiverseCore plugin) { public HelpCommand(MultiverseCore plugin) {
@ -33,7 +37,7 @@ public class HelpCommand extends PaginatedCoreCommand<Command> {
this.addKey("mv search"); this.addKey("mv search");
this.addCommandExample("/mv help ?"); this.addCommandExample("/mv help ?");
this.setPermission("multiverse.help", "Displays a nice help menu.", PermissionDefault.TRUE); this.setPermission("multiverse.help", "Displays a nice help menu.", PermissionDefault.TRUE);
this.setItemsPerPage(7); this.setItemsPerPage(7); // SUPPRESS CHECKSTYLE: MagicNumberCheck
} }
@Override @Override
@ -76,7 +80,8 @@ public class HelpCommand extends PaginatedCoreCommand<Command> {
if (filterObject.getFilter().length() > 0) { if (filterObject.getFilter().length() > 0) {
availableCommands = this.getFilteredItems(availableCommands, filterObject.getFilter()); availableCommands = this.getFilteredItems(availableCommands, filterObject.getFilter());
if (availableCommands.size() == 0) { if (availableCommands.size() == 0) {
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No commands matched your filter: " + ChatColor.AQUA + filterObject.getFilter()); sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
+ "No commands matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
return; return;
} }
} }

View File

@ -23,6 +23,9 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
/**
* Imports a new world of the specified type.
*/
public class ImportCommand extends MultiverseCommand { public class ImportCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;
@ -115,7 +118,8 @@ public class ImportCommand extends MultiverseCommand {
// Make sure we don't already know about this world. // Make sure we don't already know about this world.
if (this.worldManager.isMVWorld(worldName)) { if (this.worldManager.isMVWorld(worldName)) {
sender.sendMessage(ChatColor.GREEN + "Multiverse" + ChatColor.WHITE + " already knows about '" + ChatColor.AQUA + worldName + ChatColor.WHITE + "'!"); sender.sendMessage(ChatColor.GREEN + "Multiverse" + ChatColor.WHITE
+ " already knows about '" + ChatColor.AQUA + worldName + ChatColor.WHITE + "'!");
return; return;
} }
@ -139,8 +143,10 @@ public class ImportCommand extends MultiverseCommand {
if (worldFile.exists() && env != null) { if (worldFile.exists() && env != null) {
Command.broadcastCommandMessage(sender, "Starting import of world '" + worldName + "'..."); Command.broadcastCommandMessage(sender, "Starting import of world '" + worldName + "'...");
this.worldManager.addWorld(worldName, environment, null, generator, useSpawnAdjust); if (this.worldManager.addWorld(worldName, environment, null, generator, useSpawnAdjust))
Command.broadcastCommandMessage(sender, "Complete!"); Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!");
else
Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!");
} else if (env == null) { } else if (env == null) {
sender.sendMessage(ChatColor.RED + "FAILED."); sender.sendMessage(ChatColor.RED + "FAILED.");
sender.sendMessage("That world environment did not exist."); sender.sendMessage("That world environment did not exist.");

View File

@ -27,6 +27,9 @@ import java.util.List;
// Will use when we can compile with JDK 6 // Will use when we can compile with JDK 6
//import com.sun.xml.internal.ws.util.StringUtils; //import com.sun.xml.internal.ws.util.StringUtils;
/**
* Returns detailed information about a world.
*/
public class InfoCommand extends MultiverseCommand { public class InfoCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;
@ -106,17 +109,14 @@ public class InfoCommand extends MultiverseCommand {
message.add(new FancyHeader("General Info", colors)); message.add(new FancyHeader("General Info", colors));
message.add(new FancyMessage("World Name: ", world.getName(), colors)); message.add(new FancyMessage("World Name: ", world.getName(), colors));
message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors)); message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors));
String enforced = ""; message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors));
if (!MultiverseCore.EnforceGameModes) {
enforced = ChatColor.RED + " Not Enforced!";
}
message.add(new FancyMessage("Game Mode: ", world.getGameMode() + enforced, colors));
//message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors)); //message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors));
Location spawn = world.getSpawnLocation(); Location spawn = world.getSpawnLocation();
message.add(new FancyMessage("Spawn Location: ", LocationManipulation.strCoords(spawn), colors)); message.add(new FancyMessage("Spawn Location: ", LocationManipulation.strCoords(spawn), colors));
message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors)); message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors));
if (world.getPrice() > 0) { if (world.getPrice() > 0) {
message.add(new FancyMessage("Price to enter this world: ", this.plugin.getBank().getFormattedAmount(p, world.getPrice(), world.getCurrency()), colors)); message.add(new FancyMessage("Price to enter this world: ",
this.plugin.getBank().getFormattedAmount(p, world.getPrice(), world.getCurrency()), colors));
} else { } else {
message.add(new FancyMessage("Price to enter this world: ", ChatColor.GREEN + "FREE!", colors)); message.add(new FancyMessage("Price to enter this world: ", ChatColor.GREEN + "FREE!", colors));
} }
@ -148,13 +148,10 @@ public class InfoCommand extends MultiverseCommand {
message.add(new FancyHeader("Monster Settings", colors)); message.add(new FancyHeader("Monster Settings", colors));
message.add(new FancyMessage("Multiverse Setting: ", world.canMonstersSpawn() + "", colors)); message.add(new FancyMessage("Multiverse Setting: ", world.canMonstersSpawn() + "", colors));
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowMonsters() + "", colors)); message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowMonsters() + "", colors));
if (MultiverseCore.MobsDisabledInDefaultWorld) {
message.add(new FancyMessage(ChatColor.RED + "WARNING: ", "Monsters WILL NOT SPAWN IN THIS WORLD.", colors));
message.add(new FancyMessage(ChatColor.RED + "WARNING: ", "Check your server log for more details.", colors));
}
if (world.getMonsterList().size() > 0) { if (world.getMonsterList().size() > 0) {
if (world.canMonstersSpawn()) { if (world.canMonstersSpawn()) {
message.add(new FancyMessage("Monsters that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getMonsterList()), colors)); message.add(new FancyMessage("Monsters that" + ChatColor.RED + " CAN NOT "
+ ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getMonsterList()), colors));
} else { } else {
message.add(new FancyMessage("Monsters that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getMonsterList()), colors)); message.add(new FancyMessage("Monsters that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getMonsterList()), colors));
} }
@ -170,7 +167,8 @@ public class InfoCommand extends MultiverseCommand {
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowAnimals() + "", colors)); message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowAnimals() + "", colors));
if (world.getMonsterList().size() > 0) { if (world.getMonsterList().size() > 0) {
if (world.canMonstersSpawn()) { if (world.canMonstersSpawn()) {
message.add(new FancyMessage("Animals that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getAnimalList()), colors)); message.add(new FancyMessage("Animals that" + ChatColor.RED + " CAN NOT "
+ ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getAnimalList()), colors));
} else { } else {
message.add(new FancyMessage("Animals that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getAnimalList()), colors)); message.add(new FancyMessage("Animals that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getAnimalList()), colors));
} }
@ -198,6 +196,12 @@ public class InfoCommand extends MultiverseCommand {
return result; return result;
} }
/**
* Gets a "positive" or "negative" {@link ChatColor}.
*
* @param positive Whether this {@link ChatColor} should be "positive".
* @return The {@link ChatColor}.
*/
protected ChatColor getChatColor(boolean positive) { protected ChatColor getChatColor(boolean positive) {
return positive ? ChatColor.GREEN : ChatColor.RED; return positive ? ChatColor.GREEN : ChatColor.RED;
} }

View File

@ -18,6 +18,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Displays a listing of all worlds that a player can enter.
*/
public class ListCommand extends PaginatedCoreCommand<String> { public class ListCommand extends PaginatedCoreCommand<String> {
public ListCommand(MultiverseCore plugin) { public ListCommand(MultiverseCore plugin) {
@ -29,7 +32,7 @@ public class ListCommand extends PaginatedCoreCommand<String> {
this.addKey("mvl"); this.addKey("mvl");
this.addKey("mv list"); this.addKey("mv list");
this.setPermission("multiverse.core.list.worlds", "Displays a listing of all worlds that you can enter.", PermissionDefault.OP); this.setPermission("multiverse.core.list.worlds", "Displays a listing of all worlds that you can enter.", PermissionDefault.OP);
this.setItemsPerPage(8); this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck
} }
private List<String> getFancyWorldList(Player p) { private List<String> getFancyWorldList(Player p) {
@ -99,7 +102,8 @@ public class ListCommand extends PaginatedCoreCommand<String> {
if (filterObject.getFilter().length() > 0) { if (filterObject.getFilter().length() > 0) {
availableWorlds = this.getFilteredItems(availableWorlds, filterObject.getFilter()); availableWorlds = this.getFilteredItems(availableWorlds, filterObject.getFilter());
if (availableWorlds.size() == 0) { if (availableWorlds.size() == 0) {
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No worlds matched your filter: " + ChatColor.AQUA + filterObject.getFilter()); sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
+ "No worlds matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
return; return;
} }
} }

View File

@ -15,6 +15,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Loads a world into Multiverse.
*/
public class LoadCommand extends MultiverseCommand { public class LoadCommand extends MultiverseCommand {
public LoadCommand(MultiverseCore plugin) { public LoadCommand(MultiverseCore plugin) {

View File

@ -21,6 +21,9 @@ import java.util.List;
// This will contain all the properties that support the ADD/REMOVE // This will contain all the properties that support the ADD/REMOVE
// Anything not in here will only support the SET action // Anything not in here will only support the SET action
/**
* Used to modify various aspects of worlds.
*/
public class ModifyAddCommand extends MultiverseCommand { public class ModifyAddCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;
@ -36,7 +39,8 @@ public class ModifyAddCommand extends MultiverseCommand {
this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals"); this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals");
this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters"); this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters");
this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist"); this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist");
this.setPermission("multiverse.core.modify.add", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP); this.setPermission("multiverse.core.modify.add", "Modify various aspects of worlds. See the help wiki for how to use this command properly. "
+ "If you do not include a world, the current world will be used.", PermissionDefault.OP);
this.worldManager = this.plugin.getMVWorldManager(); this.worldManager = this.plugin.getMVWorldManager();
} }
@ -78,7 +82,8 @@ public class ModifyAddCommand extends MultiverseCommand {
} }
if (world.addToVariable(property, value)) { if (world.addToVariable(property, value)) {
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property); sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA
+ value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property);
} else { } else {
sender.sendMessage(value + " could not be added to " + property); sender.sendMessage(value + " could not be added to " + property);
} }

View File

@ -18,6 +18,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Removes all values from a world-property.
*/
public class ModifyClearCommand extends MultiverseCommand { public class ModifyClearCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;
@ -33,7 +36,8 @@ public class ModifyClearCommand extends MultiverseCommand {
this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "animals"); this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "animals");
this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "monsters"); this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "monsters");
this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "worldblacklist"); this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "worldblacklist");
this.setPermission("multiverse.core.modify.clear", "Removes all values from a property. This will work on properties that contain lists.", PermissionDefault.OP); this.setPermission("multiverse.core.modify.clear",
"Removes all values from a property. This will work on properties that contain lists.", PermissionDefault.OP);
this.worldManager = this.plugin.getMVWorldManager(); this.worldManager = this.plugin.getMVWorldManager();
} }
@ -73,9 +77,11 @@ public class ModifyClearCommand extends MultiverseCommand {
} }
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 " + ChatColor.GREEN + "CLEARED" + ChatColor.WHITE + ". It contains " + ChatColor.LIGHT_PURPLE + "0" + ChatColor.WHITE + " values now."); sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was "
+ ChatColor.GREEN + "CLEARED" + ChatColor.WHITE + ". It contains " + ChatColor.LIGHT_PURPLE + "0" + ChatColor.WHITE + " values now.");
} else { } else {
sender.sendMessage(ChatColor.RED + "Error: " + ChatColor.GOLD + property + ChatColor.WHITE + " was " + ChatColor.GOLD + "NOT" + ChatColor.WHITE + " cleared."); sender.sendMessage(ChatColor.RED + "Error: " + ChatColor.GOLD + property
+ ChatColor.WHITE + " was " + ChatColor.GOLD + "NOT" + ChatColor.WHITE + " cleared.");
} }
} }

View File

@ -19,6 +19,9 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* Used to modify various aspects of worlds.
*/
public class ModifyCommand extends MultiverseCommand { public class ModifyCommand extends MultiverseCommand {
public ModifyCommand(MultiverseCore plugin) { public ModifyCommand(MultiverseCore plugin) {
@ -34,7 +37,8 @@ public class ModifyCommand extends MultiverseCommand {
children.put("multiverse.core.modify.modify", true); children.put("multiverse.core.modify.modify", true);
children.put("multiverse.core.modify.clear", true); children.put("multiverse.core.modify.clear", true);
children.put("multiverse.core.modify.remove", true); children.put("multiverse.core.modify.remove", true);
Permission modify = new Permission("multiverse.core.modify", "Modify various aspects of worlds. It requires add/set/clear/remove. See the examples below", PermissionDefault.OP, children); Permission modify = new Permission("multiverse.core.modify",
"Modify various aspects of worlds. It requires add/set/clear/remove. See the examples below", PermissionDefault.OP, children);
this.addCommandExample(ChatColor.AQUA + "/mv modify set ?"); this.addCommandExample(ChatColor.AQUA + "/mv modify set ?");
this.addCommandExample(ChatColor.GREEN + "/mv modify add ?"); this.addCommandExample(ChatColor.GREEN + "/mv modify add ?");
this.addCommandExample(ChatColor.BLUE + "/mv modify clear ?"); this.addCommandExample(ChatColor.BLUE + "/mv modify clear ?");
@ -42,6 +46,13 @@ public class ModifyCommand extends MultiverseCommand {
this.setPermission(modify); this.setPermission(modify);
} }
/**
* Validates the specified action.
*
* @param action The {@link Action}.
* @param property The property.
* @return Whether this action is valid.
*/
protected static boolean validateAction(Action action, String property) { protected static boolean validateAction(Action action, String property) {
if (action != Action.Set) { if (action != Action.Set) {
try { try {

View File

@ -18,6 +18,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Removes values from a world-property.
*/
public class ModifyRemoveCommand extends MultiverseCommand { public class ModifyRemoveCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;
@ -37,7 +40,8 @@ public class ModifyRemoveCommand extends MultiverseCommand {
this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals"); this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals");
this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters"); this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters");
this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist"); this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist");
this.setPermission("multiverse.core.modify.remove", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP); this.setPermission("multiverse.core.modify.remove", "Modify various aspects of worlds. See the help wiki for how to use this command properly. "
+ "If you do not include a world, the current world will be used.", PermissionDefault.OP);
this.worldManager = this.plugin.getMVWorldManager(); this.worldManager = this.plugin.getMVWorldManager();
} }
@ -78,9 +82,11 @@ public class ModifyRemoveCommand extends MultiverseCommand {
return; return;
} }
if (world.removeFromVariable(property, value)) { if (world.removeFromVariable(property, value)) {
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE + " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property); sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE
+ " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property);
} else { } else {
sender.sendMessage(ChatColor.RED + "There was an error removing " + ChatColor.GRAY + value + ChatColor.WHITE + " from " + ChatColor.GOLD + property); sender.sendMessage(ChatColor.RED + "There was an error removing " + ChatColor.GRAY
+ value + ChatColor.WHITE + " from " + ChatColor.GOLD + property);
} }
} }

View File

@ -19,6 +19,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Used to set world-properties.
*/
public class ModifySetCommand extends MultiverseCommand { public class ModifySetCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;
@ -48,7 +51,8 @@ public class ModifySetCommand extends MultiverseCommand {
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "heal " + ChatColor.RED + "true"); this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "heal " + ChatColor.RED + "true");
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "adjustspawn " + ChatColor.RED + "false"); this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "adjustspawn " + ChatColor.RED + "false");
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "spawn"); this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "spawn");
this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP); this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. "
+ "If you do not include a world, the current world will be used.", PermissionDefault.OP);
} }
@Override @Override
@ -105,7 +109,8 @@ public class ModifySetCommand extends MultiverseCommand {
} }
try { try {
if (world.setProperty(property, value, sender)) { if (world.setProperty(property, value, sender)) {
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value); sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
} else { } else {
sender.sendMessage(world.getProperty(property, Object.class).getHelp()); sender.sendMessage(world.getProperty(property, Object.class).getHelp());
} }

View File

@ -8,18 +8,30 @@
package com.onarandombox.MultiverseCore.commands; package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.utils.MVMessaging;
import com.pneumaticraft.commandhandler.Command; import com.pneumaticraft.commandhandler.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.List; import java.util.List;
/**
* A generic Multiverse-command.
*/
public abstract class MultiverseCommand extends Command { public abstract class MultiverseCommand extends Command {
/**
* The reference to the core.
*/
protected MultiverseCore plugin; protected MultiverseCore plugin;
/**
* The reference to {@link MVMessaging}.
*/
protected MVMessaging messaging;
public MultiverseCommand(MultiverseCore plugin) { public MultiverseCommand(MultiverseCore plugin) {
super(plugin); super(plugin);
this.plugin = plugin; this.plugin = plugin;
this.messaging = this.plugin.getMessaging();
} }
@Override @Override

View File

@ -14,28 +14,60 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.util.List; import java.util.List;
/**
* A generic paginated command.
* @param <T> The type of items on the page.
*/
public abstract class PaginatedCommand<T> extends Command { public abstract class PaginatedCommand<T> extends Command {
protected int itemsPerPage = 9; private static final int DEFAULT_ITEMS_PER_PAGE = 9;
/**
* The number of items per page.
*/
protected int itemsPerPage = DEFAULT_ITEMS_PER_PAGE;
public PaginatedCommand(JavaPlugin plugin) { public PaginatedCommand(JavaPlugin plugin) {
super(plugin); super(plugin);
} }
/**
* Set the number of items per page.
*
* @param items The new number of items per page.
*/
protected void setItemsPerPage(int items) { protected void setItemsPerPage(int items) {
itemsPerPage = items; itemsPerPage = items;
} }
/**
* Gets filtered items.
* @param availableItems All available items.
* @param filter The filter-{@link String}.
* @return A list of items that match the filter.
*/
protected abstract List<T> getFilteredItems(List<T> availableItems, String filter); protected abstract List<T> getFilteredItems(List<T> availableItems, String filter);
/**
* Constructs a single string from a list of strings.
*
* @param list The {@link List} of strings.
* @return A single {@link String}.
*/
protected String stitchThisString(List<String> list) { protected String stitchThisString(List<String> list) {
String returnstr = ""; StringBuilder builder = new StringBuilder();
for (String s : list) { for (String s : list) {
returnstr += s + " "; builder.append(s);
builder.append(' ');
} }
return returnstr; return builder.toString();
} }
/**
* Shows a page.
*
* @param page The number of the page to show.
* @param sender The {@link CommandSender} that wants to see the page.
* @param cmds The items that should be displayed on the page.
*/
protected void showPage(int page, CommandSender sender, List<T> cmds) { protected void showPage(int page, CommandSender sender, List<T> cmds) {
// Ensure the page is at least 1. // Ensure the page is at least 1.
page = (page <= 0) ? 1 : page; page = (page <= 0) ? 1 : page;
@ -52,8 +84,20 @@ public abstract class PaginatedCommand<T> extends Command {
} }
} }
/**
* Converts an item into a string.
*
* @param item The item.
* @return A {@link String}.
*/
protected abstract String getItemText(T item); protected abstract String getItemText(T item);
/**
* Constructs a {@link FilterObject} from a {@link List} of arguments.
*
* @param args The {@link List} of arguments.
* @return The {@link FilterObject}.
*/
protected FilterObject getPageAndFilter(List<String> args) { protected FilterObject getPageAndFilter(List<String> args) {
int page = 1; int page = 1;
@ -80,6 +124,9 @@ public abstract class PaginatedCommand<T> extends Command {
return new FilterObject(page, filter); return new FilterObject(page, filter);
} }
/**
* "Key-Object" containing information about the page and the filter that were requested.
*/
protected class FilterObject { protected class FilterObject {
private Integer page; private Integer page;
private String filter; private String filter;
@ -89,14 +136,27 @@ public abstract class PaginatedCommand<T> extends Command {
this.filter = filter; this.filter = filter;
} }
/**
* Gets the page.
* @return The page.
*/
public Integer getPage() { public Integer getPage() {
return this.page; return this.page;
} }
/**
* Sets the page.
*
* @param page The new page.
*/
public void setPage(int page) { public void setPage(int page) {
this.page = page; this.page = page;
} }
/**
* Gets the filter.
* @return The filter.
*/
public String getFilter() { public String getFilter() {
return this.filter; return this.filter;
} }

View File

@ -9,7 +9,14 @@ package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
/**
* A generic paginated Multiverse-command.
* @param <T> The type of items on the page.
*/
public abstract class PaginatedCoreCommand<T> extends PaginatedCommand<T> { public abstract class PaginatedCoreCommand<T> extends PaginatedCommand<T> {
/**
* The reference to the core.
*/
protected MultiverseCore plugin; protected MultiverseCore plugin;
public PaginatedCoreCommand(MultiverseCore plugin) { public PaginatedCoreCommand(MultiverseCore plugin) {

View File

@ -20,6 +20,9 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/**
* Removes a type of mob from a world.
*/
public class PurgeCommand extends MultiverseCommand { public class PurgeCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;

View File

@ -15,6 +15,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Regenerates a world.
*/
public class RegenCommand extends MultiverseCommand { public class RegenCommand extends MultiverseCommand {
public RegenCommand(MultiverseCore plugin) { public RegenCommand(MultiverseCore plugin) {
@ -28,7 +31,8 @@ public class RegenCommand extends MultiverseCommand {
this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s"); this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s");
this.addCommandExample("or specifiy a seed to get that one:"); this.addCommandExample("or specifiy a seed to get that one:");
this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s" + ChatColor.AQUA + " gargamel"); this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s" + ChatColor.AQUA + " gargamel");
this.setPermission("multiverse.core.delete", "Deletes a world on your server. " + ChatColor.RED + "PERMANENTLY.", PermissionDefault.OP); this.setPermission("multiverse.core.regen", "Regenerates a world on your server. The previous state will be lost "
+ ChatColor.RED + "PERMANENTLY.", PermissionDefault.OP);
} }
@Override @Override
@ -37,12 +41,13 @@ public class RegenCommand extends MultiverseCommand {
Boolean randomseed = (args.size() == 2 && args.get(1).equalsIgnoreCase("-s")); Boolean randomseed = (args.size() == 2 && args.get(1).equalsIgnoreCase("-s"));
String seed = (args.size() == 3) ? args.get(2) : ""; String seed = (args.size() == 3) ? args.get(2) : "";
Class<?> paramTypes[] = {String.class, Boolean.class, Boolean.class, String.class}; Class<?>[] paramTypes = {String.class, Boolean.class, Boolean.class, String.class};
List<Object> objectArgs = new ArrayList<Object>(); List<Object> objectArgs = new ArrayList<Object>();
objectArgs.add(args.get(0)); objectArgs.add(args.get(0));
objectArgs.add(useseed); objectArgs.add(useseed);
objectArgs.add(randomseed); objectArgs.add(randomseed);
objectArgs.add(seed); objectArgs.add(seed);
this.plugin.getCommandHandler().queueCommand(sender, "mvregen", "regenWorld", objectArgs, paramTypes, ChatColor.GREEN + "World Regenerated!", ChatColor.RED + "World could NOT be regenerated!"); this.plugin.getCommandHandler().queueCommand(sender, "mvregen", "regenWorld", objectArgs,
paramTypes, ChatColor.GREEN + "World Regenerated!", ChatColor.RED + "World could NOT be regenerated!");
} }
} }

View File

@ -16,6 +16,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Reloads worlds.yml and config.yml.
*/
public class ReloadCommand extends MultiverseCommand { public class ReloadCommand extends MultiverseCommand {
public ReloadCommand(MultiverseCore plugin) { public ReloadCommand(MultiverseCore plugin) {

View File

@ -14,6 +14,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Unloads a world and removes it from the config.
*/
public class RemoveCommand extends MultiverseCommand { public class RemoveCommand extends MultiverseCommand {
public RemoveCommand(MultiverseCore plugin) { public RemoveCommand(MultiverseCore plugin) {
@ -24,7 +27,8 @@ public class RemoveCommand extends MultiverseCommand {
this.addKey("mvremove"); this.addKey("mvremove");
this.addKey("mv remove"); this.addKey("mv remove");
this.addCommandExample("/mv remove " + ChatColor.GREEN + "MyWorld"); this.addCommandExample("/mv remove " + ChatColor.GREEN + "MyWorld");
this.setPermission("multiverse.core.remove", "Unloads a world from Multiverse and removes it from worlds.yml, this does NOT DELETE the world folder.", PermissionDefault.OP); this.setPermission("multiverse.core.remove",
"Unloads a world from Multiverse and removes it from worlds.yml, this does NOT DELETE the world folder.", PermissionDefault.OP);
} }
@Override @Override

View File

@ -20,6 +20,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Sets the spawn for a world.
*/
public class SetSpawnCommand extends MultiverseCommand { public class SetSpawnCommand extends MultiverseCommand {
public SetSpawnCommand(MultiverseCore plugin) { public SetSpawnCommand(MultiverseCore plugin) {
super(plugin); super(plugin);
@ -40,6 +43,11 @@ public class SetSpawnCommand extends MultiverseCommand {
setWorldSpawn(sender); setWorldSpawn(sender);
} }
/**
* Does the actual spawn-setting-work.
*
* @param sender The {@link CommandSender} that's setting the spawn.
*/
protected void setWorldSpawn(CommandSender sender) { protected void setWorldSpawn(CommandSender sender) {
if (sender instanceof Player) { if (sender instanceof Player) {
Player p = (Player) sender; Player p = (Player) sender;

View File

@ -14,6 +14,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Takes the player to the latest bed he's slept in.
*/
public class SleepCommand extends MultiverseCommand { public class SleepCommand extends MultiverseCommand {
public SleepCommand(MultiverseCore plugin) { public SleepCommand(MultiverseCore plugin) {

View File

@ -18,11 +18,15 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Teleports a player to the spawn.
*/
public class SpawnCommand extends MultiverseCommand { public class SpawnCommand extends MultiverseCommand {
public SpawnCommand(MultiverseCore plugin) { public SpawnCommand(MultiverseCore plugin) {
super(plugin); super(plugin);
Permission otherPerm = new Permission("multiverse.core.spawn.other", "Teleports another player to the spawn of the world they are in.", PermissionDefault.OP); Permission otherPerm = new Permission("multiverse.core.spawn.other",
"Teleports another player to the spawn of the world they are in.", PermissionDefault.OP);
this.setName("Spawn"); this.setName("Spawn");
this.setCommandUsage("/mv spawn" + ChatColor.GOLD + " [PLAYER]"); this.setCommandUsage("/mv spawn" + ChatColor.GOLD + " [PLAYER]");
this.setArgRange(0, 1); this.setArgRange(0, 1);

View File

@ -19,6 +19,9 @@ import org.getspout.spoutapi.player.SpoutPlayer;
import java.util.List; import java.util.List;
/**
* Edit a world with spout.
*/
public class SpoutCommand extends MultiverseCommand { public class SpoutCommand extends MultiverseCommand {
public SpoutCommand(MultiverseCore plugin) { public SpoutCommand(MultiverseCore plugin) {
@ -48,10 +51,13 @@ public class SpoutCommand extends MultiverseCommand {
} }
PopupScreen pop = new GenericPopup(); PopupScreen pop = new GenericPopup();
GenericButton button = new GenericButton("Fish"); GenericButton button = new GenericButton("Fish");
// TODO maybe use constants for these
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
button.setX(50); button.setX(50);
button.setY(50); button.setY(50);
button.setWidth(100); button.setWidth(100);
button.setHeight(40); button.setHeight(40);
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
pop.attachWidget(this.plugin, button); pop.attachWidget(this.plugin, button);
sender.sendMessage(ChatColor.GREEN + "YAY!"); sender.sendMessage(ChatColor.GREEN + "YAY!");
p.getMainScreen().attachPopupScreen(pop); p.getMainScreen().attachPopupScreen(pop);

View File

@ -15,7 +15,6 @@ import com.onarandombox.MultiverseCore.destination.WorldDestination;
import com.onarandombox.MultiverseCore.enums.TeleportResult; import com.onarandombox.MultiverseCore.enums.TeleportResult;
import com.onarandombox.MultiverseCore.event.MVTeleportEvent; import com.onarandombox.MultiverseCore.event.MVTeleportEvent;
import com.onarandombox.MultiverseCore.utils.LocationManipulation; import com.onarandombox.MultiverseCore.utils.LocationManipulation;
import com.onarandombox.MultiverseCore.utils.MVMessaging;
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter; import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -29,6 +28,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Used to teleport players.
*/
public class TeleportCommand extends MultiverseCommand { public class TeleportCommand extends MultiverseCommand {
private SafeTTeleporter playerTeleporter; private SafeTTeleporter playerTeleporter;
@ -45,6 +47,8 @@ public class TeleportCommand extends MultiverseCommand {
this.setPermission(menu); this.setPermission(menu);
} }
private static final int UNSAFE_TELEPORT_EXPIRE_DELAY = 15;
@Override @Override
public void runCommand(CommandSender sender, List<String> args) { public void runCommand(CommandSender sender, List<String> args) {
// Check if the command was sent from a Player. // Check if the command was sent from a Player.
@ -59,7 +63,8 @@ public class TeleportCommand extends MultiverseCommand {
if (args.size() == 2) { if (args.size() == 2) {
teleportee = this.plugin.getServer().getPlayer(args.get(0)); teleportee = this.plugin.getServer().getPlayer(args.get(0));
if (teleportee == null) { if (teleportee == null) {
sender.sendMessage("Sorry, I couldn't find player: " + args.get(0)); this.messaging.sendMessage(sender, String.format("Sorry, I couldn't find player: %s%s",
ChatColor.GOLD, args.get(0)), false);
return; return;
} }
destinationName = args.get(1); destinationName = args.get(1);
@ -67,7 +72,7 @@ public class TeleportCommand extends MultiverseCommand {
} else { } else {
destinationName = args.get(0); destinationName = args.get(0);
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage("From the console, you must specify a player to teleport"); this.messaging.sendMessage(sender, String.format("From the console, you must specify a player to teleport"), false);
return; return;
} }
teleportee = (Player) sender; teleportee = (Player) sender;
@ -77,7 +82,9 @@ public class TeleportCommand extends MultiverseCommand {
String[] cannonSpeed = destinationName.split("-"); String[] cannonSpeed = destinationName.split("-");
try { try {
double speed = Double.parseDouble(cannonSpeed[1]); double speed = Double.parseDouble(cannonSpeed[1]);
destinationName = "ca:" + teleportee.getWorld().getName() + ":" + teleportee.getLocation().getX() + "," + teleportee.getLocation().getY() + "," + teleportee.getLocation().getZ() + ":" + teleportee.getLocation().getPitch() + ":" + teleportee.getLocation().getYaw() + ":" + speed; destinationName = "ca:" + teleportee.getWorld().getName() + ":" + teleportee.getLocation().getX()
+ "," + teleportee.getLocation().getY() + "," + teleportee.getLocation().getZ() + ":"
+ teleportee.getLocation().getPitch() + ":" + teleportee.getLocation().getYaw() + ":" + speed;
} catch (Exception e) { } catch (Exception e) {
destinationName = "i:invalid"; destinationName = "i:invalid";
} }
@ -95,7 +102,8 @@ public class TeleportCommand extends MultiverseCommand {
} }
if (d != null && d instanceof InvalidDestination) { if (d != null && d instanceof InvalidDestination) {
sender.sendMessage("Multiverse does not know how to take you to: " + ChatColor.RED + destinationName); this.messaging.sendMessage(sender, String.format("Multiverse does not know how to take you to %s%s",
ChatColor.RED, destinationName), false);
return; return;
} }
@ -107,14 +115,17 @@ public class TeleportCommand extends MultiverseCommand {
if (teleportee.equals(teleporter)) { if (teleportee.equals(teleporter)) {
teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there..."); teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there...");
} else { } else {
teleporter.sendMessage("Doesn't look like you're allowed to send " + ChatColor.GOLD + teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there..."); teleporter.sendMessage("Doesn't look like you're allowed to send " + ChatColor.GOLD
+ teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there...");
} }
return; return;
} else if (teleporter != null && !this.plugin.getMVPerms().canTravelFromLocation(teleporter, d.getLocation(teleportee))) { } else if (teleporter != null && !this.plugin.getMVPerms().canTravelFromLocation(teleporter, d.getLocation(teleportee))) {
if (teleportee.equals(teleporter)) { if (teleportee.equals(teleporter)) {
teleporter.sendMessage("DOH! Doesn't look like you can get to " + ChatColor.RED + "THERE from " + ChatColor.GREEN + ((Player) teleporter).getWorld().getName()); this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like you can get to %s%s %sfrom where you are...",
ChatColor.GREEN, d.toString(), ChatColor.WHITE), false);
} else { } else {
teleporter.sendMessage("DOH! Doesn't look like " + ChatColor.GREEN + ((Player) teleporter).getWorld().getName() + " can get to " + ChatColor.RED + "THERE from where they are..."); this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like %s%s %scan get to %sTHERE from where they are...",
ChatColor.GREEN, ((Player) teleporter).getWorld().getName(), ChatColor.WHITE, ChatColor.RED), false);
} }
return; return;
} }
@ -127,14 +138,19 @@ public class TeleportCommand extends MultiverseCommand {
if (teleportee.getWorld().equals(w)) { if (teleportee.getWorld().equals(w)) {
if (teleporter.equals(teleportee)) { if (teleporter.equals(teleportee)) {
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.self", true)) { if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.self", true)) {
teleporter.sendMessage("Sorry you don't have permission to go to the world spawn!"); this.messaging.sendMessages(teleporter, new String[]{
teleporter.sendMessage(ChatColor.RED + " (multiverse.core.spawn.self)"); String.format("Sorry you don't have permission to go to the world spawn!"),
String.format("%s (multiverse.core.spawn.self)",
ChatColor.RED) }, false);
return; return;
} }
} else { } else {
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.other", true)) { if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.other", true)) {
teleporter.sendMessage("Sorry you don't have permission to send " + teleportee.getDisplayName() + "to the world spawn!"); this.messaging.sendMessages(teleporter, new String[]{
teleporter.sendMessage(ChatColor.RED + " (multiverse.core.spawn.other)"); String.format("Sorry you don't have permission to send %s to the world spawn!",
teleportee.getDisplayName()),
String.format("%s (multiverse.core.spawn.other)",
ChatColor.RED) }, false);
return; return;
} }
} }
@ -142,14 +158,14 @@ public class TeleportCommand extends MultiverseCommand {
} }
if (d.getLocation(teleportee) == null) { if (d.getLocation(teleportee) == null) {
teleporter.sendMessage("Sorry Boss, I tried everything, but just couldn't teleport ya there!"); this.messaging.sendMessage(teleporter, "Sorry Boss, I tried everything, but just couldn't teleport ya there!", false);
return; return;
} }
TeleportResult result = this.playerTeleporter.safelyTeleport(teleporter, teleportee, d); TeleportResult result = this.playerTeleporter.safelyTeleport(teleporter, teleportee, d);
if (result == TeleportResult.FAIL_UNSAFE) { if (result == TeleportResult.FAIL_UNSAFE) {
this.plugin.log(Level.FINE, "Could not teleport " + teleportee.getName() + " to " + LocationManipulation.strCoordsRaw(d.getLocation(teleportee))); this.plugin.log(Level.FINE, "Could not teleport " + teleportee.getName() + " to " + LocationManipulation.strCoordsRaw(d.getLocation(teleportee)));
this.plugin.log(Level.FINE, "Queueing Command"); this.plugin.log(Level.FINE, "Queueing Command");
Class<?> paramTypes[] = {CommandSender.class, Player.class, Location.class}; Class<?>[] paramTypes = { CommandSender.class, Player.class, Location.class };
List<Object> items = new ArrayList<Object>(); List<Object> items = new ArrayList<Object>();
items.add(teleporter); items.add(teleporter);
items.add(teleportee); items.add(teleportee);
@ -158,24 +174,31 @@ public class TeleportCommand extends MultiverseCommand {
if (!teleportee.equals(teleporter)) { if (!teleportee.equals(teleporter)) {
player = teleportee.getName(); player = teleportee.getName();
} }
String message = ChatColor.GREEN + "Multiverse" + ChatColor.WHITE + " did not teleport " + ChatColor.AQUA + player + ChatColor.WHITE + " to " + ChatColor.DARK_AQUA + d.getName() + ChatColor.WHITE + " because it was unsafe."; String message = String.format("%sMultiverse %sdid not teleport %s%s%sto %s%s%sbecause it was unsafe.",
this.plugin.getCommandHandler().queueCommand(sender, "mvteleport", "teleportPlayer", items, paramTypes, message, "Would you like to try anyway?", "", "", 15); ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, player, ChatColor.WHITE, ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE);
} else { this.plugin.getCommandHandler().queueCommand(sender, "mvteleport", "teleportPlayer", items,
// Player was teleported successfully (or the tp event was fired I should say); paramTypes, message, "Would you like to try anyway?", "", "", UNSAFE_TELEPORT_EXPIRE_DELAY);
} }
// else: Player was teleported successfully (or the tp event was fired I should say)
} }
private boolean checkSendPermissions(CommandSender teleporter, Player teleportee, MVDestination destination) { private boolean checkSendPermissions(CommandSender teleporter, Player teleportee, MVDestination destination) {
MVMessaging message = this.plugin.getMessaging();
if (teleporter.equals(teleportee)) { if (teleporter.equals(teleportee)) {
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.self." + destination.getIdentifier(), true)) { if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.self." + destination.getIdentifier(), true)) {
message.sendMessages(teleporter, new String[]{"You don't have permission to teleport yourself to a " + ChatColor.GREEN + destination.getType() + " Destination.", ChatColor.RED + " (multiverse.teleport.self." + destination.getIdentifier() + ")"}); this.messaging.sendMessages(teleporter, new String[]{
String.format("%sYou don't have permission to teleport %syourself %sto a %s%s %sDestination",
ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.RED, destination.getType(), ChatColor.WHITE),
String.format("%s (multiverse.teleport.self.%s)",
ChatColor.RED, destination.getIdentifier()) }, false);
return false; return false;
} }
} else { } else {
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.other." + destination.getIdentifier(), true)) { if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.other." + destination.getIdentifier(), true)) {
message.sendMessages(teleporter, new String[]{"You don't have permission to teleport another player to a " + ChatColor.GREEN + destination.getType() + " Destination.", ChatColor.RED + " (multiverse.teleport.other." + destination.getIdentifier() + ")"}); this.messaging.sendMessages(teleporter, new String[]{
String.format("You don't have permission to teleport another player to a %s%s Destination.",
ChatColor.GREEN, destination.getType()),
String.format("%s(multiverse.teleport.other.%s)",
ChatColor.RED, destination.getIdentifier()) }, false);
return false; return false;
} }
} }

View File

@ -15,6 +15,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
/**
* Unloads worlds from Multiverse.
*/
public class UnloadCommand extends MultiverseCommand { public class UnloadCommand extends MultiverseCommand {
public UnloadCommand(MultiverseCore plugin) { public UnloadCommand(MultiverseCore plugin) {
@ -24,7 +27,8 @@ public class UnloadCommand extends MultiverseCommand {
this.setArgRange(1, 1); this.setArgRange(1, 1);
this.addKey("mvunload"); this.addKey("mvunload");
this.addKey("mv unload"); this.addKey("mv unload");
this.setPermission("multiverse.core.unload", "Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file.", PermissionDefault.OP); this.setPermission("multiverse.core.unload",
"Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file.", PermissionDefault.OP);
} }
@Override @Override

View File

@ -8,7 +8,7 @@
package com.onarandombox.MultiverseCore.commands; package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVVersionRequestEvent; import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException; import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteService; import com.onarandombox.MultiverseCore.utils.webpaste.PasteService;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory; import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory;
@ -21,6 +21,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Dumps version info to the console.
*/
public class VersionCommand extends MultiverseCommand { public class VersionCommand extends MultiverseCommand {
public VersionCommand(MultiverseCore plugin) { public VersionCommand(MultiverseCore plugin) {
@ -31,11 +34,10 @@ public class VersionCommand extends MultiverseCommand {
this.addKey("mv version"); this.addKey("mv version");
this.addKey("mvv"); this.addKey("mvv");
this.addKey("mvversion"); this.addKey("mvversion");
this.setPermission("multiverse.core.version", "Dumps version info to the console, optionally to pastie.org with -p or pastebin.com with a -b.", PermissionDefault.TRUE); this.setPermission("multiverse.core.version",
"Dumps version info to the console, optionally to pastie.org with -p or pastebin.com with a -b.", PermissionDefault.TRUE);
} }
private String pasteBinBuffer = "";
@Override @Override
public void runCommand(CommandSender sender, List<String> args) { public void runCommand(CommandSender sender, List<String> args) {
// Check if the command was sent from a Player. // Check if the command was sent from a Player.
@ -43,33 +45,42 @@ public class VersionCommand extends MultiverseCommand {
sender.sendMessage("Version info dumped to console. Please check your server logs."); sender.sendMessage("Version info dumped to console. Please check your server logs.");
} }
logAndAddToPasteBinBuffer("Multiverse-Core Version: " + this.plugin.getDescription().getVersion()); StringBuilder buffer = new StringBuilder();
logAndAddToPasteBinBuffer("Bukkit Version: " + this.plugin.getServer().getVersion()); buffer.append("[Multiverse-Core] Multiverse-Core Version: ").append(this.plugin.getDescription().getVersion()).append('\n');
logAndAddToPasteBinBuffer("Loaded Worlds: " + this.plugin.getMVWorldManager().getMVWorlds().size()); buffer.append("[Multiverse-Core] Bukkit Version: ").append(this.plugin.getServer().getVersion()).append('\n');
logAndAddToPasteBinBuffer("Multiverse Plugins Loaded: " + this.plugin.getPluginCount()); buffer.append("[Multiverse-Core] Loaded Worlds: ").append(this.plugin.getMVWorldManager().getMVWorlds().size()).append('\n');
logAndAddToPasteBinBuffer("Economy being used: " + this.plugin.getBank().getEconUsed()); buffer.append("[Multiverse-Core] Multiverse Plugins Loaded: ").append(this.plugin.getPluginCount()).append('\n');
logAndAddToPasteBinBuffer("Permissions Plugin: " + this.plugin.getMVPerms().getType()); buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getBank().getEconUsed()).append('\n');
logAndAddToPasteBinBuffer("Dumping Config Values: (version " + this.plugin.getMVConfiguration().getString("version", "NOT SET") + ")"); buffer.append("[Multiverse-Core] Permissions Plugin: ").append(this.plugin.getMVPerms().getType()).append('\n');
logAndAddToPasteBinBuffer("messagecooldown: " + "Not yet IMPLEMENTED"); buffer.append("[Multiverse-Core] Dumping Config Values: (version ")
logAndAddToPasteBinBuffer("teleportcooldown: " + "Not yet IMPLEMENTED"); .append(this.plugin.getMVConfiguration().getDouble("version", -1)).append(")").append('\n');
logAndAddToPasteBinBuffer("worldnameprefix: " + MultiverseCore.PrefixChat); buffer.append("[Multiverse-Core] messagecooldown: ").append(this.plugin.getMessaging().getCooldown()).append('\n');
logAndAddToPasteBinBuffer("enforceaccess: " + MultiverseCore.EnforceAccess); buffer.append("[Multiverse-Core] teleportcooldown: ").append("Not yet IMPLEMENTED").append('\n');
logAndAddToPasteBinBuffer("enforcegamemodes: " + MultiverseCore.EnforceGameModes); buffer.append("[Multiverse-Core] worldnameprefix: ").append(MultiverseCore.PrefixChat).append('\n');
logAndAddToPasteBinBuffer("displaypermerrors: " + MultiverseCore.DisplayPermErrors); buffer.append("[Multiverse-Core] enforceaccess: ").append(MultiverseCore.EnforceAccess).append('\n');
logAndAddToPasteBinBuffer("teleportintercept: " + MultiverseCore.TeleportIntercept); buffer.append("[Multiverse-Core] displaypermerrors: ").append(MultiverseCore.DisplayPermErrors).append('\n');
logAndAddToPasteBinBuffer("debug: " + MultiverseCore.GlobalDebug); buffer.append("[Multiverse-Core] teleportintercept: ").append(MultiverseCore.TeleportIntercept).append('\n');
logAndAddToPasteBinBuffer("Special Code: FRN002"); buffer.append("[Multiverse-Core] firstspawnoverride: ").append(MultiverseCore.FirstSpawnOverride).append('\n');
buffer.append("[Multiverse-Core] firstspawnworld: ").append(this.plugin.getMVConfiguration().getString("firstspawnworld", "NOT SET")).append('\n');
buffer.append("[Multiverse-Core] debug: ").append(MultiverseCore.GlobalDebug).append('\n');
buffer.append("[Multiverse-Core] Special Code: FRN002").append('\n');
MVVersionRequestEvent versionEvent = new MVVersionRequestEvent(pasteBinBuffer); MVVersionEvent versionEvent = new MVVersionEvent(buffer.toString());
this.plugin.getServer().getPluginManager().callEvent(versionEvent); this.plugin.getServer().getPluginManager().callEvent(versionEvent);
pasteBinBuffer = versionEvent.getPasteBinBuffer();
// log to console
String data = versionEvent.getVersionInfo();
String[] lines = data.split("\n");
for (String line : lines) {
this.plugin.log(Level.INFO, line);
}
if (args.size() == 1) { if (args.size() == 1) {
String pasteUrl = ""; String pasteUrl = "";
if (args.get(0).equalsIgnoreCase("-p")) { if (args.get(0).equalsIgnoreCase("-p")) {
pasteUrl = this.postToService(PasteServiceType.PASTIE, true); // private post to pastie pasteUrl = postToService(PasteServiceType.PASTIE, true, data); // private post to pastie
} else if (args.get(0).equalsIgnoreCase("-b")) { } else if (args.get(0).equalsIgnoreCase("-b")) {
pasteUrl = this.postToService(PasteServiceType.PASTEBIN, true); // private post to pastie pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data); // private post to pastie
} else { } else {
return; return;
} }
@ -79,11 +90,6 @@ public class VersionCommand extends MultiverseCommand {
} }
} }
private void logAndAddToPasteBinBuffer(String string) {
this.pasteBinBuffer += "[Multiverse-Core] " + string + "\n";
this.plugin.log(Level.INFO, string);
}
/** /**
* Send the current contents of this.pasteBinBuffer to a web service. * Send the current contents of this.pasteBinBuffer to a web service.
* *
@ -91,10 +97,10 @@ public class VersionCommand extends MultiverseCommand {
* @param isPrivate Should the paste be marked as private. * @param isPrivate Should the paste be marked as private.
* @return URL of visible paste * @return URL of visible paste
*/ */
private String postToService(PasteServiceType type, boolean isPrivate) { private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData) {
PasteService ps = PasteServiceFactory.getService(type, isPrivate); PasteService ps = PasteServiceFactory.getService(type, isPrivate);
try { try {
return ps.postData(ps.encodeData(this.pasteBinBuffer), ps.getPostURL()); return ps.postData(ps.encodeData(pasteData), ps.getPostURL());
} catch (PasteFailedException e) { } catch (PasteFailedException e) {
System.out.print(e); System.out.print(e);
return "Error posting to service"; return "Error posting to service";

View File

@ -18,6 +18,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* States who is in what world.
*/
public class WhoCommand extends MultiverseCommand { public class WhoCommand extends MultiverseCommand {
private MVWorldManager worldManager; private MVWorldManager worldManager;

View File

@ -0,0 +1,4 @@
/**
* This package contains all Commands.
*/
package com.onarandombox.MultiverseCore.commands;

View File

@ -0,0 +1,115 @@
/******************************************************************************
* 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;
}
}

View File

@ -9,12 +9,16 @@ package com.onarandombox.MultiverseCore.configuration;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class BooleanConfigProperty implements MVConfigProperty<Boolean> { /**
* A {@link Boolean} config-property.
*/
public class BooleanConfigProperty implements MVActiveConfigProperty<Boolean> {
private String name; private String name;
private Boolean value; private Boolean value;
private String configNode; private String configNode;
private ConfigurationSection section; private ConfigurationSection section;
private String help; private String help;
private String method;
public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String help) { public BooleanConfigProperty(ConfigurationSection section, String name, Boolean defaultValue, String help) {
this(section, name, defaultValue, name, help); this(section, name, defaultValue, name, help);
@ -29,16 +33,30 @@ public class BooleanConfigProperty implements MVConfigProperty<Boolean> {
this.setValue(this.section.getBoolean(this.configNode, 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 @Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Boolean getValue() { public Boolean getValue() {
return this.value; return this.value;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean setValue(Boolean value) { public boolean setValue(Boolean value) {
if (value == null) { if (value == null) {
@ -49,6 +67,9 @@ public class BooleanConfigProperty implements MVConfigProperty<Boolean> {
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean parseValue(String value) { public boolean parseValue(String value) {
if (value == null) { if (value == null) {
@ -61,18 +82,54 @@ public class BooleanConfigProperty implements MVConfigProperty<Boolean> {
return false; return false;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getConfigNode() { public String getConfigNode() {
return this.configNode; return this.configNode;
} }
/**
* {@inheritDoc}
*/
@Override
public String getHelp() {
return this.help;
}
@Override @Override
public String toString() { public String toString() {
return value.toString(); return value.toString();
} }
/**
* Gets the method that will be executed.
*
* @return The name of the method in MVWorld to be called.
*/
@Override @Override
public String getHelp() { public String getMethod() {
return this.help; 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;
} }
} }

View File

@ -10,6 +10,9 @@ package com.onarandombox.MultiverseCore.configuration;
import com.onarandombox.MultiverseCore.enums.EnglishChatColor; import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
/**
* A {@link EnglishChatColor} config-property.
*/
public class ColorConfigProperty implements MVConfigProperty<EnglishChatColor> { public class ColorConfigProperty implements MVConfigProperty<EnglishChatColor> {
private String name; private String name;
private EnglishChatColor value; private EnglishChatColor value;
@ -30,16 +33,25 @@ public class ColorConfigProperty implements MVConfigProperty<EnglishChatColor> {
this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public EnglishChatColor getValue() { public EnglishChatColor getValue() {
return this.value; return this.value;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean setValue(EnglishChatColor value) { public boolean setValue(EnglishChatColor value) {
if (value == null) { if (value == null) {
@ -50,6 +62,9 @@ public class ColorConfigProperty implements MVConfigProperty<EnglishChatColor> {
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean parseValue(String value) { public boolean parseValue(String value) {
EnglishChatColor color = EnglishChatColor.fromString(value); EnglishChatColor color = EnglishChatColor.fromString(value);
@ -60,18 +75,24 @@ public class ColorConfigProperty implements MVConfigProperty<EnglishChatColor> {
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getConfigNode() { public String getConfigNode() {
return this.configNode; return this.configNode;
} }
/**
* {@inheritDoc}
*/
@Override
public String getHelp() {
return this.help;
}
@Override @Override
public String toString() { public String toString() {
return value.toString(); return value.toString();
} }
@Override
public String getHelp() {
return this.help;
}
} }

View File

@ -1,5 +1,5 @@
/****************************************************************************** /******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. * * Multiverse 2 Copyright (c) the Multiverse Team 2012. *
* Multiverse 2 is licensed under the BSD License. * * Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included * * For more information please check the README.md file included *
* with this project. * * with this project. *
@ -22,74 +22,271 @@ public class ConfigPropertyFactory {
} }
// Booleans // 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) { public BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String help) {
return new BooleanConfigProperty(this.section, name, defaultValue, 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) { public BooleanConfigProperty getNewProperty(String name, boolean defaultValue, String node, String help) {
return new BooleanConfigProperty(this.section, name, defaultValue, node, 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 // 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) { public IntegerConfigProperty getNewProperty(String name, int defaultValue, String help) {
return new IntegerConfigProperty(this.section, name, defaultValue, 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) { public IntegerConfigProperty getNewProperty(String name, int defaultValue, String node, String help) {
return new IntegerConfigProperty(this.section, name, defaultValue, node, help); return new IntegerConfigProperty(this.section, name, defaultValue, node, help);
} }
// Doubles // 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) { public DoubleConfigProperty getNewProperty(String name, double defaultValue, String help) {
return new DoubleConfigProperty(this.section, name, defaultValue, 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) { public DoubleConfigProperty getNewProperty(String name, double defaultValue, String node, String help) {
return new DoubleConfigProperty(this.section, name, defaultValue, node, 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 // 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) { public StringConfigProperty getNewProperty(String name, String defaultValue, String help) {
return new StringConfigProperty(this.section, name, defaultValue, 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) { public StringConfigProperty getNewProperty(String name, String defaultValue, String node, String help) {
return new StringConfigProperty(this.section, name, defaultValue, node, help); return new StringConfigProperty(this.section, name, defaultValue, node, help);
} }
// Colors // 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) { public ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue, String help) {
return new ColorConfigProperty(this.section, name, defaultValue, 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) { public ColorConfigProperty getNewProperty(String name, EnglishChatColor defaultValue, String node, String help) {
return new ColorConfigProperty(this.section, name, defaultValue, node, help); return new ColorConfigProperty(this.section, name, defaultValue, node, help);
} }
// Difficulty // 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) { public DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue, String help) {
return new DifficultyConfigProperty(this.section, name, defaultValue, 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) { public DifficultyConfigProperty getNewProperty(String name, Difficulty defaultValue, String node, String help) {
return new DifficultyConfigProperty(this.section, name, defaultValue, node, help); return new DifficultyConfigProperty(this.section, name, defaultValue, node, help);
} }
// GameMode // 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) { public GameModeConfigProperty getNewProperty(String name, GameMode defaultValue, String help) {
return new GameModeConfigProperty(this.section, name, defaultValue, 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) { public GameModeConfigProperty getNewProperty(String name, GameMode defaultValue, String node, String help) {
return new GameModeConfigProperty(this.section, name, defaultValue, node, help); return new GameModeConfigProperty(this.section, name, defaultValue, node, help);
} }
// GameMode // 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 LocationConfigProperty getNewProperty(String name, Location defaultValue, String help) { public LocationConfigProperty getNewProperty(String name, Location defaultValue, String help) {
return new LocationConfigProperty(this.section, name, defaultValue, 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) { public LocationConfigProperty getNewProperty(String name, Location defaultValue, String node, String help) {
return new LocationConfigProperty(this.section, name, defaultValue, node, 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);
}
/**
* 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);
}
} }

View File

@ -10,7 +10,10 @@ package com.onarandombox.MultiverseCore.configuration;
import org.bukkit.Difficulty; import org.bukkit.Difficulty;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class DifficultyConfigProperty implements MVConfigProperty<Difficulty> { /**
* A {@link Difficulty} config-property.
*/
public class DifficultyConfigProperty implements MVActiveConfigProperty<Difficulty> {
private String name; private String name;
private Difficulty value; private Difficulty value;
private String configNode; private String configNode;
@ -30,16 +33,25 @@ public class DifficultyConfigProperty implements MVConfigProperty<Difficulty> {
this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Difficulty getValue() { public Difficulty getValue() {
return this.value; return this.value;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean setValue(Difficulty value) { public boolean setValue(Difficulty value) {
if (value == null) { if (value == null) {
@ -50,6 +62,9 @@ public class DifficultyConfigProperty implements MVConfigProperty<Difficulty> {
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean parseValue(String value) { public boolean parseValue(String value) {
try { try {
@ -63,18 +78,52 @@ public class DifficultyConfigProperty implements MVConfigProperty<Difficulty> {
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getConfigNode() { public String getConfigNode() {
return this.configNode; return this.configNode;
} }
/**
* {@inheritDoc}
*/
@Override
public String getHelp() {
return this.help;
}
@Override @Override
public String toString() { public String toString() {
return value.toString(); return value.toString();
} }
/**
* Gets the method that will be executed.
*
* @return The name of the method in MVWorld to be called.
*/
@Override @Override
public String getHelp() { public String getMethod() {
return this.help; return "setDifficulty";
}
/**
* 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;
} }
} }

View File

@ -9,12 +9,16 @@ package com.onarandombox.MultiverseCore.configuration;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class DoubleConfigProperty implements MVConfigProperty<Double> { /**
* A {@link Double} config-property.
*/
public class DoubleConfigProperty implements MVActiveConfigProperty<Double> {
private String name; private String name;
private Double value; private Double value;
private String configNode; private String configNode;
private ConfigurationSection section; private ConfigurationSection section;
private String help; private String help;
private String method;
public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String help) { public DoubleConfigProperty(ConfigurationSection section, String name, Double defaultValue, String help) {
this(section, name, defaultValue, name, help); this(section, name, defaultValue, name, help);
@ -29,16 +33,30 @@ public class DoubleConfigProperty implements MVConfigProperty<Double> {
this.setValue(this.section.getDouble(this.configNode, 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 @Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Double getValue() { public Double getValue() {
return this.value; return this.value;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean setValue(Double value) { public boolean setValue(Double value) {
if (value == null) { if (value == null) {
@ -49,6 +67,9 @@ public class DoubleConfigProperty implements MVConfigProperty<Double> {
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean parseValue(String value) { public boolean parseValue(String value) {
try { try {
@ -59,18 +80,54 @@ public class DoubleConfigProperty implements MVConfigProperty<Double> {
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getConfigNode() { public String getConfigNode() {
return this.configNode; return this.configNode;
} }
/**
* {@inheritDoc}
*/
@Override
public String getHelp() {
return this.help;
}
@Override @Override
public String toString() { public String toString() {
return value.toString(); return value.toString();
} }
/**
* Gets the method that will be executed.
*
* @return The name of the method in MVWorld to be called.
*/
@Override @Override
public String getHelp() { public String getMethod() {
return this.help; 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;
} }
} }

View File

@ -10,7 +10,10 @@ package com.onarandombox.MultiverseCore.configuration;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class GameModeConfigProperty implements MVConfigProperty<GameMode> { /**
* A {@link GameMode} config-property.
*/
public class GameModeConfigProperty implements MVActiveConfigProperty<GameMode> {
private String name; private String name;
private GameMode value; private GameMode value;
private String configNode; private String configNode;
@ -30,16 +33,25 @@ public class GameModeConfigProperty implements MVConfigProperty<GameMode> {
this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); this.parseValue(this.section.getString(this.configNode, defaultValue.toString()));
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public GameMode getValue() { public GameMode getValue() {
return this.value; return this.value;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean setValue(GameMode value) { public boolean setValue(GameMode value) {
if (value == null) { if (value == null) {
@ -50,6 +62,9 @@ public class GameModeConfigProperty implements MVConfigProperty<GameMode> {
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean parseValue(String value) { public boolean parseValue(String value) {
try { try {
@ -63,18 +78,52 @@ public class GameModeConfigProperty implements MVConfigProperty<GameMode> {
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getConfigNode() { public String getConfigNode() {
return this.configNode; return this.configNode;
} }
/**
* {@inheritDoc}
*/
@Override
public String getHelp() {
return this.help;
}
@Override @Override
public String toString() { public String toString() {
return value.toString(); return value.toString();
} }
/**
* Gets the method that will be executed.
*
* @return The name of the method in MVWorld to be called.
*/
@Override @Override
public String getHelp() { public String getMethod() {
return this.help; 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;
} }
} }

View File

@ -9,6 +9,9 @@ package com.onarandombox.MultiverseCore.configuration;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
/**
* A {@link Integer} config-property.
*/
public class IntegerConfigProperty implements MVConfigProperty<Integer> { public class IntegerConfigProperty implements MVConfigProperty<Integer> {
private String name; private String name;
private Integer value; private Integer value;
@ -29,16 +32,25 @@ public class IntegerConfigProperty implements MVConfigProperty<Integer> {
this.setValue(this.section.getInt(this.configNode, defaultValue)); this.setValue(this.section.getInt(this.configNode, defaultValue));
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Integer getValue() { public Integer getValue() {
return this.value; return this.value;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean setValue(Integer value) { public boolean setValue(Integer value) {
if (value == null) { if (value == null) {
@ -49,6 +61,9 @@ public class IntegerConfigProperty implements MVConfigProperty<Integer> {
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean parseValue(String value) { public boolean parseValue(String value) {
try { try {
@ -59,18 +74,24 @@ public class IntegerConfigProperty implements MVConfigProperty<Integer> {
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getConfigNode() { public String getConfigNode() {
return this.configNode; return this.configNode;
} }
/**
* {@inheritDoc}
*/
@Override
public String getHelp() {
return this.help;
}
@Override @Override
public String toString() { public String toString() {
return value.toString(); return value.toString();
} }
@Override
public String getHelp() {
return this.help;
}
} }

View File

@ -11,12 +11,16 @@ import com.onarandombox.MultiverseCore.utils.LocationManipulation;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class LocationConfigProperty implements MVConfigProperty<Location> { /**
* A {@link Location} config-property.
*/
public class LocationConfigProperty implements MVActiveConfigProperty<Location> {
private String name; private String name;
private Location value; private Location value;
private String configNode; private String configNode;
private ConfigurationSection section; private ConfigurationSection section;
private String help; private String help;
private String method;
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String help) { public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String help) {
this(section, name, defaultValue, name, help); this(section, name, defaultValue, name, help);
@ -31,37 +35,55 @@ public class LocationConfigProperty implements MVConfigProperty<Location> {
this.setValue(this.getLocationFromConfig(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 @Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Location getValue() { public Location getValue() {
return this.value; return this.value;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean parseValue(String value) { public boolean parseValue(String value) {
Location parsed = LocationManipulation.stringToLocation(value); Location parsed = LocationManipulation.stringToLocation(value);
return this.setValue(parsed); return this.setValue(parsed);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getConfigNode() { public String getConfigNode() {
return this.configNode; return this.configNode;
} }
@Override /**
public String toString() { * {@inheritDoc}
return LocationManipulation.strCoordsRaw(this.value); */
}
@Override @Override
public String getHelp() { public String getHelp() {
return this.help; return this.help;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean setValue(Location value) { public boolean setValue(Location value) {
if (value == null) { if (value == null) {
@ -91,4 +113,39 @@ public class LocationConfigProperty implements MVConfigProperty<Location> {
} }
return defaultValue; return defaultValue;
} }
@Override
public String toString() {
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;
}
} }

View File

@ -0,0 +1,35 @@
/******************************************************************************
* 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;
/**
* An "active" {@link MVConfigProperty} that uses the specified method to be "actually" set.
* @param <T> The type of the config-property.
* @see MVConfigProperty
*/
public interface MVActiveConfigProperty<T> extends MVConfigProperty<T> {
/**
* Gets the method that will be executed.
*
* @return The name of the method in MVWorld to be called.
*/
String getMethod();
/**
* Sets the method that will be executed.
*
* @param methodName The name of the method in MVWorld to be called.
*/
void setMethod(String methodName);
/**
* Returns the class of the object we're looking at.
* @return the class of the object we're looking at.
*/
Class<?> getPropertyClass();
}

View File

@ -17,8 +17,17 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@SuppressWarnings("deprecation") /*
* This is a mess, so I'm just going to suppress all warnings here.
* BEGIN CHECKSTYLE-SUPPRESSION: ALL
*/
/**
* @deprecated This isn't used any more, is it?
*/
@Deprecated
public abstract class MVConfigMigrator { public abstract class MVConfigMigrator {
public List<String> createdDefaults = new ArrayList<String>(); public List<String> createdDefaults = new ArrayList<String>();
public abstract boolean migrate(String name, File folder); public abstract boolean migrate(String name, File folder);
@ -60,3 +69,7 @@ public abstract class MVConfigMigrator {
return oldFolder; return oldFolder;
} }
} }
/*
* END CHECKSTYLE-SUPPRESSION: ALL
*/

View File

@ -7,6 +7,11 @@
package com.onarandombox.MultiverseCore.configuration; package com.onarandombox.MultiverseCore.configuration;
/**
* A generic config-property.
*
* @param <T> The type of the config-property.
*/
public interface MVConfigProperty<T> { public interface MVConfigProperty<T> {
/** /**
* Gets the name of this property. * Gets the name of this property.
@ -40,6 +45,7 @@ public interface MVConfigProperty<T> {
* Sets the value of this property. * Sets the value of this property.
* *
* @param value The T representation of this value. * @param value The T representation of this value.
* @return True the value was successfully set.
*/ */
boolean setValue(T value); boolean setValue(T value);
@ -52,5 +58,10 @@ public interface MVConfigProperty<T> {
*/ */
boolean parseValue(String value); boolean parseValue(String value);
/**
* Gets the name of the config-node that this {@link MVConfigProperty} is saved as.
*
* @return The name of the config-node that this {@link MVConfigProperty} is saved as.
*/
String getConfigNode(); String getConfigNode();
} }

View File

@ -9,6 +9,9 @@ package com.onarandombox.MultiverseCore.configuration;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
/**
* A {@link String} config-property.
*/
public class StringConfigProperty implements MVConfigProperty<String> { public class StringConfigProperty implements MVConfigProperty<String> {
private String name; private String name;
private String value; private String value;
@ -29,16 +32,25 @@ public class StringConfigProperty implements MVConfigProperty<String> {
this.parseValue(this.section.getString(this.configNode, defaultValue)); this.parseValue(this.section.getString(this.configNode, defaultValue));
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getValue() { public String getValue() {
return this.value; return this.value;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean parseValue(String value) { public boolean parseValue(String value) {
if (value == null) { if (value == null) {
@ -48,21 +60,25 @@ public class StringConfigProperty implements MVConfigProperty<String> {
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getConfigNode() { public String getConfigNode() {
return this.configNode; return this.configNode;
} }
@Override /**
public String toString() { * {@inheritDoc}
return value; */
}
@Override @Override
public String getHelp() { public String getHelp() {
return this.help; return this.help;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean setValue(String value) { public boolean setValue(String value) {
if (value == null) { if (value == null) {
@ -72,4 +88,9 @@ public class StringConfigProperty implements MVConfigProperty<String> {
this.section.set(configNode, this.value); this.section.set(configNode, this.value);
return true; return true;
} }
@Override
public String toString() {
return value;
}
} }

View File

@ -0,0 +1,4 @@
/**
* This package contains the Multiverse-configuration.
*/
package com.onarandombox.MultiverseCore.configuration;

View File

@ -17,21 +17,34 @@ import org.bukkit.util.Vector;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/**
* An anchor-{@link MVDestination}.
*/
public class AnchorDestination implements MVDestination { public class AnchorDestination implements MVDestination {
private boolean isValid; private boolean isValid;
private Location location; private Location location;
private MultiverseCore plugin; private MultiverseCore plugin;
private String name; private String name;
/**
* {@inheritDoc}
*/
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return "a"; return "a";
} }
/**
* {@inheritDoc}
*/
@Override
public Vector getVelocity() { public Vector getVelocity() {
return new Vector(0, 0, 0); return new Vector(0, 0, 0);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isThisType(JavaPlugin plugin, String destination) { public boolean isThisType(JavaPlugin plugin, String destination) {
if (!(plugin instanceof MultiverseCore)) { if (!(plugin instanceof MultiverseCore)) {
@ -47,16 +60,25 @@ public class AnchorDestination implements MVDestination {
return parsed.get(0).equalsIgnoreCase("a"); return parsed.get(0).equalsIgnoreCase("a");
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Location getLocation(Entity e) { public Location getLocation(Entity e) {
return this.location; return this.location;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isValid() { public boolean isValid() {
return this.isValid; return this.isValid;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDestination(JavaPlugin plugin, String destination) { public void setDestination(JavaPlugin plugin, String destination) {
if (!(plugin instanceof MultiverseCore)) { if (!(plugin instanceof MultiverseCore)) {
@ -83,11 +105,17 @@ public class AnchorDestination implements MVDestination {
this.isValid = true; this.isValid = true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getType() { public String getType() {
return "Anchor"; return "Anchor";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return "Anchor: " + this.name; return "Anchor: " + this.name;
@ -101,11 +129,17 @@ public class AnchorDestination implements MVDestination {
return "i:Invalid Destination"; return "i:Invalid Destination";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getRequiredPermission() { public String getRequiredPermission() {
return "multiverse.access." + this.location.getWorld().getName(); return "multiverse.access." + this.location.getWorld().getName();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean useSafeTeleporter() { public boolean useSafeTeleporter() {
// This is an ANCHOR destination, don't safely teleport here. // This is an ANCHOR destination, don't safely teleport here.

View File

@ -14,16 +14,25 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
/**
* A bed-{@link MVDestination}.
*/
public class BedDestination implements MVDestination { public class BedDestination implements MVDestination {
private boolean isValid; private boolean isValid;
private Location knownBedLoc; private Location knownBedLoc;
/**
* {@inheritDoc}
*/
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return "b"; return "b";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isThisType(JavaPlugin plugin, String destination) { public boolean isThisType(JavaPlugin plugin, String destination) {
String[] split = destination.split(":"); String[] split = destination.split(":");
@ -31,6 +40,9 @@ public class BedDestination implements MVDestination {
return this.isValid; return this.isValid;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Location getLocation(Entity entity) { public Location getLocation(Entity entity) {
if (entity instanceof Player) { if (entity instanceof Player) {
@ -40,31 +52,49 @@ public class BedDestination implements MVDestination {
return null; return null;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Vector getVelocity() { public Vector getVelocity() {
return new Vector(); return new Vector();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDestination(JavaPlugin plugin, String destination) { public void setDestination(JavaPlugin plugin, String destination) {
// Not needed. // Not needed.
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isValid() { public boolean isValid() {
return this.isValid; return this.isValid;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getType() { public String getType() {
return "Bed"; return "Bed";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return "Bed"; return "Bed";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getRequiredPermission() { public String getRequiredPermission() {
if (knownBedLoc != null) { if (knownBedLoc != null) {
@ -73,6 +103,9 @@ public class BedDestination implements MVDestination {
return ""; return "";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean useSafeTeleporter() { public boolean useSafeTeleporter() {
// Bukkit should have already checked this. // Bukkit should have already checked this.

View File

@ -17,12 +17,19 @@ import org.bukkit.util.Vector;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/**
* A cannon-{@link MVDestination}.
*/
public class CannonDestination implements MVDestination { public class CannonDestination implements MVDestination {
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)"; private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
private boolean isValid; private boolean isValid;
private Location location; private Location location;
private double speed; private double speed;
/**
* {@inheritDoc}
*/
@Override
public Vector getVelocity() { public Vector getVelocity() {
double pitchRadians = Math.toRadians(location.getPitch()); double pitchRadians = Math.toRadians(location.getPitch());
double yawRadians = Math.toRadians(location.getYaw()); double yawRadians = Math.toRadians(location.getYaw());
@ -35,20 +42,28 @@ public class CannonDestination implements MVDestination {
return new Vector(x, y, z); return new Vector(x, y, z);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return "ca"; return "ca";
} }
// NEED ca:world:x,y,z:pitch:yaw:speed
// so basically 6
private static final int SPLIT_SIZE = 6;
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isThisType(JavaPlugin plugin, String destination) { public boolean isThisType(JavaPlugin plugin, String destination) {
if (!(plugin instanceof MultiverseCore)) { if (!(plugin instanceof MultiverseCore)) {
return false; return false;
} }
List<String> parsed = Arrays.asList(destination.split(":")); List<String> parsed = Arrays.asList(destination.split(":"));
// NEED ca:world:x,y,z:pitch:yaw:speed if (parsed.size() != SPLIT_SIZE) {
// so basically 6
if (parsed.size() != 6) {
return false; return false;
} }
// If it's not an Cannon type // If it's not an Cannon type
@ -66,35 +81,44 @@ public class CannonDestination implements MVDestination {
} }
try { try {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
Float.parseFloat(parsed.get(3)); Float.parseFloat(parsed.get(3));
Float.parseFloat(parsed.get(4)); Float.parseFloat(parsed.get(4));
Float.parseFloat(parsed.get(5)); Float.parseFloat(parsed.get(5));
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return false; return false;
} }
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Location getLocation(Entity e) { public Location getLocation(Entity e) {
return this.location; return this.location;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isValid() { public boolean isValid() {
return this.isValid; return this.isValid;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDestination(JavaPlugin plugin, String destination) { public void setDestination(JavaPlugin plugin, String destination) {
if (!(plugin instanceof MultiverseCore)) { if (!(plugin instanceof MultiverseCore)) {
return; return;
} }
List<String> parsed = Arrays.asList(destination.split(":")); List<String> parsed = Arrays.asList(destination.split(":"));
// Need at least: e:world:x,y,z
// OR e:world:x,y,z:pitch:yaw if (parsed.size() != SPLIT_SIZE) {
// so basically 3 or 5
if (parsed.size() != 6) {
this.isValid = false; this.isValid = false;
return; return;
} }
@ -129,9 +153,11 @@ public class CannonDestination implements MVDestination {
this.location.setZ(coords[2]); this.location.setZ(coords[2]);
try { try {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
this.location.setPitch(Float.parseFloat(parsed.get(3))); this.location.setPitch(Float.parseFloat(parsed.get(3)));
this.location.setYaw(Float.parseFloat(parsed.get(4))); this.location.setYaw(Float.parseFloat(parsed.get(4)));
this.speed = Math.abs(Float.parseFloat(parsed.get(5))); this.speed = Math.abs(Float.parseFloat(parsed.get(5)));
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
this.isValid = false; this.isValid = false;
return; return;
@ -141,18 +167,30 @@ public class CannonDestination implements MVDestination {
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getType() { public String getType() {
return "Cannon!"; return "Cannon!";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return "Cannon (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":" + return "Cannon (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":"
this.location.getPitch() + ":" + this.location.getYaw() + ":" + this.speed + ")"; + this.location.getPitch() + ":" + this.location.getYaw() + ":" + this.speed + ")";
} }
/**
* Sets this {@link CannonDestination}.
*
* @param location The {@link Location}.
* @param speed The speed.
*/
public void setDestination(Location location, double speed) { public void setDestination(Location location, double speed) {
if (location != null) { if (location != null) {
this.location = location; this.location = location;
@ -162,21 +200,28 @@ public class CannonDestination implements MVDestination {
this.isValid = false; this.isValid = false;
} }
@Override /**
public String toString() { * {@inheritDoc}
if (isValid) { */
return "ca:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed;
}
return "i:Invalid Destination";
}
@Override @Override
public String getRequiredPermission() { public String getRequiredPermission() {
return "multiverse.access." + this.location.getWorld().getName(); return "multiverse.access." + this.location.getWorld().getName();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean useSafeTeleporter() { public boolean useSafeTeleporter() {
return false; return false;
} }
@Override
public String toString() {
if (isValid) {
return "ca:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY()
+ "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed;
}
return "i:Invalid Destination";
}
} }

View File

@ -66,6 +66,13 @@ public class DestinationFactory {
return new InvalidDestination(); return new InvalidDestination();
} }
/**
* Registers a {@link MVDestination}.
*
* @param c The {@link Class} of the {@link MVDestination} to register.
* @param identifier The {@link String}-identifier.
* @return True if the class was successfully registered.
*/
public boolean registerDestinationType(Class<? extends MVDestination> c, String identifier) { public boolean registerDestinationType(Class<? extends MVDestination> c, String identifier) {
if (this.destList.containsKey(identifier)) { if (this.destList.containsKey(identifier)) {
return false; return false;
@ -79,12 +86,14 @@ public class DestinationFactory {
Permission other = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.other." + identifier); Permission other = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.other." + identifier);
PermissionTools pt = new PermissionTools(this.plugin); PermissionTools pt = new PermissionTools(this.plugin);
if (self == null) { if (self == null) {
self = new Permission("multiverse.teleport.self." + identifier, "Permission to teleport yourself for the " + identifier + " destination.", PermissionDefault.OP); self = new Permission("multiverse.teleport.self." + identifier,
"Permission to teleport yourself for the " + identifier + " destination.", PermissionDefault.OP);
this.plugin.getServer().getPluginManager().addPermission(self); this.plugin.getServer().getPluginManager().addPermission(self);
pt.addToParentPerms("multiverse.teleport.self." + identifier); pt.addToParentPerms("multiverse.teleport.self." + identifier);
} }
if (other == null) { if (other == null) {
other = new Permission("multiverse.teleport.other." + identifier, "Permission to teleport others for the " + identifier + " destination.", PermissionDefault.OP); other = new Permission("multiverse.teleport.other." + identifier,
"Permission to teleport others for the " + identifier + " destination.", PermissionDefault.OP);
this.plugin.getServer().getPluginManager().addPermission(other); this.plugin.getServer().getPluginManager().addPermission(other);
pt.addToParentPerms("multiverse.teleport.other." + identifier); pt.addToParentPerms("multiverse.teleport.other." + identifier);
} }

View File

@ -17,20 +17,33 @@ import org.bukkit.util.Vector;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/**
* An exact {@link MVDestination}.
*/
public class ExactDestination implements MVDestination { public class ExactDestination implements MVDestination {
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)"; private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
private boolean isValid; private boolean isValid;
private Location location; private Location location;
/**
* {@inheritDoc}
*/
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return "e"; return "e";
} }
/**
* {@inheritDoc}
*/
@Override
public Vector getVelocity() { public Vector getVelocity() {
return new Vector(0, 0, 0); return new Vector(0, 0, 0);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isThisType(JavaPlugin plugin, String destination) { public boolean isThisType(JavaPlugin plugin, String destination) {
if (!(plugin instanceof MultiverseCore)) { if (!(plugin instanceof MultiverseCore)) {
@ -40,7 +53,7 @@ public class ExactDestination implements MVDestination {
// Need at least: e:world:x,y,z // Need at least: e:world:x,y,z
// OR e:world:x,y,z:pitch:yaw // OR e:world:x,y,z:pitch:yaw
// so basically 3 or 5 // so basically 3 or 5
if (!(parsed.size() == 3 || parsed.size() == 5)) { if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
return false; return false;
} }
// If it's not an Exact type // If it's not an Exact type
@ -63,23 +76,32 @@ public class ExactDestination implements MVDestination {
try { try {
Float.parseFloat(parsed.get(3)); Float.parseFloat(parsed.get(3));
Float.parseFloat(parsed.get(4)); Float.parseFloat(parsed.get(4)); // SUPPRESS CHECKSTYLE: MagicNumberCheck
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return false; return false;
} }
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Location getLocation(Entity e) { public Location getLocation(Entity e) {
return this.location; return this.location;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isValid() { public boolean isValid() {
return this.isValid; return this.isValid;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDestination(JavaPlugin plugin, String destination) { public void setDestination(JavaPlugin plugin, String destination) {
if (!(plugin instanceof MultiverseCore)) { if (!(plugin instanceof MultiverseCore)) {
@ -89,7 +111,7 @@ public class ExactDestination implements MVDestination {
// Need at least: e:world:x,y,z // Need at least: e:world:x,y,z
// OR e:world:x,y,z:pitch:yaw // OR e:world:x,y,z:pitch:yaw
// so basically 3 or 5 // so basically 3 or 5
if (!(parsed.size() == 3 || parsed.size() == 5)) { if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
this.isValid = false; this.isValid = false;
return; return;
} }
@ -130,7 +152,7 @@ public class ExactDestination implements MVDestination {
try { try {
this.location.setPitch(Float.parseFloat(parsed.get(3))); this.location.setPitch(Float.parseFloat(parsed.get(3)));
this.location.setYaw(Float.parseFloat(parsed.get(4))); this.location.setYaw(Float.parseFloat(parsed.get(4))); // SUPPRESS CHECKSTYLE: MagicNumberCheck
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
this.isValid = false; this.isValid = false;
return; return;
@ -139,16 +161,28 @@ public class ExactDestination implements MVDestination {
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getType() { public String getType() {
return "Exact"; return "Exact";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return "Exact (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ")"; return "Exact (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ()
+ ":" + location.getPitch() + ":" + location.getYaw() + ")";
} }
/**
* Sets this {@link ExactDestination}.
*
* @param location The {@link Location}.
*/
public void setDestination(Location location) { public void setDestination(Location location) {
if (location != null) { if (location != null) {
this.location = location; this.location = location;
@ -157,19 +191,29 @@ public class ExactDestination implements MVDestination {
this.isValid = false; this.isValid = false;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String toString() { public String toString() {
if (isValid) { if (isValid) {
return "e:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw(); return "e:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY()
+ "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw();
} }
return "i:Invalid Destination"; return "i:Invalid Destination";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getRequiredPermission() { public String getRequiredPermission() {
return "multiverse.access." + this.location.getWorld().getName(); return "multiverse.access." + this.location.getWorld().getName();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean useSafeTeleporter() { public boolean useSafeTeleporter() {
// This is an EXACT destination, don't safely teleport here. // This is an EXACT destination, don't safely teleport here.

View File

@ -14,38 +14,62 @@ import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
/**
* An invalid {@link MVDestination}.
*/
public class InvalidDestination implements MVDestination { public class InvalidDestination implements MVDestination {
/**
* {@inheritDoc}
*/
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return "i"; return "i";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isThisType(JavaPlugin plugin, String destination) { public boolean isThisType(JavaPlugin plugin, String destination) {
return false; return false;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Location getLocation(Entity e) { public Location getLocation(Entity e) {
return null; return null;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isValid() { public boolean isValid() {
return false; return false;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDestination(JavaPlugin plugin, String destination) { public void setDestination(JavaPlugin plugin, String destination) {
// Nothing needed, it's invalid. // Nothing needed, it's invalid.
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getType() { public String getType() {
return ChatColor.RED + "Invalid Destination"; return ChatColor.RED + "Invalid Destination";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return ChatColor.RED + "Invalid Destination"; return ChatColor.RED + "Invalid Destination";
@ -56,15 +80,25 @@ public class InvalidDestination implements MVDestination {
return "i:Invalid Destination"; return "i:Invalid Destination";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getRequiredPermission() { public String getRequiredPermission() {
return null; return null;
} }
/**
* {@inheritDoc}
*/
@Override
public Vector getVelocity() { public Vector getVelocity() {
return new Vector(0, 0, 0); return new Vector(0, 0, 0);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean useSafeTeleporter() { public boolean useSafeTeleporter() {
return false; return false;

View File

@ -14,16 +14,25 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
/**
* A player-{@link MVDestination}.
*/
public class PlayerDestination implements MVDestination { public class PlayerDestination implements MVDestination {
private String player; private String player;
private boolean isValid; private boolean isValid;
private JavaPlugin plugin; private JavaPlugin plugin;
/**
* {@inheritDoc}
*/
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return "pl"; return "pl";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isThisType(JavaPlugin plugin, String destination) { public boolean isThisType(JavaPlugin plugin, String destination) {
String[] items = destination.split(":"); String[] items = destination.split(":");
@ -36,6 +45,9 @@ public class PlayerDestination implements MVDestination {
return true; return true;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Location getLocation(Entity e) { public Location getLocation(Entity e) {
Player p = plugin.getServer().getPlayer(this.player); Player p = plugin.getServer().getPlayer(this.player);
@ -52,11 +64,17 @@ public class PlayerDestination implements MVDestination {
return null; return null;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isValid() { public boolean isValid() {
return this.isValid; return this.isValid;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDestination(JavaPlugin plugin, String destination) { public void setDestination(JavaPlugin plugin, String destination) {
String[] items = destination.split(":"); String[] items = destination.split(":");
@ -71,11 +89,17 @@ public class PlayerDestination implements MVDestination {
this.plugin = plugin; this.plugin = plugin;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getType() { public String getType() {
return "Player"; return "Player";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return this.player; return this.player;
@ -86,15 +110,25 @@ public class PlayerDestination implements MVDestination {
return "pl:" + this.player; return "pl:" + this.player;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getRequiredPermission() { public String getRequiredPermission() {
return ""; return "";
} }
/**
* {@inheritDoc}
*/
@Override
public Vector getVelocity() { public Vector getVelocity() {
return new Vector(0, 0, 0); return new Vector(0, 0, 0);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean useSafeTeleporter() { public boolean useSafeTeleporter() {
return true; return true;

View File

@ -16,17 +16,26 @@ import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
/**
* A world-{@link MVDestination}.
*/
public class WorldDestination implements MVDestination { public class WorldDestination implements MVDestination {
private boolean isValid; private boolean isValid;
private MultiverseWorld world; private MultiverseWorld world;
private float yaw = -1; private float yaw = -1;
private String direction = ""; private String direction = "";
/**
* {@inheritDoc}
*/
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return "w"; return "w";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isThisType(JavaPlugin plugin, String destination) { public boolean isThisType(JavaPlugin plugin, String destination) {
String[] items = destination.split(":"); String[] items = destination.split(":");
@ -48,6 +57,9 @@ public class WorldDestination implements MVDestination {
return false; return false;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public Location getLocation(Entity e) { public Location getLocation(Entity e) {
Location spawnLoc = getAcurateSpawnLocation(e, this.world); Location spawnLoc = getAcurateSpawnLocation(e, this.world);
@ -62,15 +74,23 @@ public class WorldDestination implements MVDestination {
if (world != null) { if (world != null) {
return world.getSpawnLocation(); return world.getSpawnLocation();
} else { } else {
// add 0.5 to x and z to center people
// (spawn location is stored as int meaning that you would spawn in the corner of a block)
return e.getWorld().getSpawnLocation().add(.5, 0, .5); return e.getWorld().getSpawnLocation().add(.5, 0, .5);
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isValid() { public boolean isValid() {
return this.isValid; return this.isValid;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDestination(JavaPlugin plugin, String destination) { public void setDestination(JavaPlugin plugin, String destination) {
String[] items = destination.split(":"); String[] items = destination.split(":");
@ -97,11 +117,17 @@ public class WorldDestination implements MVDestination {
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getType() { public String getType() {
return "World"; return "World";
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return this.world.getColoredWorldString(); return this.world.getColoredWorldString();
@ -115,6 +141,9 @@ public class WorldDestination implements MVDestination {
return this.world.getCBWorld().getName(); return this.world.getCBWorld().getName();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getRequiredPermission() { public String getRequiredPermission() {
// TODO: Potenitally replace spaces wiht tabs for friendlier yaml. // TODO: Potenitally replace spaces wiht tabs for friendlier yaml.
@ -122,10 +151,17 @@ public class WorldDestination implements MVDestination {
return "multiverse.access." + this.world.getName(); return "multiverse.access." + this.world.getName();
} }
/**
* {@inheritDoc}
*/
@Override
public Vector getVelocity() { public Vector getVelocity() {
return new Vector(0, 0, 0); return new Vector(0, 0, 0);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean useSafeTeleporter() { public boolean useSafeTeleporter() {
return true; return true;

View File

@ -0,0 +1,4 @@
/**
* This package contains all destination-types.
*/
package com.onarandombox.MultiverseCore.destination;

View File

@ -7,6 +7,24 @@
package com.onarandombox.MultiverseCore.enums; package com.onarandombox.MultiverseCore.enums;
/**
* A enum containing all actions that can be used to modify world-properties.
*/
public enum Action { public enum Action {
Set, Add, Remove, Clear /**
* Setting a property.
*/
Set,
/**
* Adding something to a list-property.
*/
Add,
/**
* Removing something from a list-property.
*/
Remove,
/**
* Clearing a list-property.
*/
Clear
} }

View File

@ -7,6 +7,20 @@
package com.onarandombox.MultiverseCore.enums; package com.onarandombox.MultiverseCore.enums;
/**
* An enum containing all list-properties.
*/
public enum AddProperties { public enum AddProperties {
worldblacklist, animals, monsters /**
* Worlds that people cannot go to from a world.
*/
worldblacklist,
/**
* Animal-exceptions.
*/
animals,
/**
* Monster-exceptions.
*/
monsters
} }

View File

@ -7,9 +7,52 @@
package com.onarandombox.MultiverseCore.enums; package com.onarandombox.MultiverseCore.enums;
/**
* An enum containing all config-properties that can be set.
*/
public enum ConfigProperty { public enum ConfigProperty {
messagecooldown, teleportcooldown, worldnameprefix, enforcegamemodes, enforceaccess, displaypermerrors, debug, firstspawnworld, teleportintercept, firstspawnoverride; /**
* How long to leave in between sending a message to the player. (NOT YET IMPLEMENTED)
*/
messagecooldown,
/**
* How fast are people allowed to use /MVTP (NOT YET IMPLEMENTED).
*/
teleportcooldown,
/**
* Prefix chat-messages with world-names.
*/
worldnameprefix,
/**
* If value is set to false, Multiverse will NOT enforce world access permissions.
*/
enforceaccess,
/**
* Whether users should get detailed information about the permissions they would need.
*/
displaypermerrors,
/**
* Debug-information.
*/
debug,
/**
* The world new users will spawn in.
*/
firstspawnworld,
/**
* Whether Multiverse should intercept teleports.
*/
teleportintercept,
/**
* Whether Multiverse should override the first spawn.
*/
firstspawnoverride;
/**
* Constructs a string containing all values in this enum.
*
* @return That {@link String}.
*/
public static String getAllValues() { public static String getAllValues() {
String buffer = ""; String buffer = "";
for (ConfigProperty c : ConfigProperty.values()) { for (ConfigProperty c : ConfigProperty.values()) {

View File

@ -9,22 +9,44 @@ package com.onarandombox.MultiverseCore.enums;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
/**
* A regular {@link ChatColor} represented by an english string.
*/
public enum EnglishChatColor { public enum EnglishChatColor {
/*
* I know. this is quite ugly.
*/
/** AQUA. */
AQUA("AQUA", ChatColor.AQUA), AQUA("AQUA", ChatColor.AQUA),
/** BLACK. */
BLACK("BLACK", ChatColor.BLACK), BLACK("BLACK", ChatColor.BLACK),
/** BLUE. */
BLUE("BLUE", ChatColor.BLUE), BLUE("BLUE", ChatColor.BLUE),
/** DARKAQUA. */
DARKAQUA("DARKAQUA", ChatColor.DARK_AQUA), DARKAQUA("DARKAQUA", ChatColor.DARK_AQUA),
/** DARKBLUE. */
DARKBLUE("DARKBLUE", ChatColor.DARK_BLUE), DARKBLUE("DARKBLUE", ChatColor.DARK_BLUE),
/** DARKGRAY. */
DARKGRAY("DARKGRAY", ChatColor.DARK_GRAY), DARKGRAY("DARKGRAY", ChatColor.DARK_GRAY),
/** DARKGREEN. */
DARKGREEN("DARKGREEN", ChatColor.DARK_GREEN), DARKGREEN("DARKGREEN", ChatColor.DARK_GREEN),
/** DARKPURPLE. */
DARKPURPLE("DARKPURPLE", ChatColor.DARK_PURPLE), DARKPURPLE("DARKPURPLE", ChatColor.DARK_PURPLE),
/** DARKRED. */
DARKRED("DARKRED", ChatColor.DARK_RED), DARKRED("DARKRED", ChatColor.DARK_RED),
/** GOLD. */
GOLD("GOLD", ChatColor.GOLD), GOLD("GOLD", ChatColor.GOLD),
/** GRAY. */
GRAY("GRAY", ChatColor.GRAY), GRAY("GRAY", ChatColor.GRAY),
/** GREEN. */
GREEN("GREEN", ChatColor.GREEN), GREEN("GREEN", ChatColor.GREEN),
/** LIGHTPURPLE. */
LIGHTPURPLE("LIGHTPURPLE", ChatColor.LIGHT_PURPLE), LIGHTPURPLE("LIGHTPURPLE", ChatColor.LIGHT_PURPLE),
/** RED. */
RED("RED", ChatColor.RED), RED("RED", ChatColor.RED),
/** YELLOW. */
YELLOW("YELLOW", ChatColor.YELLOW), YELLOW("YELLOW", ChatColor.YELLOW),
/** WHITE. */
WHITE("WHITE", ChatColor.WHITE); WHITE("WHITE", ChatColor.WHITE);
private ChatColor color; private ChatColor color;
private String text; private String text;
@ -34,14 +56,26 @@ public enum EnglishChatColor {
this.text = name; this.text = name;
} }
/**
* Gets the text.
* @return The text.
*/
public String getText() { public String getText() {
return this.text; return this.text;
} }
/**
* Gets the color.
* @return The color as {@link ChatColor}.
*/
public ChatColor getColor() { public ChatColor getColor() {
return this.color; return this.color;
} }
/**
* Constructs a string containing all available colors.
* @return That {@link String}.
*/
public static String getAllColors() { public static String getAllColors() {
String buffer = ""; String buffer = "";
for (EnglishChatColor c : EnglishChatColor.values()) { for (EnglishChatColor c : EnglishChatColor.values()) {
@ -50,6 +84,11 @@ public enum EnglishChatColor {
return buffer; return buffer;
} }
/**
* Constructs an {@link EnglishChatColor} from a {@link String}.
* @param text The {@link String}.
* @return The {@link EnglishChatColor}.
*/
public static EnglishChatColor fromString(String text) { public static EnglishChatColor fromString(String text) {
if (text != null) { if (text != null) {
for (EnglishChatColor c : EnglishChatColor.values()) { for (EnglishChatColor c : EnglishChatColor.values()) {

View File

@ -7,6 +7,32 @@
package com.onarandombox.MultiverseCore.enums; package com.onarandombox.MultiverseCore.enums;
/**
* An enum containing possible teleport-results.
*/
public enum TeleportResult { public enum TeleportResult {
FAIL_PERMISSION, FAIL_UNSAFE, FAIL_TOO_POOR, FAIL_INVALID, FAIL_OTHER, SUCCESS /**
* Insufficient permissions.
*/
FAIL_PERMISSION,
/**
* The teleport was unsafe.
*/
FAIL_UNSAFE,
/**
* The player was to poor.
*/
FAIL_TOO_POOR,
/**
* The teleport was invalid.
*/
FAIL_INVALID,
/**
* Unknown reason.
*/
FAIL_OTHER,
/**
* The player was successfully teleported.
*/
SUCCESS
} }

View File

@ -0,0 +1,4 @@
/**
* This package contains all enums.
*/
package com.onarandombox.MultiverseCore.enums;

View File

@ -1,30 +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.event;
import org.bukkit.event.Event;
import java.util.List;
public class MVConfigMigrateEvent extends Event {
private static final long serialVersionUID = 3647950355746345397L;
private List<String> configsLoaded;
public MVConfigMigrateEvent(List<String> configsLoaded) {
super("MVConfigMigrate");
this.configsLoaded = configsLoaded;
}
public void addConfig(String config) {
this.configsLoaded.add(config);
}
public List<String> getAllConfigsLoaded() {
return this.configsLoaded;
}
}

View File

@ -11,6 +11,9 @@ import org.bukkit.event.Event;
import java.util.List; import java.util.List;
/**
* Called when the Multiverse-config should be reloaded.
*/
public class MVConfigReloadEvent extends Event { public class MVConfigReloadEvent extends Event {
private static final long serialVersionUID = 3647950355746345397L; private static final long serialVersionUID = 3647950355746345397L;
private List<String> configsLoaded; private List<String> configsLoaded;
@ -20,10 +23,18 @@ public class MVConfigReloadEvent extends Event {
this.configsLoaded = configsLoaded; this.configsLoaded = configsLoaded;
} }
/**
* Adds a config to this event.
* @param config The config to add.
*/
public void addConfig(String config) { public void addConfig(String config) {
this.configsLoaded.add(config); this.configsLoaded.add(config);
} }
/**
* Gets all loaded configs.
* @return A list of all loaded configs.
*/
public List<String> getAllConfigsLoaded() { public List<String> getAllConfigsLoaded() {
return this.configsLoaded; return this.configsLoaded;
} }

View File

@ -0,0 +1,54 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.event;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
/**
* This event is thrown when a portal is touched.
*/
public class MVPlayerTouchedPortalEvent extends Event implements Cancellable {
private Player p;
private Location l;
private boolean isCancelled;
public MVPlayerTouchedPortalEvent(Player p, Location l) {
super("MVPlayerTouchedPortalEvent");
this.p = p;
this.l = l;
}
/**
* Gets the {@link Location} of the portal-block that was touched.
* @return The {@link Location} of the portal-block that was touched.
*/
public Location getBlockTouched() {
return this.l;
}
/**
* Gets the {@link Player} that's touching the portal.
* @return The {@link Player} that's touching the portal.
*/
public Player getPlayer() {
return this.p;
}
@Override
public boolean isCancelled() {
return this.isCancelled;
}
@Override
public void setCancelled(boolean b) {
this.isCancelled = b;
}
}

View File

@ -11,6 +11,9 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
/**
* Called when a player is respawning.
*/
public class MVRespawnEvent extends Event { public class MVRespawnEvent extends Event {
private Player player; private Player player;
private Location location; private Location location;
@ -24,18 +27,34 @@ public class MVRespawnEvent extends Event {
this.respawnMethod = respawnMethod; this.respawnMethod = respawnMethod;
} }
/**
* Gets the {@link Player} that's respawning.
* @return The {@link Player} that's respawning.
*/
public Player getPlayer() { public Player getPlayer() {
return this.player; return this.player;
} }
/**
* Gets the respawn-method.
* @return The respawn-method.
*/
public String getRespawnMethod() { public String getRespawnMethod() {
return this.respawnMethod; return this.respawnMethod;
} }
/**
* Gets the player's respawn-{@link Location}.
* @return The player's respawn-{@link Location}.
*/
public Location getPlayersRespawnLocation() { public Location getPlayersRespawnLocation() {
return this.location; return this.location;
} }
/**
* Sets the player's respawn-{@link Location}.
* @param l The new respawn-{@link Location}.
*/
public void setRespawnLocation(Location l) { public void setRespawnLocation(Location l) {
this.location = l; this.location = l;
} }

View File

@ -8,6 +8,7 @@
package com.onarandombox.MultiverseCore.event; package com.onarandombox.MultiverseCore.event;
import com.onarandombox.MultiverseCore.api.MVDestination; import com.onarandombox.MultiverseCore.api.MVDestination;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -68,6 +69,14 @@ public class MVTeleportEvent extends Event implements Cancellable {
return this.dest; return this.dest;
} }
/**
* Looks if this {@link MVTeleportEvent} is using the {@link SafeTTeleporter}.
* @return True if this {@link MVTeleportEvent} is using the {@link SafeTTeleporter}.
*/
public boolean isUsingSafeTTeleporter() {
return useSafeTeleport;
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return this.isCancelled; return this.isCancelled;

View File

@ -0,0 +1,32 @@
package com.onarandombox.MultiverseCore.event;
import org.bukkit.event.Event;
/**
* Called when somebody requests version information about Multiverse.
*/
public class MVVersionEvent extends Event {
private final StringBuilder versionInfoBuilder;
public MVVersionEvent(String versionInfo) {
super("MVVersionEvent");
versionInfoBuilder = new StringBuilder(versionInfo);
}
/**
* Gets the version-info currently saved in this event.
* @return The version-info.
*/
public String getVersionInfo() {
return versionInfoBuilder.toString();
}
/**
* Appends more version-info to the version-info currently saved in this event.
* @param moreVersionInfo The version-info to add. Should end with '\n'.
*/
public void appendVersionInfo(String moreVersionInfo) {
versionInfoBuilder.append(moreVersionInfo);
}
}

View File

@ -9,6 +9,11 @@ package com.onarandombox.MultiverseCore.event;
import org.bukkit.event.Event; import org.bukkit.event.Event;
/**
* Called when somebody requests version information about Multiverse.
* @deprecated Use {@link MVVersionEvent} instead.
*/
@Deprecated
public class MVVersionRequestEvent extends Event { public class MVVersionRequestEvent extends Event {
private String pasteBinBuffer; private String pasteBinBuffer;
@ -18,10 +23,22 @@ public class MVVersionRequestEvent extends Event {
this.pasteBinBuffer = pasteBinBuffer; this.pasteBinBuffer = pasteBinBuffer;
} }
/**
* Gets the pasteBinBuffer.
* @return The pasteBinBuffer.
* @deprecated Use {@link MVVersionEvent} instead.
*/
@Deprecated
public String getPasteBinBuffer() { public String getPasteBinBuffer() {
return this.pasteBinBuffer; return this.pasteBinBuffer;
} }
/**
* Sets the pasteBinBuffer.
* @param buffer The new pasteBinBuffer.
* @deprecated Use {@link MVVersionEvent} instead.
*/
@Deprecated
public void setPasteBinBuffer(String buffer) { public void setPasteBinBuffer(String buffer) {
this.pasteBinBuffer = buffer; this.pasteBinBuffer = buffer;
} }

View File

@ -15,7 +15,7 @@ import org.bukkit.event.Event;
/** /**
* This event is fired *before* the property is actually changed. * This event is fired *before* the property is actually changed.
* <p> * <p>
* If it is cancled, 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() * If you want to get the value being changed, use getProperty()
@ -36,14 +36,26 @@ public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
this.value = value; this.value = value;
} }
/**
* Gets the changed world property's name.
* @return The changed world property's name.
*/
public String getPropertyName() { public String getPropertyName() {
return this.name; return this.name;
} }
/**
* Gets the new value.
* @return The new value.
*/
public String getNewValue() { public String getNewValue() {
return this.value; return this.value;
} }
/**
* Sets the new value.
* @param value The new new value.
*/
public void setNewValue(String value) { public void setNewValue(String value) {
this.value = value; this.value = value;
} }

View File

@ -0,0 +1,4 @@
/**
* This package contains all events.
*/
package com.onarandombox.MultiverseCore.event;

View File

@ -7,6 +7,9 @@
package com.onarandombox.MultiverseCore.exceptions; package com.onarandombox.MultiverseCore.exceptions;
/**
* Thrown when a world-property doesn't exist.
*/
public class PropertyDoesNotExistException extends Exception { public class PropertyDoesNotExistException extends Exception {
public PropertyDoesNotExistException(String name) { public PropertyDoesNotExistException(String name) {
super(name); super(name);

View File

@ -0,0 +1,4 @@
/**
* This package contains all exceptions.
*/
package com.onarandombox.MultiverseCore.exceptions;

View File

@ -10,7 +10,6 @@ package com.onarandombox.MultiverseCore.listeners;
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.utils.PermissionTools;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Animals; import org.bukkit.entity.Animals;
import org.bukkit.entity.CreatureType; import org.bukkit.entity.CreatureType;
@ -29,16 +28,17 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Multiverse's {@link EntityListener}.
*/
public class MVEntityListener extends EntityListener { public class MVEntityListener extends EntityListener {
private MultiverseCore plugin; private MultiverseCore plugin;
private MVWorldManager worldManager; private MVWorldManager worldManager;
private PermissionTools pt;
public MVEntityListener(MultiverseCore plugin) { public MVEntityListener(MultiverseCore plugin) {
this.plugin = plugin; this.plugin = plugin;
this.worldManager = plugin.getMVWorldManager(); this.worldManager = plugin.getMVWorldManager();
this.pt = new PermissionTools(this.plugin);
} }
@Override @Override
@ -73,6 +73,7 @@ public class MVEntityListener extends EntityListener {
/** /**
* Handle Animal/Monster Spawn settings, seems like a more concrete method than using CraftBukkit. * Handle Animal/Monster Spawn settings, seems like a more concrete method than using CraftBukkit.
* @param event The event.
*/ */
@Override @Override
public void onCreatureSpawn(CreatureSpawnEvent event) { public void onCreatureSpawn(CreatureSpawnEvent event) {

View File

@ -12,20 +12,26 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent; import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
import com.onarandombox.MultiverseCore.utils.PermissionTools; import com.onarandombox.MultiverseCore.utils.PermissionTools;
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.*; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Multiverse's {@link PlayerListener}.
*/
public class MVPlayerListener extends PlayerListener { public class MVPlayerListener extends PlayerListener {
private MultiverseCore plugin; private MultiverseCore plugin;
private SafeTTeleporter mvteleporter;
private MVWorldManager worldManager; private MVWorldManager worldManager;
private PermissionTools pt; private PermissionTools pt;
@ -116,20 +122,14 @@ public class MVPlayerListener extends PlayerListener {
this.plugin.log(Level.FINE, "Player joined AGAIN!"); this.plugin.log(Level.FINE, "Player joined AGAIN!");
} }
// Handle the Players GameMode setting for the new world. // Handle the Players GameMode setting for the new world.
if (MultiverseCore.EnforceGameModes) {
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
} }
}
@Override @Override
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
// Handle the Players GameMode setting for the new world. // Permissions now determine whether or not to handle a gamemode.
if (MultiverseCore.EnforceGameModes) {
// Not yet implemented, but eventually we'll switch to this!
//if (this.plugin.getMVWorldManager().getMVWorld(event.getPlayer().getWorld()).getEnforceGameMode())
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
} }
}
@Override @Override
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
@ -154,7 +154,8 @@ public class MVPlayerListener extends PlayerListener {
teleporter = this.plugin.getServer().getPlayer(teleporterName); teleporter = this.plugin.getServer().getPlayer(teleporterName);
} }
} }
this.plugin.log(Level.FINEST, "Inferred sender '" + teleporter + "' from name '" + teleporterName + "', fetched from name '" + teleportee.getName() + "'"); this.plugin.log(Level.FINEST, String.format("Inferred sender '%s' from name '%s', fetched from name '%s'",
teleporter, teleporterName, teleportee.getName()));
MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) { if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
@ -166,37 +167,28 @@ public class MVPlayerListener extends PlayerListener {
// Charge the teleporter // Charge the teleporter
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true)); event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true));
if (event.isCancelled() && teleporter != null) { if (event.isCancelled() && teleporter != null) {
this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because '%s' don't have the FUNDS required to enter it.",
"' because '" + teleporter.getName() + "' don't have the FUNDS required to enter it."); teleportee.getName(), event.getTo().getWorld().getName(), teleporter.getName()));
return; return;
} }
if (MultiverseCore.EnforceAccess) { if (MultiverseCore.EnforceAccess) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee)); event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
if (event.isCancelled() && teleporter != null) { if (event.isCancelled() && teleporter != null) {
this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because '%s' don't have: multiverse.access.%s",
"' because '" + teleporter.getName() + "' don't have: multiverse.access." + event.getTo().getWorld().getName()); teleportee.getName(), event.getTo().getWorld().getName(), teleporter.getName(), event.getTo().getWorld().getName()));
} }
} else { } else {
this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was allowed to go to '" + event.getTo().getWorld().getName() + "' because enforceaccess is off."); this.plugin.log(Level.FINE, String.format("Player '%s' was allowed to go to '%s' because enforceaccess is off.",
teleportee.getName(), event.getTo().getWorld().getName()));
} }
} }
@Override @Override
public void onPlayerPortal(PlayerPortalEvent event) { public void onPlayerPortal(PlayerPortalEvent event) {
if (event.isCancelled() || event.getFrom() == null) { if (event.isCancelled() || (event.getFrom() == null)) {
return; return;
} }
// REMEMBER! getTo MAY be NULL HERE!!! // The adjust should have happened much earlier.
// If the player was actually outside of the portal, adjust the from location
if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.PORTAL) {
Location newloc = SafeTTeleporter.findPortalBlockNextTo(event.getFrom());
// TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what
// TODO: we want to do here.
if (newloc != null) {
event.setFrom(newloc);
}
}
// Wait for the adjust, then return!
if (event.getTo() == null) { if (event.getTo() == null) {
return; return;
} }
@ -209,25 +201,32 @@ public class MVPlayerListener extends PlayerListener {
} }
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, event.getPlayer(), event.getPlayer(), true)); event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, event.getPlayer(), event.getPlayer(), true));
if (event.isCancelled()) { if (event.isCancelled()) {
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName() + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have the FUNDS required to enter.",
"' because they don't have the FUNDS required to enter."); event.getPlayer().getName(), event.getTo().getWorld().getName()));
return; return;
} }
if (MultiverseCore.EnforceAccess) { if (MultiverseCore.EnforceAccess) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer())); event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer()));
if (event.isCancelled()) { if (event.isCancelled()) {
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName() + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have: multiverse.access.%s",
"' because they don't have: multiverse.access." + event.getTo().getWorld().getName()); event.getPlayer().getName(), event.getTo().getWorld().getName(), event.getTo().getWorld().getName()));
} }
} else { } else {
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName() + "' was allowed to go to '" + event.getTo().getWorld().getName() + "' because enforceaccess is off."); this.plugin.log(Level.FINE, String.format("Player '%s' was allowed to go to '%s' because enforceaccess is off.",
event.getPlayer().getName(), event.getTo().getWorld().getName()));
} }
} }
private void spawnNewPlayer(Player player) { private void spawnNewPlayer(final Player player) {
// Spawn the player 1 tick after the login. I'm sure there's GOT to be a better way to do this... // Spawn 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, new SpawnNewbie(player, this.plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation()), 1L); this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
public void run() {
player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation());
} }
}, 1L);
}
// FOLLOWING 2 Methods and Private class handle Per Player GameModes. // FOLLOWING 2 Methods and Private class handle Per Player GameModes.
private void handleGameMode(Player player, World world) { private void handleGameMode(Player player, World world) {
@ -237,53 +236,34 @@ public class MVPlayerListener extends PlayerListener {
} }
} }
public void handleGameMode(Player player, MultiverseWorld world) { /**
* Handles the gamemode for the specified {@link Player}.
* @param player The {@link Player}.
* @param world The world the player is in.
*/
public void handleGameMode(final Player player, final MultiverseWorld world) {
// We perform this task one tick later to MAKE SURE that the player actually reaches the // We perform this task one tick later to MAKE SURE that the player actually reaches the
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere. // destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) { if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
this.plugin.log(Level.FINE, "Handeling gamemode for player: " + player.getName()); this.plugin.log(Level.FINE, "Handeling gamemode for player: " + player.getName());
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new HandleGameMode(player, world), 1L); this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
} else { new Runnable() {
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
}
}
private class SpawnNewbie implements Runnable {
private Player player;
private Location spawn;
private SpawnNewbie(Player player, Location spawn) {
this.player = player;
this.spawn = spawn;
}
@Override
public void run() {
this.player.teleport(this.spawn);
}
}
/**
* The following private class is used to handle player game mode changes within a scheduler.
*/
private class HandleGameMode implements Runnable {
private Player player;
private MultiverseWorld world;
private HandleGameMode(Player player, MultiverseWorld world) {
this.player = player;
this.world = world;
}
@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().getName().equals(world.getCBWorld().getName())) { if (player.getWorld() == world.getCBWorld()) {
MultiverseCore.staticLog(Level.FINE, "Handeling gamemode for player: " + player.getName() + ", " + world.getGameMode().toString()); MultiverseCore.staticLog(Level.FINE, "Handeling gamemode for player: " + player.getName() + ", " + world.getGameMode().toString());
MultiverseCore.staticLog(Level.FINE, "PWorld: " + player.getWorld()); MultiverseCore.staticLog(Level.FINE, "PWorld: " + player.getWorld());
MultiverseCore.staticLog(Level.FINE, "AWorld: " + world); MultiverseCore.staticLog(Level.FINE, "AWorld: " + world);
player.setGameMode(world.getGameMode()); player.setGameMode(world.getGameMode());
} } else {
MultiverseCore.staticLog(Level.FINE,
String.format("The gamemode was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
player.getName(), player.getWorld().getName(), world.getName()));
}
}
}, 1L);
} else {
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
} }
} }
} }

View File

@ -16,6 +16,9 @@ import org.bukkit.event.server.ServerListener;
import java.util.Arrays; import java.util.Arrays;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Multiverse's {@link ServerListener}.
*/
public class MVPluginListener extends ServerListener { public class MVPluginListener extends ServerListener {
private MultiverseCore plugin; private MultiverseCore plugin;
@ -24,7 +27,10 @@ public class MVPluginListener extends ServerListener {
this.plugin = plugin; this.plugin = plugin;
} }
/** Keep an eye out for Plugins which we can utilize. */ /**
* Keep an eye out for Plugins which we can utilize.
* @param event The event.
*/
@Override @Override
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
// Let AllPay handle all econ plugin loadings, only go for econ plugins we support // Let AllPay handle all econ plugin loadings, only go for econ plugins we support
@ -38,7 +44,10 @@ public class MVPluginListener extends ServerListener {
} }
} }
/** We'll check if any of the plugins we rely on decide to Disable themselves. */ /**
* We'll check if any of the plugins we rely on decide to Disable themselves.
* @param event The event.
*/
@Override @Override
public void onPluginDisable(PluginDisableEvent event) { public void onPluginDisable(PluginDisableEvent event) {
// TODO: Disable econ when it disables. // TODO: Disable econ when it disables.

View File

@ -0,0 +1,55 @@
/******************************************************************************
* 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.listeners;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerPortalEvent;
import java.util.logging.Level;
/**
* Multiverse's second {@link PlayerListener}.
* <p>
* Used to double-monitor {@link Type#PLAYER_PORTAL}.
*/
public class MVPortalAdjustListener extends PlayerListener {
private MultiverseCore plugin;
public MVPortalAdjustListener(MultiverseCore core) {
this.plugin = core;
}
@Override
public void onPlayerPortal(PlayerPortalEvent event) {
this.plugin.log(Level.FINE, "CALLING CORE-ADJUST!!!");
if (event.isCancelled() || event.getFrom() == null) {
return;
}
// REMEMBER! getTo MAY be NULL HERE!!!
// If the player was actually outside of the portal, adjust the from location
if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.PORTAL) {
Location newloc = SafeTTeleporter.findPortalBlockNextTo(event.getFrom());
// TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what
// TODO: we want to do here.
if (newloc != null) {
event.setFrom(newloc);
}
}
// Wait for the adjust, then return!
if (event.getTo() == null) {
return;
}
}
}

View File

@ -13,6 +13,9 @@ import org.bukkit.event.weather.ThunderChangeEvent;
import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.weather.WeatherListener; import org.bukkit.event.weather.WeatherListener;
/**
* Multiverse's {@link WeatherListener}.
*/
public class MVWeatherListener extends WeatherListener { public class MVWeatherListener extends WeatherListener {
private MultiverseCore plugin; private MultiverseCore plugin;
@ -22,7 +25,6 @@ public class MVWeatherListener extends WeatherListener {
@Override @Override
public void onWeatherChange(WeatherChangeEvent event) { public void onWeatherChange(WeatherChangeEvent event) {
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName()); MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName());
if (world != null) { if (world != null) {
// If it's going to start raining and we have weather disabled // If it's going to start raining and we have weather disabled
@ -32,7 +34,6 @@ public class MVWeatherListener extends WeatherListener {
@Override @Override
public void onThunderChange(ThunderChangeEvent event) { public void onThunderChange(ThunderChangeEvent event) {
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName()); MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName());
if (world != null) { if (world != null) {
// If it's going to start raining and we have weather disabled // If it's going to start raining and we have weather disabled

View File

@ -0,0 +1,96 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.event.CustomEventListener;
import org.bukkit.event.Event;
import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent;
import com.onarandombox.MultiverseCore.event.MVPlayerTouchedPortalEvent;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
import com.onarandombox.MultiverseCore.event.MVTeleportEvent;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent;
/**
* Subclasses of this listener can be used to conveniently listen to MultiverseCore-events.
*/
public abstract class MultiverseCoreListener extends CustomEventListener {
/**
* {@inheritDoc}
*/
@Override
public final void onCustomEvent(Event event) {
if (event.getEventName().equals("MVConfigReload") && event instanceof MVConfigReloadEvent) {
onMVConfigReload((MVConfigReloadEvent) event);
} else if (event.getEventName().equals("MVPlayerTouchedPortalEvent") && event instanceof MVPlayerTouchedPortalEvent) {
onPlayerTouchedPortal((MVPlayerTouchedPortalEvent) event);
} else if (event.getEventName().equals("MVRespawn") && event instanceof MVRespawnEvent) {
onPlayerRespawn((MVRespawnEvent) event);
} else if (event.getEventName().equals("SafeTTeleporter") && event instanceof MVTeleportEvent) {
onPlayerTeleport((MVTeleportEvent) event);
} else if (event.getEventName().equals("MVVersionEvent") && event instanceof MVVersionEvent) {
onVersionRequest((MVVersionEvent) event);
} else if (event.getEventName().equals("MVWorldDeleteEvent") && event instanceof MVWorldDeleteEvent) {
onWorldDelete((MVWorldDeleteEvent) event);
} else if (event.getEventName().equals("MVWorldPropertyChange") && event instanceof MVWorldPropertyChangeEvent) {
onWorldPropertyChange((MVWorldPropertyChangeEvent) event);
}
}
/**
* Called when a {@link MVWorldPropertyChangeEvent} is fired.
* @param event The event.
*/
public void onWorldPropertyChange(MVWorldPropertyChangeEvent event) {
}
/**
* Called when a {@link MVWorldDeleteEvent} is fired.
* @param event The event.
*/
public void onWorldDelete(MVWorldDeleteEvent event) {
}
/**
* Called when a {@link MVVersionEvent} is fired.
* @param event The event.
*/
public void onVersionRequest(MVVersionEvent event) {
}
/**
* Called when a {@link MVTeleportEvent} is fired.
* @param event The event.
*/
public void onPlayerTeleport(MVTeleportEvent event) {
}
/**
* Called when a {@link MVRespawnEvent} is fired.
* @param event The event.
*/
public void onPlayerRespawn(MVRespawnEvent event) {
}
/**
* Called when a {@link MVPlayerTouchedPortalEvent} is fired.
* @param event The event.
*/
public void onPlayerTouchedPortal(MVPlayerTouchedPortalEvent event) {
}
/**
* Called when a {@link MVConfigReloadEvent} is fired.
* @param event The event.
*/
public void onMVConfigReload(MVConfigReloadEvent event) {
}
}

View File

@ -0,0 +1,4 @@
/**
* This package contains all listeners.
*/
package com.onarandombox.MultiverseCore.listeners;

View File

@ -0,0 +1,4 @@
/**
* The "master"-package, containing everything related to Multiverse-Core.
*/
package com.onarandombox.MultiverseCore;

View File

@ -17,12 +17,16 @@ import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Manages anchors.
*/
public class AnchorManager { public class AnchorManager {
private MultiverseCore plugin; private MultiverseCore plugin;
private Map<String, Location> anchors; private Map<String, Location> anchors;
@ -33,15 +37,18 @@ public class AnchorManager {
this.anchors = new HashMap<String, Location>(); this.anchors = new HashMap<String, Location>();
} }
/**
* Loads all anchors.
*/
public void loadAnchors() { public void loadAnchors() {
this.anchors = new HashMap<String, Location>(); this.anchors = new HashMap<String, Location>();
this.anchorConfig = YamlConfiguration.loadConfiguration(new File(this.plugin.getDataFolder(), "anchors.yml")); this.anchorConfig = YamlConfiguration.loadConfiguration(new File(this.plugin.getDataFolder(), "anchors.yml"));
this.ensureConfigIsPrepared(); this.ensureConfigIsPrepared();
ConfigurationSection anchors = this.anchorConfig.getConfigurationSection("anchors"); ConfigurationSection anchorsSection = this.anchorConfig.getConfigurationSection("anchors");
Set<String> anchorKeys = anchors.getKeys(false); Set<String> anchorKeys = anchorsSection.getKeys(false);
for (String key : anchorKeys) { for (String key : anchorKeys) {
//world:x,y,z:pitch:yaw //world:x,y,z:pitch:yaw
Location anchorLocation = LocationManipulation.stringToLocation(anchors.getString(key, "")); Location anchorLocation = LocationManipulation.stringToLocation(anchorsSection.getString(key, ""));
if (anchorLocation != null) { if (anchorLocation != null) {
MultiverseCore.staticLog(Level.INFO, "Loading anchor: '" + key + "'..."); MultiverseCore.staticLog(Level.INFO, "Loading anchor: '" + key + "'...");
this.anchors.put(key, anchorLocation); this.anchors.put(key, anchorLocation);
@ -58,6 +65,10 @@ public class AnchorManager {
} }
} }
/**
* Saves all anchors.
* @return True if all anchors were successfully saved.
*/
public boolean saveAnchors() { public boolean saveAnchors() {
try { try {
this.anchorConfig.save(new File(this.plugin.getDataFolder(), "anchors.yml")); this.anchorConfig.save(new File(this.plugin.getDataFolder(), "anchors.yml"));
@ -68,6 +79,11 @@ public class AnchorManager {
} }
} }
/**
* Gets the {@link Location} associated with an anchor.
* @param anchor The name of the anchor.
* @return The {@link Location}.
*/
public Location getAnchorLocation(String anchor) { public Location getAnchorLocation(String anchor) {
if (this.anchors.containsKey(anchor)) { if (this.anchors.containsKey(anchor)) {
return this.anchors.get(anchor); return this.anchors.get(anchor);
@ -75,11 +91,23 @@ public class AnchorManager {
return null; return null;
} }
/**
* Saves an anchor.
* @param anchor The name of the anchor.
* @param location The location of the anchor as string.
* @return True if the anchor was successfully saved.
*/
public boolean saveAnchorLocation(String anchor, String location) { public boolean saveAnchorLocation(String anchor, String location) {
Location parsed = LocationManipulation.stringToLocation(location); Location parsed = LocationManipulation.stringToLocation(location);
return parsed != null && this.saveAnchorLocation(anchor, parsed); return parsed != null && this.saveAnchorLocation(anchor, parsed);
} }
/**
* Saves an anchor.
* @param anchor The name of the anchor.
* @param l The {@link Location} of the anchor.
* @return True if the anchor was successfully saved.
*/
public boolean saveAnchorLocation(String anchor, Location l) { public boolean saveAnchorLocation(String anchor, Location l) {
if (l == null) { if (l == null) {
return false; return false;
@ -89,27 +117,41 @@ public class AnchorManager {
return this.saveAnchors(); return this.saveAnchors();
} }
/**
* Gets all anchors.
* @return An unmodifiable {@link Set} containing all anchors.
*/
public Set<String> getAllAnchors() { public Set<String> getAllAnchors() {
return this.anchors.keySet(); return Collections.unmodifiableSet(this.anchors.keySet());
} }
/**
* Gets all anchors that the specified {@link Player} can access.
* @param p The {@link Player}.
* @return An unmodifiable {@link Set} containing all anchors the specified {@link Player} can access.
*/
public Set<String> getAnchors(Player p) { public Set<String> getAnchors(Player p) {
if (p == null) { if (p == null) {
return this.anchors.keySet(); return this.anchors.keySet();
} }
Set<String> anchors = new HashSet<String>(); Set<String> myAnchors = new HashSet<String>();
for (String anchor : this.anchors.keySet()) { for (String anchor : this.anchors.keySet()) {
Location ancLoc = this.anchors.get(anchor); Location ancLoc = this.anchors.get(anchor);
if (ancLoc == null) { if (ancLoc == null) {
continue; continue;
} }
if (p.hasPermission("multiverse.access." + ancLoc.getWorld().getName())) { if (p.hasPermission("multiverse.access." + ancLoc.getWorld().getName())) {
anchors.add(anchor); myAnchors.add(anchor);
} }
} }
return anchors; return Collections.unmodifiableSet(myAnchors);
} }
/**
* Deletes the specified anchor.
* @param s The name of the anchor.
* @return True if the anchor was successfully deleted.
*/
public boolean deleteAnchor(String s) { public boolean deleteAnchor(String s) {
if (this.anchors.containsKey(s)) { if (this.anchors.containsKey(s)) {
this.anchors.remove(s); this.anchors.remove(s);

View File

@ -11,32 +11,40 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Minecart; import org.bukkit.entity.Minecart;
import org.bukkit.entity.Vehicle; import org.bukkit.entity.Vehicle;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Used to determine block/location-related facts.
*/
public class BlockSafety { public class BlockSafety {
public BlockSafety() {
// TODO Auto-generated constructor stub
}
/** /**
* This function checks whether the block at the given coordinates are above air or not. * This function checks whether the block at the given coordinates are above air or not.
* @param l The {@link Location} of the block.
* @return True if the block at that {@link Location} is above air.
*/ */
public boolean isBlockAboveAir(Location l) { public boolean isBlockAboveAir(Location l) {
Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); Location downOne = l.clone();
downOne.setY(downOne.getY() - 1); downOne.setY(downOne.getY() - 1);
return (downOne.getBlock().getType() == Material.AIR); return (downOne.getBlock().getType() == Material.AIR);
} }
public boolean blockIsNotSafe(World world, double x, double y, double z) { // TODO maybe remove this?
Location l = new Location(world, x, y, z); private boolean blockIsNotSafe(World world, double x, double y, double z) {
return !playerCanSpawnHereSafely(l); return !playerCanSpawnHereSafely(world, x, y, z);
} }
/**
* Checks if a player can spawn safely at the given coordinates.
* @param world The {@link World}.
* @param x The x-coordinate.
* @param y The y-coordinate.
* @param z The z-coordinate.
* @return True if a player can spawn safely at the given coordinates.
*/
public boolean playerCanSpawnHereSafely(World world, double x, double y, double z) { public boolean playerCanSpawnHereSafely(World world, double x, double y, double z) {
Location l = new Location(world, x, y, z); Location l = new Location(world, x, y, z);
return playerCanSpawnHereSafely(l); return playerCanSpawnHereSafely(l);
@ -62,20 +70,24 @@ public class BlockSafety {
upOne.setY(upOne.getY() + 1); upOne.setY(upOne.getY() + 1);
downOne.setY(downOne.getY() - 1); downOne.setY(downOne.getY() - 1);
if (this.isSolidBlock(world.getBlockAt(actual).getType()) || if (this.isSolidBlock(world.getBlockAt(actual).getType())
this.isSolidBlock(upOne.getBlock().getType())) { || this.isSolidBlock(upOne.getBlock().getType())) {
MultiverseCore.staticLog(Level.FINER, "Error Here (Actual)? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]"); MultiverseCore.staticLog(Level.FINER, "Error Here (Actual)? ("
MultiverseCore.staticLog(Level.FINER, "Error Here (upOne)? (" + upOne.getBlock().getType() + ")[" + this.isSolidBlock(upOne.getBlock().getType()) + "]"); + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
MultiverseCore.staticLog(Level.FINER, "Error Here (upOne)? ("
+ upOne.getBlock().getType() + ")[" + this.isSolidBlock(upOne.getBlock().getType()) + "]");
return false; return false;
} }
if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) { if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
MultiverseCore.staticLog(Level.FINER, "Error Here (downOne)? (" + downOne.getBlock().getType() + ")[" + this.isSolidBlock(downOne.getBlock().getType()) + "]"); MultiverseCore.staticLog(Level.FINER, "Error Here (downOne)? ("
+ downOne.getBlock().getType() + ")[" + this.isSolidBlock(downOne.getBlock().getType()) + "]");
return false; return false;
} }
if (downOne.getBlock().getType() == Material.FIRE) { if (downOne.getBlock().getType() == Material.FIRE) {
MultiverseCore.staticLog(Level.FINER, "There's fire below! (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]"); MultiverseCore.staticLog(Level.FINER, "There's fire below! ("
+ actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
return false; return false;
} }
@ -87,9 +99,14 @@ public class BlockSafety {
return true; return true;
} }
/**
* Gets the location of the top block at the specified {@link Location}.
* @param l Any {@link Location}.
* @return The {@link Location} of the top-block.
*/
public Location getTopBlock(Location l) { public Location getTopBlock(Location l) {
Location check = l.clone(); Location check = l.clone();
check.setY(127); check.setY(127); // SUPPRESS CHECKSTYLE: MagicNumberCheck
while (check.getY() > 0) { while (check.getY() > 0) {
if (this.playerCanSpawnHereSafely(check)) { if (this.playerCanSpawnHereSafely(check)) {
return check; return check;
@ -99,10 +116,15 @@ public class BlockSafety {
return null; return null;
} }
/**
* Gets the location of the top block at the specified {@link Location}.
* @param l Any {@link Location}.
* @return The {@link Location} of the top-block.
*/
public Location getBottomBlock(Location l) { public Location getBottomBlock(Location l) {
Location check = l.clone(); Location check = l.clone();
check.setY(0); check.setY(0);
while (check.getY() <= 126) { while (check.getY() < 127) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
if (this.playerCanSpawnHereSafely(check)) { if (this.playerCanSpawnHereSafely(check)) {
return check; return check;
} }
@ -111,7 +133,7 @@ public class BlockSafety {
return null; return null;
} }
/** /*
* If someone has a better way of this... Please either tell us, or submit a pull request! * If someone has a better way of this... Please either tell us, or submit a pull request!
*/ */
private boolean isSolidBlock(Material type) { private boolean isSolidBlock(Material type) {
@ -174,16 +196,23 @@ public class BlockSafety {
return false; return false;
case WATER: case WATER:
return false; return false;
} default:
return true; return true;
} }
}
public boolean isEntitiyOnTrack(Entity e, Location l) { /**
* Checks if an entity would be on track at the specified {@link Location}.
* @param l The {@link Location}.
* @return True if an entity would be on tracks at the specified {@link Location}.
*/
public boolean isEntitiyOnTrack(Location l) {
Material currentBlock = l.getBlock().getType(); Material currentBlock = l.getBlock().getType();
return (currentBlock == Material.POWERED_RAIL || currentBlock == Material.DETECTOR_RAIL || currentBlock == Material.RAILS); return (currentBlock == Material.POWERED_RAIL || currentBlock == Material.DETECTOR_RAIL || currentBlock == Material.RAILS);
} }
public void showDangers(Location l) { // TODO maybe remove this?
private void showDangers(Location l) {
Location actual = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); Location actual = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
Location upOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); Location upOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
@ -204,7 +233,7 @@ public class BlockSafety {
* @param l The {@link Location} * @param l The {@link Location}
* @return Whether there are 2 blocks of water * @return Whether there are 2 blocks of water
*/ */
public boolean hasTwoBlocksofWaterBelow(Location l) { private boolean hasTwoBlocksofWaterBelow(Location l) {
if (l.getBlockY() < 0) { if (l.getBlockY() < 0) {
return false; return false;
} }
@ -221,17 +250,26 @@ public class BlockSafety {
return hasTwoBlocksofWaterBelow(oneBelow); return hasTwoBlocksofWaterBelow(oneBelow);
} }
/**
* Checks if the specified {@link Minecart} can spawn safely.
* @param cart The {@link Minecart}.
* @return True if the minecart can spawn safely.
*/
public boolean canSpawnCartSafely(Minecart cart) { public boolean canSpawnCartSafely(Minecart cart) {
if (this.isBlockAboveAir(cart.getLocation())) { if (this.isBlockAboveAir(cart.getLocation())) {
return true; return true;
} }
if (this.isEntitiyOnTrack(cart, LocationManipulation.getNextBlock(cart))) { if (this.isEntitiyOnTrack(LocationManipulation.getNextBlock(cart))) {
return true; return true;
} }
return false; return false;
} }
/**
* Checks if the specified {@link Vehicle} can spawn safely.
* @param vehicle The {@link Vehicle}.
* @return True if the vehicle can spawn safely.
*/
public boolean canSpawnVehicleSafely(Vehicle vehicle) { public boolean canSpawnVehicleSafely(Vehicle vehicle) {
if (this.isBlockAboveAir(vehicle.getLocation())) { if (this.isBlockAboveAir(vehicle.getLocation())) {
return true; return true;

View File

@ -18,6 +18,9 @@ import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
/**
* The Multiverse debug-logger.
*/
public class DebugLog { public class DebugLog {
private FileHandler fh; private FileHandler fh;
@ -51,13 +54,16 @@ public class DebugLog {
/** /**
* Log a message at a certain level. * Log a message at a certain level.
* *
* @param level * @param level The log-{@link Level}.
* @param msg * @param msg the message.
*/ */
public void log(Level level, String msg) { public void log(Level level, String msg) {
this.log.log(level, msg); this.log.log(level, msg);
} }
/**
* Our log-{@link Formatter}.
*/
private class LogFormatter extends Formatter { private class LogFormatter extends Formatter {
private final SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@ -83,6 +89,9 @@ public class DebugLog {
} }
} }
/**
* Closes this {@link DebugLog}.
*/
public void close() { public void close() {
this.fh.close(); this.fh.close();
} }

View File

@ -9,6 +9,9 @@ package com.onarandombox.MultiverseCore.utils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
/**
* A color-scheme.
*/
public class FancyColorScheme { public class FancyColorScheme {
private ChatColor headerColor; private ChatColor headerColor;
private ChatColor mainColor; private ChatColor mainColor;
@ -22,22 +25,43 @@ public class FancyColorScheme {
this.defContentColor = defaultColor; this.defContentColor = defaultColor;
} }
/**
* Gets the header's {@link ChatColor}.
* @return The header's {@link ChatColor}.
*/
public ChatColor getHeader() { public ChatColor getHeader() {
return this.headerColor; return this.headerColor;
} }
/**
* Gets the main {@link ChatColor}.
* @return The main {@link ChatColor}.
*/
public ChatColor getMain() { public ChatColor getMain() {
return this.mainColor; return this.mainColor;
} }
/**
* Gets the alt {@link ChatColor}.
* @return The alt {@link ChatColor}.
*/
public ChatColor getAlt() { public ChatColor getAlt() {
return this.altColor; return this.altColor;
} }
/**
* Gets the default {@link ChatColor}.
* @return The default {@link ChatColor}.
*/
public ChatColor getDefault() { public ChatColor getDefault() {
return this.defContentColor; return this.defContentColor;
} }
/**
* Gets either the main or the alt {@link ChatColor}.
* @param main True if the main-color is desired, false to get the alt color.
* @return The desired {@link ChatColor}.
*/
public ChatColor getMain(boolean main) { public ChatColor getMain(boolean main) {
return main ? this.getMain() : this.getAlt(); return main ? this.getMain() : this.getAlt();
} }

View File

@ -9,23 +9,30 @@ package com.onarandombox.MultiverseCore.utils;
import com.onarandombox.MultiverseCore.api.FancyText; import com.onarandombox.MultiverseCore.api.FancyText;
/**
* A colored text-header.
*/
public class FancyHeader implements FancyText { public class FancyHeader implements FancyText {
private FancyColorScheme colors; private FancyColorScheme colors;
private String text; private StringBuilder text;
public FancyHeader(String text, FancyColorScheme scheme) { public FancyHeader(String text, FancyColorScheme scheme) {
this.colors = scheme; this.colors = scheme;
this.text = text; this.text = new StringBuilder(text);
} }
@Override @Override
public String getFancyText() { public String getFancyText() {
return colors.getHeader() + "--- " + text + colors.getHeader() + " ---"; return String.format("%s--- %s%s ---", colors.getHeader(), text.toString(), colors.getHeader());
} }
/**
* Appends text to this {@link FancyHeader}.
* @param string The text to append.
*/
public void appendText(String string) { public void appendText(String string) {
this.text += string; this.text.append(string);
} }
} }

View File

@ -9,6 +9,9 @@ package com.onarandombox.MultiverseCore.utils;
import com.onarandombox.MultiverseCore.api.FancyText; import com.onarandombox.MultiverseCore.api.FancyText;
/**
* A colored text-message.
*/
public class FancyMessage implements FancyText { public class FancyMessage implements FancyText {
private String title; private String title;
private String message; private String message;
@ -27,10 +30,16 @@ public class FancyMessage implements FancyText {
this.colors = scheme; this.colors = scheme;
} }
/**
* Makes this {@link FancyMessage} use the main-color.
*/
public void setColorMain() { public void setColorMain() {
this.main = true; this.main = true;
} }
/**
* Makes this {@link FancyMessage} use the alt-color.
*/
public void setColorAlt() { public void setColorAlt() {
this.main = false; this.main = false;
} }
@ -40,10 +49,18 @@ public class FancyMessage implements FancyText {
return this.colors.getMain(this.main) + this.title + this.colors.getDefault() + message; return this.colors.getMain(this.main) + this.title + this.colors.getDefault() + message;
} }
/**
* Specifies whether this {@link FancyMessage} should use the alt-color.
* @param altColor Whether this {@link FancyMessage} should use the alt-color.
*/
public void setAltColor(boolean altColor) { public void setAltColor(boolean altColor) {
this.main = !altColor; this.main = !altColor;
} }
/**
* Specifies whether this {@link FancyMessage} should use the main-color.
* @param mainColor Whether this {@link FancyMessage} should use the main-color.
*/
public void setMainColor(boolean mainColor) { public void setMainColor(boolean mainColor) {
this.main = mainColor; this.main = mainColor;
} }

View File

@ -9,18 +9,19 @@ package com.onarandombox.MultiverseCore.utils;
import java.io.File; import java.io.File;
/**
* File-utilities.
*/
public class FileUtils { public class FileUtils {
protected FileUtils() protected FileUtils() {
{
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/* /**
* Delete a folder Courtesy of: lithium3141 * Used to delete a folder.
* *
* @param file The folder to delete * @param file The folder to delete.
* * @return true if the folder was successfully deleted.
* @return true if success
*/ */
public static boolean deleteFolder(File file) { public static boolean deleteFolder(File file) {
if (file.exists()) { if (file.exists()) {

View File

@ -15,16 +15,20 @@ import org.bukkit.entity.Vehicle;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Formatter; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* Utility class to manipulate locations.
*/
public class LocationManipulation { public class LocationManipulation {
private LocationManipulation() { } private LocationManipulation() { }
private static Map<String, Integer> orientationInts = new HashMap<String, Integer>(); private static Map<String, Integer> orientationInts = new HashMap<String, Integer>();
static { static {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
orientationInts.put("n", 180); orientationInts.put("n", 180);
orientationInts.put("ne", 225); orientationInts.put("ne", 225);
orientationInts.put("e", 270); orientationInts.put("e", 270);
@ -33,6 +37,10 @@ public class LocationManipulation {
orientationInts.put("sw", 45); orientationInts.put("sw", 45);
orientationInts.put("w", 90); orientationInts.put("w", 90);
orientationInts.put("nw", 135); orientationInts.put("nw", 135);
// "freeze" the map:
orientationInts = Collections.unmodifiableMap(orientationInts);
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
} }
/** /**
@ -49,10 +57,21 @@ public class LocationManipulation {
if (location == null) { if (location == null) {
return ""; return "";
} }
StringBuilder l = new StringBuilder(); return String.format("%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(),
Formatter formatter = new Formatter(l); location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
formatter.format("%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); }
return formatter.toString();
/**
* This method simply does some rounding, rather than forcing a call to the server to get the blockdata.
*
* @param l The location to round to the block location
* @return A rounded location.
*/
public static Location getBlockLocation(Location l) {
l.setX(l.getBlockX());
l.setY(l.getBlockY());
l.setZ(l.getBlockZ());
return l;
} }
/** /**
@ -75,7 +94,7 @@ public class LocationManipulation {
// Split the whole string, format is: // Split the whole string, format is:
// {'world', 'x,y,z'[, 'pitch', 'yaw']} // {'world', 'x,y,z'[, 'pitch', 'yaw']}
String[] split = locationString.split(":"); String[] split = locationString.split(":");
if (split.length < 2 || split.length > 4) { if (split.length < 2 || split.length > 4) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
return null; return null;
} }
// Split the xyz string, format is: // Split the xyz string, format is:
@ -97,7 +116,7 @@ public class LocationManipulation {
if (split.length >= 3) { if (split.length >= 3) {
yaw = (float) Double.parseDouble(split[2]); yaw = (float) Double.parseDouble(split[2]);
} }
if (split.length == 4) { if (split.length == 4) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
pitch = (float) Double.parseDouble(split[3]); pitch = (float) Double.parseDouble(split[3]);
} }
return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch); return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch);
@ -154,6 +173,7 @@ public class LocationManipulation {
* @return The NESW Direction * @return The NESW Direction
*/ */
public static String getDirection(Location location) { public static String getDirection(Location location) {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
double r = (location.getYaw() % 360) + 180; double r = (location.getYaw() % 360) + 180;
// Remember, these numbers are every 45 degrees with a 22.5 offset, to detect boundaries. // Remember, these numbers are every 45 degrees with a 22.5 offset, to detect boundaries.
String dir; String dir;
@ -175,6 +195,7 @@ public class LocationManipulation {
dir = "nw"; dir = "nw";
else else
dir = "n"; dir = "n";
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
return dir; return dir;
} }

Some files were not shown because too many files have changed in this diff Show More