* This API contains a bunch of useful things you can get out of Multiverse in general! */ public interface Core { diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java index b0ac0b44..fd0f6cce 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java @@ -21,7 +21,7 @@ import org.bukkit.util.Vector; public interface MVDestination { /** * Returns the identifier or prefix that is required for this destination. - *
+ ** Portals have a prefix of "p" for example and OpenWarp (third party plugin) uses "ow". This is derived from a * hash and cannot have duplicate values. Read that as your plugin cannot use 'p' because it's already used. * Please check the wiki when adding a custom destination! @@ -32,7 +32,7 @@ public interface MVDestination { /** * Allows you to determine if a Destination is valid for the type it thinks it is. - *
+ ** An example of this would be the exact destination. A valid string would be: e:0,0,0 where an invalid one would * be e:1:2:3. The first string would return true the second would return false. This is simply a convenience * method @@ -48,11 +48,11 @@ public interface MVDestination { /** * Returns the location a specific entity will spawn at. - *
+ ** To just retrieve the location as it is stored you can just pass null, but be warned some destinations may return * null back to you if you do this. It is always safer to pass an actual entity. This is used so things like * minecarts can be teleported. - *
+ ** Do not forget to use {@link #getVelocity()} as destinations can use this too! * * @param entity The entity to be teleported. @@ -63,7 +63,7 @@ public interface MVDestination { /** * Returns the velocity vector for this destination. - *
+ ** Plugins wishing to fully support MVDestinations MUST implement this. * * @return A vector representing the speed/direction the player should travel when arriving @@ -72,7 +72,7 @@ public interface MVDestination { /** * Sets the destination string. - *
+ ** This should be used when you want to tell this destination object about a change in where it should take people. * The destination param should be match the result from {@link #getIdentifier()}. A valid example would be that if * {@link #getIdentifier()} returned "ow" our destination string could be "ow:TownCenter" but could not be @@ -85,7 +85,7 @@ public interface MVDestination { /** * Returns true if the destination is valid and players will be taken to it. - *
+ ** Even if destinations are in the correct format (p:MyPortal) MyPortal may not exist, and therefore this would * return false. * @@ -95,7 +95,7 @@ public interface MVDestination { /** * Gives you a general friendly description of the type of destination. - *
+ ** For example, the PlayerDestination sets this to "Player". You can use this to show where a player will be taken. * * @return A friendly string description of the type of destination. @@ -104,7 +104,7 @@ public interface MVDestination { /** * Gives you a specific name of the destination. - *
+ ** For example, the PlayerDestination sets this to The Player's Name. * * @return A friendly string stating the name of the destination. @@ -114,7 +114,7 @@ public interface MVDestination { /** * Returns a string that can easily be saved in the config that contains all the details needed to rebuild this * destination. - *
+ ** ex: e:0,0,0:50:50 * * @return The savable config string. @@ -123,9 +123,9 @@ public interface MVDestination { /** * Returns the permissions string required to go here. - *
+ ** ex: multiverse.access.world - *
+ ** NOTE: This is NOT the permission to use the teleport command. * * @return the permissions string required to go here. @@ -134,7 +134,7 @@ public interface MVDestination { /** * Should the Multiverse SafeTeleporter be used? - *
+ ** If not, MV will blindly take people to the location specified. * * @return True if the SafeTeleporter will be used, false if not. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java index 52c77702..086e01a1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java @@ -19,7 +19,7 @@ import java.util.List; /** * Multiverse 2 World Manager API - *
+ ** This API contains all of the world managing * functions that your heart desires! */ @@ -142,7 +142,7 @@ public interface MVWorldManager { /** * Loads the Worlds & Settings for any worlds that bukkit loaded before us. - *
+ ** This way people will _always_ have some worlds in the list. */ public void loadDefaultWorlds(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index e4915aff..fb7d1a7c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -17,7 +17,7 @@ import java.util.List; /** * The API for a Multiverse Handled World. - *
+ *
* Currently INCOMPLETE
*/
public interface MultiverseWorld {
@@ -48,8 +48,10 @@ public interface MultiverseWorld {
* @param property The name of a world property to get.
* @return A valid MVWorldProperty.
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
+ * @deprecated Use {@link #getProperty(String, Class)} instead
*/
- public MVConfigProperty getProperty(String property) throws PropertyDoesNotExistException;
+ @Deprecated
+ public MVConfigProperty> getProperty(String property) throws PropertyDoesNotExistException;
/**
* Gets the string representation of a property.
@@ -61,6 +63,17 @@ public interface MultiverseWorld {
*/
public String getPropertyValue(String property) throws PropertyDoesNotExistException;
+ /**
+ * Gets the actual MVConfigProperty from this world.
+ * It will throw a PropertyDoesNotExistException if the property is not found.
+ *
+ * @param property The name of a world property to get.
+ * @param expected The type of the expected property. Use Object.class if this doesn't matter for you.
+ * @return A valid MVWorldProperty.
+ * @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
+ */
+ public
* Note: This will ONLY take effect once the world is unloaded/reloaded.
*
* @param environment A {@link org.bukkit.World.Environment}.
@@ -127,7 +140,7 @@ public interface MultiverseWorld {
/**
* Gets the alias of this world.
- *
* This alias allows users to have a world named "world" but show up in the list as "FernIsland"
*
* @return The alias of the world as a String.
@@ -472,7 +485,7 @@ public interface MultiverseWorld {
/**
* Sets whether or not Multiverse should auto-load this world.
- *
* True is default.
*
* @param autoLoad True if multiverse should autoload this world the spawn, false if not.
@@ -489,7 +502,7 @@ public interface MultiverseWorld {
/**
* Sets whether or not a player who dies in this world will respawn in their
* bed or follow the normal respawn pattern.
- *
* True is default.
*
* @param autoLoad True if players dying in this world respawn at their bed.
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java
index 0283eb27..9b990d3b 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java
@@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
-import com.onarandombox.MultiverseCore.utils.WorldManager;
import com.pneumaticraft.commandhandler.CommandHandler;
import org.bukkit.ChatColor;
import org.bukkit.World.Environment;
@@ -47,7 +46,7 @@ public class CreateCommand extends MultiverseCommand {
return;
}
String worldName = args.get(0);
- File worldFile = new File(this.plugin.getServerFolder(), worldName);
+ File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
String env = args.get(1);
String seed = CommandHandler.getFlag("-s", args);
String generator = CommandHandler.getFlag("-g", args);
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java
index e0dbb524..1edf1828 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java
@@ -106,7 +106,7 @@ public class ImportCommand extends MultiverseCommand {
this.showHelp(sender);
return;
}
- File worldFile = new File(this.plugin.getServerFolder(), worldName);
+ File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
if (this.worldManager.isMVWorld(worldName) && worldFile.exists()) {
sender.sendMessage(ChatColor.RED + "Multiverse already knows about this world!");
return;
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java
index 657b2c09..ee58368d 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java
@@ -9,7 +9,8 @@ package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
-import com.pneumaticraft.commandhandler.Command;
+import com.onarandombox.MultiverseCore.localization.MessageProvider;
+import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
import org.bukkit.ChatColor;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
@@ -21,15 +22,18 @@ import java.util.List;
public class ListCommand extends PaginatedCoreCommand
* If it is cancled, no change will happen.
- *
* 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()
*/
diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java
index 339df8a5..497adb9f 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java
@@ -11,9 +11,6 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.utils.PermissionTools;
-import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
-import org.bukkit.Location;
-import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.*;
import org.bukkit.event.entity.*;
diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java
index 6598e020..f5389abd 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java
@@ -173,10 +173,7 @@ public class MVPlayerListener extends PlayerListener {
// 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) {
- System.out.println("Found a new location!");
event.setFrom(newloc);
- } else {
- System.out.println("Did NOT find a new location!");
}
}
// Wait for the adjust, then return!
diff --git a/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java b/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java
index 0a3ea57e..dc97c136 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java
@@ -4,7 +4,15 @@ package com.onarandombox.MultiverseCore.localization;
* An enum containing all messages/strings used by Multiverse.
*/
public enum MultiverseMessage {
- TEST_STRING("a test-string from the enum");
+ TEST_STRING("a test-string from the enum"),
+ LIST_NAME("World Listing"),
+ LIST_TITLE("Multiverse World List"),
+ LIST_DESC("Displays a listing of all worlds that you can enter."),
+ LIST_NO_MATCH("No worlds matched your filter:"),
+ GENERIC_SORRY("Sorry..."),
+ GENERIC_OF("of"),
+ GENERIC_PAGE("Page"),
+ GENERIC_UNLOADED("UNLOADED");
private final String def;
diff --git a/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java b/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java
index c4a1dece..bc35bedc 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/localization/SimpleMessageProvider.java
@@ -143,7 +143,6 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider {
public void setLocale(Locale locale) {
if (locale == null)
throw new IllegalArgumentException("Can't set locale to null!");
-
try {
maybeLoadLocale(locale);
} catch (LocalizationLoadingException e) {
diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java
index 450fb6c1..9b325cbc 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java
@@ -42,7 +42,7 @@ public class AnchorManager {
Set
+ * WORLD:X,Y,Z:yaw:pitch
+ *
+ * The corresponding String2Loc function is {@link #stringToLocation}
*
- * @param location
- * @return
+ * @param location The Location to save.
+ * @return The location as a string in this format: WORLD:x,y,z:yaw:pitch
*/
public static String locationToString(Location location) {
if (location == null) {
return "";
}
StringBuilder l = new StringBuilder();
- l.append(location.getWorld().getName() + ":");
- l.append(location.getBlockX() + ",");
- l.append(location.getBlockY() + ",");
- l.append(location.getBlockZ() + ":");
- l.append(location.getYaw() + ":");
- l.append(location.getPitch());
- return l.toString();
+ Formatter formatter = new Formatter(l);
+ formatter.format("%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
+ return formatter.toString();
}
/**
- * Convert a String to a Location.
+ * Returns a new location from a given string. The format is as follows:
+ *
+ * WORLD:X,Y,Z:yaw:pitch
+ *
+ * The corresponding Location2String function is {@link #stringToLocation}
*
- * @param world
- * @param xStr
- * @param yStr
- * @param zStr
- * @param yawStr
- * @param pitchStr
- * @return
+ * @param locationString The location represented as a string (WORLD:X,Y,Z:yaw:pitch)
+ * @return A new location defined by the string or null if the string was invalid.
*/
- public Location stringToLocation(World world, String xStr, String yStr, String zStr, String yawStr, String pitchStr) {
- double x = Double.parseDouble(xStr);
- double y = Double.parseDouble(yStr);
- double z = Double.parseDouble(zStr);
- float yaw = Float.valueOf(yawStr);
- float pitch = Float.valueOf(pitchStr);
+ public static Location stringToLocation(String locationString) {
+ //format:
+ //world:x,y,z:pitch:yaw
+ if (locationString == null) {
+ return null;
+ }
- return new Location(world, x, y, z, yaw, pitch);
+ // Split the whole string, format is:
+ // {'world', 'x,y,z'[, 'pitch', 'yaw']}
+ String[] split = locationString.split(":");
+ if (split.length < 2 || split.length > 4) {
+ return null;
+ }
+ // Split the xyz string, format is:
+ // {'x', 'y', 'z'}
+ String[] xyzsplit = split[1].split(",");
+ if (xyzsplit.length != 3) {
+ return null;
+ }
+
+ // Verify the world is valid
+ World w = Bukkit.getWorld(split[0]);
+ if (w == null) {
+ return null;
+ }
+
+ try {
+ float pitch = 0;
+ float yaw = 0;
+ if (split.length >= 3) {
+ yaw = (float) Double.parseDouble(split[2]);
+ }
+ if (split.length == 4) {
+ pitch = (float) Double.parseDouble(split[3]);
+ }
+ return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch);
+ } catch (NumberFormatException e) {
+ return null;
+ }
}
/**
* Returns a colored string with the coords
*
- * @param l
- * @return
+ * @param l The {@link Location}
+ * @return The {@link String}
*/
public static String strCoords(Location l) {
String result = "";
@@ -97,8 +127,8 @@ public class LocationManipulation {
/**
* Converts a location to a printable readable formatted string including pitch/yaw
*
- * @param l
- * @return
+ * @param l The {@link Location}
+ * @return The {@link String}
*/
public static String strCoordsRaw(Location l) {
String result = "";
@@ -116,8 +146,8 @@ public class LocationManipulation {
/**
* Return the NESW Direction a Location is facing.
*
- * @param location
- * @return
+ * @param location The {@link Location}
+ * @return The NESW Direction
*/
public static String getDirection(Location location) {
double r = (location.getYaw() % 360) + 180;
@@ -146,10 +176,10 @@ public class LocationManipulation {
}
/**
- * Returns the float yaw position for the given cardianl direction
+ * Returns the float yaw position for the given cardinal direction
*
- * @param orientation
- * @return
+ * @param orientation The cardinal direction
+ * @return The yaw
*/
public static float getYaw(String orientation) {
if (orientation == null) {
@@ -164,8 +194,8 @@ public class LocationManipulation {
/**
* Returns a speed float from a given vector.
*
- * @param v
- * @return
+ * @param v The {@link Vector}
+ * @return The speed
*/
public static float getSpeed(Vector v) {
return (float) Math.sqrt(v.getX() * v.getX() + v.getZ() * v.getZ());
@@ -177,9 +207,9 @@ public class LocationManipulation {
/**
* Returns a translated vector from the given direction
*
- * @param v
- * @param direction
- * @return
+ * @param v The old {@link Vector}
+ * @param direction The new direction
+ * @return The translated {@link Vector}
*/
public static Vector getTranslatedVector(Vector v, String direction) {
if (direction == null) {
@@ -209,10 +239,10 @@ public class LocationManipulation {
}
/**
- * Returns the next Location that an entity is traveling at
+ * Returns the next Location that a {@link Vehicle} is traveling at
*
- * @param v
- * @return
+ * @param v The {@link Vehicle}
+ * @return The {@link Location}
*/
public static Location getNextBlock(Vehicle v) {
Vector vector = v.getVelocity();
@@ -221,43 +251,4 @@ public class LocationManipulation {
int z = vector.getZ() < 0 ? vector.getZ() == 0 ? 0 : -1 : 1;
return location.add(x, 0, z);
}
-
- public static Location getLocationFromString(String value) {
- //format:
- //world:x,y,z:pitch:yaw
- if (value == null) {
- return null;
- }
-
- // Split the whole string, format is:
- // {'world', 'x,y,z'[, 'pitch', 'yaw']}
- String[] split = value.split(":");
- if (split.length < 2 || split.length > 4) {
- return null;
- }
- // Split the xyz string, format is:
- // {'x', 'y', 'z'}
- String[] xyzsplit = split[1].split(",");
- if (xyzsplit.length != 3) {
- return null;
- }
-
- // Verify the world is valid
- World w = Bukkit.getWorld(split[0]);
- if (w == null) {
- return null;
- }
-
- try {
- if (split.length == 2) {
- return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]));
- }
- if (split.length == 3) {
- return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), (float) Double.parseDouble(split[2]), (float) 0.0);
- }
- return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), (float) Double.parseDouble(split[2]), (float) Double.parseDouble(split[3]));
- } catch (NumberFormatException e) {
- return null;
- }
- }
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java
index 4c02ebbc..072e6762 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java
@@ -39,9 +39,9 @@ public class MVPermissions implements PermissionsInterface {
/**
* Check if a Player can teleport to the Destination world from there current world.
*
- * @param p The player to check.
- * @param w
- * @return
+ * @param p The {@link Player} to check.
+ * @param w The {@link MultiverseWorld} the player wants to teleport to.
+ * @return Whether the player can teleport to the given {@link MultiverseWorld}.
*/
public boolean canTravelFromWorld(Player p, MultiverseWorld w) {
List
* The return is a little backwards, and will return a value safe for event.setCancelled.
*
* @param fromWorld The MultiverseWorld they are in.
diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java b/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java
index edb464ad..8ed7bd99 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java
@@ -85,11 +85,10 @@ public class UpdateChecker {
}
/**
- * Convert the given Version String to a Normalised Version String so we can compare it.
+ * Convert the given Version String to a Normalized Version String so we can compare it.
*
- * @param version
- *
- * @return
+ * @param version The version string
+ * @return The normalized version string
*/
public static String normalisedVersion(String version) {
return normalisedVersion(version, ".", 4);
diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java
index 042b679b..1dae09c4 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java
@@ -8,7 +8,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PastebinPasteService implements PasteService {
diff --git a/src/main/resources/localization/en.yml b/src/main/resources/localization/en.yml
index ab9b410f..892c1e65 100644
--- a/src/main/resources/localization/en.yml
+++ b/src/main/resources/localization/en.yml
@@ -1 +1,17 @@
-TEST_STRING: a test-string from the resource
\ No newline at end of file
+TEST_STRING: a test-string from the resource
+
+# Generic Strings
+GENERIC_SORRY: Sorry...
+GENERIC_PAGE: Page
+GENERIC_OF: of
+GENERIC_UNLOADED: UNLOADED
+
+# Commands
+
+# List Command
+LIST_NAME: World Listing
+LIST_DESC: Displays a listing of all worlds that you can enter.
+
+LIST_TITLE: Multiverse World List
+LIST_NO_MATCH: No worlds matched your filter:
+
diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestLocalization.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestLocalization.java
index a4b46c1a..f2b7c7a7 100644
--- a/src/test/java/com/onarandombox/MultiverseCore/test/TestLocalization.java
+++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestLocalization.java
@@ -1,3 +1,10 @@
+/******************************************************************************
+ * Multiverse 2 Copyright (c) the Multiverse Team 2011. *
+ * Multiverse 2 is licensed under the BSD License. *
+ * For more information please check the README.md file included *
+ * with this project. *
+ ******************************************************************************/
+
package com.onarandombox.MultiverseCore.test;
import static org.junit.Assert.*;
diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java
index 31536bba..5076d8f5 100644
--- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java
+++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldStuff.java
@@ -7,15 +7,13 @@
package com.onarandombox.MultiverseCore.test;
-import static junit.framework.Assert.*;
-import static org.mockito.Mockito.*;
-
-import java.io.File;
-
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.Server;
-import org.bukkit.WorldCreator;
+import com.onarandombox.MultiverseCore.MultiverseCore;
+import com.onarandombox.MultiverseCore.api.MultiverseWorld;
+import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
+import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
+import com.onarandombox.MultiverseCore.test.utils.WorldCreatorMatcher;
+import com.onarandombox.MultiverseCore.utils.WorldManager;
+import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission;
@@ -30,18 +28,18 @@ import org.mockito.internal.verification.VerificationModeFactory;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import com.onarandombox.MultiverseCore.MultiverseCore;
-import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
-import com.onarandombox.MultiverseCore.test.utils.WorldCreatorMatcher;
-import com.onarandombox.MultiverseCore.utils.WorldManager;
+import java.io.File;
+
+import static junit.framework.Assert.*;
+import static org.mockito.Mockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, WorldManager.class })
public class TestWorldStuff {
- TestInstanceCreator creator;
- Server mockServer;
- CommandSender mockCommandSender;
+ private TestInstanceCreator creator;
+ private Server mockServer;
+ private CommandSender mockCommandSender;
@Before
public void setUp() throws Exception {
@@ -76,7 +74,7 @@ public class TestWorldStuff {
// Initialize a fake command
Command mockCommand = mock(Command.class);
when(mockCommand.getName()).thenReturn("mv");
- String[] normalArgs = new String[] { "import", "world", "normal" };
+ String[] normalArgs = new String[]{ "import", "world", "normal" };
// Ensure we have a fresh copy of MV, 0 worlds.
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
@@ -109,21 +107,21 @@ public class TestWorldStuff {
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Import the first world.
- String[] normalArgs = new String[] { "import", "world", "normal" };
+ String[] normalArgs = new String[]{ "import", "world", "normal" };
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
// We should now have one world imported!
assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Import the second world.
- String[] netherArgs = new String[] { "import", "world_nether", "nether" };
+ String[] netherArgs = new String[]{ "import", "world_nether", "nether" };
plugin.onCommand(mockCommandSender, mockCommand, "", netherArgs);
// We should now have 2 worlds imported!
assertEquals(2, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Import the third world.
- String[] skyArgs = new String[] { "import", "world_skylands", "end" };
+ String[] skyArgs = new String[]{ "import", "world_the_end", "end" };
plugin.onCommand(mockCommandSender, mockCommand, "", skyArgs);
// We should now have 2 worlds imported!
@@ -132,7 +130,7 @@ public class TestWorldStuff {
// Verify that the commandSender has been called 3 times.
verify(mockCommandSender).sendMessage("Starting import of world 'world'...");
verify(mockCommandSender).sendMessage("Starting import of world 'world_nether'...");
- verify(mockCommandSender).sendMessage("Starting import of world 'world_skylands'...");
+ verify(mockCommandSender).sendMessage("Starting import of world 'world_the_end'...");
verify(mockCommandSender, VerificationModeFactory.times(3)).sendMessage("Complete!");
}
@@ -155,7 +153,7 @@ public class TestWorldStuff {
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Create the world
- String[] normalArgs = new String[] { "create", "newworld", "normal" };
+ String[] normalArgs = new String[]{ "create", "newworld", "normal" };
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
// We should now have one world!
@@ -168,4 +166,56 @@ public class TestWorldStuff {
WorldCreatorMatcher matcher = new WorldCreatorMatcher(new WorldCreator("newworld"));
verify(mockServer).createWorld(Matchers.argThat(matcher));
}
+
+ @Test
+ public void testModifyGameMode() {
+ // Pull a core instance from the server.
+ Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
+ Command mockCommand = mock(Command.class);
+ when(mockCommand.getName()).thenReturn("mv");
+
+ // Ensure that there are no worlds imported. This is a fresh setup.
+ assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
+ this.createInitialWorlds(plugin, mockCommand);
+
+ // Ensure that the default worlds have been created.
+ assertEquals(3, creator.getCore().getMVWorldManager().getMVWorlds().size());
+ MultiverseWorld mainWorld = creator.getCore().getMVWorldManager().getMVWorld("world");
+
+ // Ensure that the default mode was normal.
+ assertEquals(GameMode.SURVIVAL, mainWorld.getGameMode());
+
+ // Set the mode to creative in world.
+ plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "mode", "creative", "world" });
+ verify(mockCommandSender).sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + "mode" + ChatColor.WHITE + " was set to " + ChatColor.GREEN + "creative");
+ // Ensure the world is now a creative world
+ assertEquals(GameMode.CREATIVE, mainWorld.getGameMode());
+
+ // More tests, with alternate syntax.
+ plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "gamemode", "0", "world" });
+ verify(mockCommandSender).sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + "gamemode" + ChatColor.WHITE + " was set to " + ChatColor.GREEN + "0");
+ assertEquals(GameMode.SURVIVAL, mainWorld.getGameMode());
+
+ // Now fail one.
+ plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "mode", "fish", "world" });
+ try {
+ verify(mockCommandSender).sendMessage(mainWorld.getProperty("mode", Object.class).getHelp());
+ } catch (PropertyDoesNotExistException e) {
+ fail("Mode property did not exist.");
+ }
+
+ plugin.onCommand(mockCommandSender, mockCommand, "", new String[]{ "modify", "set", "blah", "fish", "world" });
+ verify(mockCommandSender).sendMessage(ChatColor.RED + "Sorry, You can't set: '"+ChatColor.GRAY+ "blah" + ChatColor.RED + "'");
+
+ }
+
+ private void createInitialWorlds(Plugin plugin, Command command) {
+ plugin.onCommand(mockCommandSender, command, "", new String[]{ "import", "world", "normal" });
+ plugin.onCommand(mockCommandSender, command, "", new String[]{ "import", "world_nether", "nether" });
+ plugin.onCommand(mockCommandSender, command, "", new String[]{ "import", "world_the_end", "end" });
+ verify(mockCommandSender).sendMessage("Starting import of world 'world'...");
+ verify(mockCommandSender).sendMessage("Starting import of world 'world_nether'...");
+ verify(mockCommandSender).sendMessage("Starting import of world 'world_the_end'...");
+ verify(mockCommandSender, times(3)).sendMessage("Complete!");
+ }
}
diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java
index 3eb3b18d..9519f29b 100644
--- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java
+++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java
@@ -263,7 +263,7 @@ public class MockBlock implements Block{
/**
* Captures the current state of this block. You may then cast that state
* into any accepted type, such as Furnace or Sign.
- *
* The returned object will never be updated, and you are not guaranteed that
* (for example) a sign is still a sign after you capture its state.
*
@@ -352,7 +352,7 @@ public class MockBlock implements Block{
/**
* Checks if this block is empty.
- *
* A block is considered empty when {@link #getType()} returns {@link org.bukkit.Material#AIR}.
*
* @return true if this block is empty
@@ -364,7 +364,7 @@ public class MockBlock implements Block{
/**
* Checks if this block is liquid.
- *
* A block is considered liquid when {@link #getType()} returns {@link org.bukkit.Material#WATER}, {@link
* org.bukkit.Material#STATIONARY_WATER}, {@link org.bukkit.Material#LAVA} or {@link
* org.bukkit.Material#STATIONARY_LAVA}.
diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java
index 341b7045..c7089599 100644
--- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java
+++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java
@@ -7,9 +7,6 @@
package com.onarandombox.MultiverseCore.test.utils;
-import java.util.Set;
-import java.util.logging.Logger;
-
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@@ -18,6 +15,9 @@ import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
+import java.util.Set;
+import java.util.logging.Logger;
+
public class TestCommandSender implements CommandSender {
private Server server;
@@ -67,7 +67,6 @@ public class TestCommandSender implements CommandSender {
* Checks if this object contains an override for the specified permission, by fully qualified name
*
* @param name Name of the permission
- *
* @return true if the permission is set, otherwise false
*/
@Override
@@ -79,7 +78,6 @@ public class TestCommandSender implements CommandSender {
* Checks if this object contains an override for the specified {@link org.bukkit.permissions.Permission}
*
* @param perm Permission to check
- *
* @return true if the permission is set, otherwise false
*/
@Override
@@ -89,11 +87,10 @@ public class TestCommandSender implements CommandSender {
/**
* Gets the value of the specified permission, if set.
- *
* If a permission override is not set on this object, the default value of the permission will be returned.
*
* @param name Name of the permission
- *
* @return Value of the permission
*/
@Override
@@ -103,11 +100,10 @@ public class TestCommandSender implements CommandSender {
/**
* Gets the value of the specified permission, if set.
- *
* If a permission override is not set on this object, the default value of the permission will be returned
*
* @param perm Permission to get
- *
* @return Value of the permission
*/
@Override
@@ -121,7 +117,6 @@ public class TestCommandSender implements CommandSender {
* @param plugin Plugin responsible for this attachment, may not be null or disabled
* @param name Name of the permission to attach
* @param value Value of the permission
- *
* @return The PermissionAttachment that was just created
*/
@Override
@@ -133,7 +128,6 @@ public class TestCommandSender implements CommandSender {
* Adds a new empty {@link org.bukkit.permissions.PermissionAttachment} to this object
*
* @param plugin Plugin responsible for this attachment, may not be null or disabled
- *
* @return The PermissionAttachment that was just created
*/
@Override
@@ -149,7 +143,6 @@ public class TestCommandSender implements CommandSender {
* @param name Name of the permission to attach
* @param value Value of the permission
* @param ticks Amount of ticks to automatically remove this attachment after
- *
* @return The PermissionAttachment that was just created
*/
@Override
@@ -162,7 +155,6 @@ public class TestCommandSender implements CommandSender {
*
* @param plugin Plugin responsible for this attachment, may not be null or disabled
* @param ticks Amount of ticks to automatically remove this attachment after
- *
* @return The PermissionAttachment that was just created
*/
@Override
@@ -174,7 +166,6 @@ public class TestCommandSender implements CommandSender {
* Removes the given {@link org.bukkit.permissions.PermissionAttachment} from this object
*
* @param attachment Attachment to remove
- *
* @throws IllegalArgumentException Thrown when the specified attachment isn't part of this object
*/
@Override
@@ -183,7 +174,7 @@ public class TestCommandSender implements CommandSender {
/**
* Recalculates the permissions for this object, if the attachments have changed values.
- *
* This should very rarely need to be called from a plugin.
*/
@Override
diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java
index 3463ebb7..f936c19c 100644
--- a/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java
+++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java
@@ -46,6 +46,7 @@ public class TestInstanceCreator {
public static final File pluginDirectory = new File("bin/test/server/plugins/coretest");
public static final File serverDirectory = new File("bin/test/server");
+ public static final File worldsDirectory = new File("bin/test/server");
public boolean setUp() {
try {
@@ -81,7 +82,7 @@ public class TestInstanceCreator {
File worldNetherFile = new File(core.getServerFolder(), "world_nether");
Util.log("Creating world-folder: " + worldNetherFile.getAbsolutePath());
worldNetherFile.mkdirs();
- File worldSkylandsFile = new File(core.getServerFolder(), "world_skylands");
+ File worldSkylandsFile = new File(core.getServerFolder(), "world_the_end");
Util.log("Creating world-folder: " + worldSkylandsFile.getAbsolutePath());
worldSkylandsFile.mkdirs();
@@ -90,6 +91,7 @@ public class TestInstanceCreator {
when(mockServer.getName()).thenReturn("TestBukkit");
Logger.getLogger("Minecraft").setParent(Util.logger);
when(mockServer.getLogger()).thenReturn(Util.logger);
+ when(mockServer.getWorldContainer()).thenReturn(worldsDirectory);
// Give the server some worlds
when(mockServer.getWorld(anyString())).thenAnswer(new Answer