diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java
index a7806c34..c6292ffd 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java
@@ -7,6 +7,7 @@
package com.onarandombox.MultiverseCore;
+import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.configuration.ConfigPropertyFactory;
import com.onarandombox.MultiverseCore.configuration.MVActiveConfigProperty;
@@ -14,9 +15,7 @@ import com.onarandombox.MultiverseCore.configuration.MVConfigProperty;
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
-import com.onarandombox.MultiverseCore.utils.BlockSafety;
-import com.onarandombox.MultiverseCore.utils.LocationManipulation;
-import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
+import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
@@ -33,7 +32,6 @@ import org.bukkit.permissions.PermissionDefault;
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
@@ -433,7 +431,7 @@ public class MVWorld implements MultiverseWorld {
} else {
this.world.setSpawnFlags(true, this.world.getAllowAnimals());
}
- this.plugin.getMVWorldManager().getWorldPurger().purgeWorld(null, this);
+ this.plugin.getMVWorldManager().getTheWorldPurger().purgeWorld(this);
}
/**
@@ -986,8 +984,8 @@ public class MVWorld implements MultiverseWorld {
// Set the worldspawn to our configspawn
w.setSpawnLocation(configLocation.getBlockX(), configLocation.getBlockY(), configLocation.getBlockZ());
- SafeTTeleporter teleporter = this.plugin.getTeleporter();
- BlockSafety bs = new BlockSafety();
+ SafeTTeleporter teleporter = this.plugin.getSafeTTeleporter();
+ BlockSafety bs = this.plugin.getBlockSafety();
// Verify that location was safe
if (!bs.playerCanSpawnHereSafely(configLocation)) {
if (!this.getAdjustSpawn()) {
@@ -999,7 +997,7 @@ public class MVWorld implements MultiverseWorld {
}
// 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, "Original Location: " + LocationManipulation.strCoordsRaw(spawnLocation));
+ this.plugin.log(Level.WARNING, "Original Location: " + plugin.getLocationManipulation().strCoordsRaw(spawnLocation));
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.
@@ -1008,7 +1006,8 @@ public class MVWorld implements MultiverseWorld {
if (newSpawn != null) {
this.setSpawnLocation(newSpawn);
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: " + plugin.getLocationManipulation().locationToString(configLocation));
} else {
// If it's a standard end world, let's check in a better place:
Location newerSpawn;
@@ -1017,7 +1016,7 @@ public class MVWorld implements MultiverseWorld {
this.setSpawnLocation(newerSpawn);
configLocation = this.getSpawnLocation();
this.plugin.log(Level.INFO, "New Spawn for '" + this.getName()
- + "' is Located at: " + LocationManipulation.locationToString(configLocation));
+ + "' is Located at: " + plugin.getLocationManipulation().locationToString(configLocation));
} else {
this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!");
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java
index 4ad99513..b60e5120 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java
@@ -9,10 +9,14 @@ package com.onarandombox.MultiverseCore;
import com.fernferret.allpay.AllPay;
import com.fernferret.allpay.GenericBank;
+import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.Core;
+import com.onarandombox.MultiverseCore.api.LocationManipulation;
import com.onarandombox.MultiverseCore.api.MVPlugin;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
+import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
+import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.commands.*;
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
import com.onarandombox.MultiverseCore.destination.BedDestination;
@@ -26,14 +30,7 @@ import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
-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.onarandombox.MultiverseCore.utils.*;
import com.pneumaticraft.commandhandler.CommandHandler;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@@ -168,7 +165,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private SpoutInterface spoutInterface = null;
private static final double ALLPAY_VERSION = 5;
private static final double CH_VERSION = 4;
- private MVMessaging messaging;
+ private MultiverseMessaging messaging;
+ private BlockSafety blockSafety;
+ private LocationManipulation locationManipulation;
+ private SafeTTeleporter safeTTeleporter;
private File serverFolder = new File(System.getProperty("user.dir"));
@@ -178,6 +178,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
getDataFolder().mkdirs();
// Setup our Debug Log
debugLog = new DebugLog("Multiverse-Core", getDataFolder() + File.separator + "debug.log");
+ // Setup our BlockSafety
+ this.blockSafety = new SimpleBlockSafety(this);
+ // Setup our LocationManipulation
+ this.locationManipulation = new SimpleLocationManipulation();
+ // Setup our SafeTTeleporter
+ this.safeTTeleporter = new SimpleSafeTTeleporter(this);
}
/**
@@ -375,7 +381,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
* {@inheritDoc}
*/
@Override
- public MVMessaging getMessaging() {
+ public MultiverseMessaging getMessaging() {
return this.messaging;
}
@@ -445,10 +451,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
/**
* {@inheritDoc}
+ *
+ * @deprecated This is deprecated.
*/
@Override
- public SafeTTeleporter getTeleporter() {
- return new SafeTTeleporter(this);
+ @Deprecated
+ public com.onarandombox.MultiverseCore.utils.SafeTTeleporter getTeleporter() {
+ return new com.onarandombox.MultiverseCore.utils.SafeTTeleporter(this);
}
/**
@@ -637,7 +646,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
*/
public void teleportPlayer(CommandSender teleporter, Player p, Location l) {
// This command is the override, and MUST NOT TELEPORT SAFELY
- this.getTeleporter().safelyTeleport(teleporter, p, l, false);
+ this.getSafeTTeleporter().safelyTeleport(teleporter, p, l, false);
}
/**
@@ -779,7 +788,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
}
if (this.worldManager.deleteWorld(name, false)) {
this.worldManager.loadWorlds(false);
- SafeTTeleporter teleporter = this.getTeleporter();
+ SafeTTeleporter teleporter = this.getSafeTTeleporter();
Location newSpawn = this.getServer().getWorld(name).getSpawnLocation();
// Send all players that were in the old world, BACK to it!
for (Player p : ps) {
@@ -798,4 +807,51 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
return this.anchorManager;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BlockSafety getBlockSafety() {
+ return blockSafety;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setBlockSafety(BlockSafety bs) {
+ this.blockSafety = bs;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public LocationManipulation getLocationManipulation() {
+ return locationManipulation;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setLocationManipulation(LocationManipulation locationManipulation) {
+ this.locationManipulation = locationManipulation;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SafeTTeleporter getSafeTTeleporter() {
+ return safeTTeleporter;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setSafeTTeleporter(SafeTTeleporter safeTTeleporter) {
+ this.safeTTeleporter = safeTTeleporter;
+ }
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/BlockSafety.java b/src/main/java/com/onarandombox/MultiverseCore/api/BlockSafety.java
new file mode 100644
index 00000000..db25a17e
--- /dev/null
+++ b/src/main/java/com/onarandombox/MultiverseCore/api/BlockSafety.java
@@ -0,0 +1,72 @@
+package com.onarandombox.MultiverseCore.api;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Minecart;
+import org.bukkit.entity.Vehicle;
+
+/**
+ * Used to get block/location-related information.
+ */
+public interface BlockSafety {
+ /**
+ * 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.
+ */
+ boolean isBlockAboveAir(Location l);
+
+ /**
+ * 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.
+ */
+ boolean playerCanSpawnHereSafely(World world, double x, double y, double z);
+
+ /**
+ * This function checks whether the block at the coordinates given is safe or not by checking for Lava/Fire/Air
+ * etc. This also ensures there is enough space for a player to spawn!
+ *
+ * @param l The {@link Location}
+ * @return Whether the player can spawn safely at the given {@link Location}
+ */
+ boolean playerCanSpawnHereSafely(Location l);
+
+ /**
+ * 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.
+ */
+ Location getTopBlock(Location l);
+
+ /**
+ * 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.
+ */
+ Location getBottomBlock(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}.
+ */
+ boolean isEntitiyOnTrack(Location l);
+
+ /**
+ * Checks if the specified {@link Minecart} can spawn safely.
+ * @param cart The {@link Minecart}.
+ * @return True if the minecart can spawn safely.
+ */
+ boolean canSpawnCartSafely(Minecart cart);
+
+ /**
+ * Checks if the specified {@link Vehicle} can spawn safely.
+ * @param vehicle The {@link Vehicle}.
+ * @return True if the vehicle can spawn safely.
+ */
+ boolean canSpawnVehicleSafely(Vehicle vehicle);
+}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java
index 7eec0ba2..4e1007f9 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java
@@ -46,9 +46,9 @@ public interface Core {
* Gets the Multiverse message system. This allows you to send messages
* to users at specified intervals.
*
- * @return The loaded {@link MVMessaging}.
+ * @return The loaded {@link MultiverseMessaging}.
*/
- MVMessaging getMessaging();
+ MultiverseMessaging getMessaging();
/**
* Gets the {@link MVPlayerSession} for the given player.
@@ -66,8 +66,11 @@ public interface Core {
* safe teleports.
*
* @return A non-null {@link SafeTTeleporter}.
+ *
+ * @deprecated Use {@link #getSafeTTeleporter()} instead.
*/
- SafeTTeleporter getTeleporter();
+ @Deprecated
+ com.onarandombox.MultiverseCore.utils.SafeTTeleporter getTeleporter();
/**
* Multiverse uses an advanced permissions setup, this object
@@ -163,4 +166,53 @@ public interface Core {
* @return The readable authors-{@link String}
*/
String getAuthors();
+
+ /**
+ * Gets the {@link BlockSafety} this {@link Core} is using.
+ * @return The {@link BlockSafety} this {@link Core} is using.
+ * @see BlockSafety
+ * @see SimpleBlockSafety
+ */
+ BlockSafety getBlockSafety();
+
+ /**
+ * Sets the {@link BlockSafety} this {@link Core} is using.
+ * @param blockSafety The new {@link BlockSafety}.
+ * @see BlockSafety
+ * @see SimpleBlockSafety
+ */
+ void setBlockSafety(BlockSafety blockSafety);
+
+ /**
+ * Gets the {@link LocationManipulation} this {@link Core} is using.
+ * @return The {@link LocationManipulation} this {@link Core} is using.
+ * @see LocationManipulation
+ * @see SimpleLocationManipulation
+ */
+ LocationManipulation getLocationManipulation();
+
+ /**
+ * Sets the {@link LocationManipulation} this {@link Core} is using.
+ * @param locationManipulation The new {@link LocationManipulation}.
+ * @see LocationManipulation
+ * @see SimpleLocationManipulation
+ */
+ void setLocationManipulation(LocationManipulation locationManipulation);
+
+ /**
+ * Gets the {@link SafeTTeleporter} this {@link Core} is using.
+ * @return The {@link SafeTTeleporter} this {@link Core} is using.
+ * @see SafeTTeleporter
+ * @see SimpleSafeTTeleporter
+ */
+ SafeTTeleporter getSafeTTeleporter();
+
+ /**
+ * Sets the {@link SafeTTeleporter} this {@link Core} is using.
+ * @param safeTTeleporter The new {@link SafeTTeleporter}.
+ * @see SafeTTeleporter
+ * @see SimpleSafeTTeleporter
+ */
+ void setSafeTTeleporter(SafeTTeleporter safeTTeleporter);
+
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/LocationManipulation.java b/src/main/java/com/onarandombox/MultiverseCore/api/LocationManipulation.java
new file mode 100644
index 00000000..38c5f3f9
--- /dev/null
+++ b/src/main/java/com/onarandombox/MultiverseCore/api/LocationManipulation.java
@@ -0,0 +1,99 @@
+package com.onarandombox.MultiverseCore.api;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Vehicle;
+import org.bukkit.util.Vector;
+
+/**
+ * Used to manipulate locations.
+ */
+public interface LocationManipulation {
+ /**
+ * Convert a Location into a Colon separated string to allow us to store it in text.
+ *
+ * WORLD:X,Y,Z:yaw:pitch
+ *
+ * The corresponding String2Loc function is {@link #stringToLocation}
+ *
+ * @param location The Location to save.
+ * @return The location as a string in this format: WORLD:x,y,z:yaw:pitch
+ */
+ String locationToString(Location location);
+
+ /**
+ * 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.
+ */
+ Location getBlockLocation(Location l);
+
+ /**
+ * 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 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.
+ */
+ Location stringToLocation(String locationString);
+
+ /**
+ * Returns a colored string with the coords.
+ *
+ * @param l The {@link Location}
+ * @return The {@link String}
+ */
+ String strCoords(Location l);
+
+ /**
+ * Converts a location to a printable readable formatted string including pitch/yaw.
+ *
+ * @param l The {@link Location}
+ * @return The {@link String}
+ */
+ String strCoordsRaw(Location l);
+
+ /**
+ * Return the NESW Direction a Location is facing.
+ *
+ * @param location The {@link Location}
+ * @return The NESW Direction
+ */
+ String getDirection(Location location);
+
+ /**
+ * Returns the float yaw position for the given cardinal direction.
+ *
+ * @param orientation The cardinal direction
+ * @return The yaw
+ */
+ float getYaw(String orientation);
+
+ /**
+ * Returns a speed float from a given vector.
+ *
+ * @param v The {@link Vector}
+ * @return The speed
+ */
+ float getSpeed(Vector v);
+
+ /**
+ * Returns a translated vector from the given direction.
+ *
+ * @param v The old {@link Vector}
+ * @param direction The new direction
+ * @return The translated {@link Vector}
+ */
+ Vector getTranslatedVector(Vector v, String direction);
+
+ /**
+ * Returns the next Location that a {@link Vehicle} is traveling at.
+ *
+ * @param v The {@link Vehicle}
+ * @return The {@link Location}
+ */
+ Location getNextBlock(Vehicle v);
+}
\ No newline at end of file
diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java
index 40300ef0..023bf1b6 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java
@@ -8,6 +8,8 @@
package com.onarandombox.MultiverseCore.api;
import com.onarandombox.MultiverseCore.utils.PurgeWorlds;
+import com.onarandombox.MultiverseCore.utils.SimpleWorldPurger;
+
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldType;
@@ -168,9 +170,21 @@ public interface MVWorldManager {
* Return the World Purger.
*
* @return A valid {@link PurgeWorlds}.
+ * @deprecated {@link PurgeWorlds} is deprecated!
*/
+ @Deprecated
PurgeWorlds getWorldPurger();
+ /**
+ * Gets the {@link WorldPurger}.
+ *
+ * TODO: Remove {@link #getWorldPurger()} and replace it with this method.
+ * @return The {@link WorldPurger} this {@link MVWorldManager} is using.
+ * @see WorldPurger
+ * @see SimpleWorldPurger
+ */
+ WorldPurger getTheWorldPurger();
+
/**
* Gets the world players will spawn in on first join.
* Currently this always returns worlds.get(0) from Bukkit.
diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseMessaging.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseMessaging.java
new file mode 100644
index 00000000..ae2bd004
--- /dev/null
+++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseMessaging.java
@@ -0,0 +1,56 @@
+package com.onarandombox.MultiverseCore.api;
+
+import java.util.Collection;
+
+import org.bukkit.command.CommandSender;
+
+/**
+ * Multiverse-messaging.
+ */
+public interface MultiverseMessaging {
+ /**
+ * Sets the message-cooldown.
+ * @param milliseconds The new message-cooldown in milliseconds.
+ */
+ void setCooldown(int milliseconds);
+
+ /**
+ * Sends a message to the specified sender if the cooldown has passed.
+ *
+ * @param sender The person/console to send the message to.
+ * @param message The message to send.
+ * @param ignoreCooldown If true this message will always be sent. Useful for things like menus
+ * @return true if the message was sent, false if not.
+ */
+ boolean sendMessage(CommandSender sender, String message, boolean ignoreCooldown);
+
+ /**
+ * Sends a group of messages to the specified sender if the cooldown has passed.
+ * This method is needed, since sending many messages in quick succession would violate
+ * the cooldown.
+ *
+ * @param sender The person/console to send the message to.
+ * @param messages The messages to send.
+ * @param ignoreCooldown If true these messages will always be sent. Useful for things like menus
+ * @return true if the message was sent, false if not.
+ */
+ boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown);
+
+ /**
+ * Sends a group of messages to the specified sender if the cooldown has passed.
+ * This method is needed, since sending many messages in quick succession would violate
+ * the cooldown.
+ *
+ * @param sender The person/console to send the message to.
+ * @param messages The messages to send.
+ * @param ignoreCooldown If true these messages will always be sent. Useful for things like menus
+ * @return true if the message was sent, false if not.
+ */
+ boolean sendMessages(CommandSender sender, Collection messages, boolean ignoreCooldown);
+
+ /**
+ * Gets the message-cooldown.
+ * @return The message-cooldown.
+ */
+ int getCooldown();
+}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java b/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java
new file mode 100644
index 00000000..a38140e1
--- /dev/null
+++ b/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java
@@ -0,0 +1,71 @@
+package com.onarandombox.MultiverseCore.api;
+
+import org.bukkit.Location;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Entity;
+
+import com.onarandombox.MultiverseCore.enums.TeleportResult;
+
+/**
+ * Used to safely teleport people.
+ */
+public interface SafeTTeleporter {
+
+ /**
+ * Gets the next safe location around the given location.
+ * @param l A {@link Location}.
+ * @return A safe {@link Location}.
+ */
+ Location getSafeLocation(Location l);
+
+ /**
+ * Gets the next safe location around the given location.
+ * @param l A {@link Location}.
+ * @param tolerance The tolerance.
+ * @param radius The radius.
+ * @return A safe {@link Location}.
+ */
+ Location getSafeLocation(Location l, int tolerance, int radius);
+
+ /**
+ * Safely teleport the entity to the MVDestination. This will perform checks to see if the place is safe, and if
+ * it's not, will adjust the final destination accordingly.
+ *
+ * @param teleporter Person who performed the teleport command.
+ * @param teleportee Entity to teleport
+ * @param d Destination to teleport them to
+ * @return true for success, false for failure
+ */
+ TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, MVDestination d);
+
+ /**
+ * Safely teleport the entity to the Location. This may perform checks to
+ * see if the place is safe, and if
+ * it's not, will adjust the final destination accordingly.
+ *
+ * @param teleporter Person who issued the teleport command.
+ * @param teleportee Entity to teleport.
+ * @param location Location to teleport them to.
+ * @param safely Should the destination be checked for safety before teleport?
+ * @return true for success, false for failure.
+ */
+ TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, Location location,
+ boolean safely);
+
+ /**
+ * Returns a safe location for the entity to spawn at.
+ *
+ * @param e The entity to spawn
+ * @param d The MVDestination to take the entity to.
+ * @return A new location to spawn the entity at.
+ */
+ Location getSafeLocation(Entity e, MVDestination d);
+
+ /**
+ * Finds a portal-block next to the specified {@link Location}.
+ * @param l The {@link Location}
+ * @return The next portal-block's {@link Location}.
+ */
+ Location findPortalBlockNextTo(Location l);
+
+}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/WorldPurger.java b/src/main/java/com/onarandombox/MultiverseCore/api/WorldPurger.java
new file mode 100644
index 00000000..6be96bba
--- /dev/null
+++ b/src/main/java/com/onarandombox/MultiverseCore/api/WorldPurger.java
@@ -0,0 +1,49 @@
+package com.onarandombox.MultiverseCore.api;
+
+import java.util.List;
+
+import org.bukkit.command.CommandSender;
+
+/**
+ * Used to remove animals from worlds that don't belong there.
+ */
+public interface WorldPurger {
+
+ /**
+ * Synchronizes the given world with it's settings.
+ *
+ * @param worlds A list of {@link MultiverseWorld}
+ */
+ void purgeWorlds(List worlds);
+
+ /**
+ * Convenience method for {@link #purgeWorld(CommandSender, MultiverseWorld, List, boolean, boolean)} that takes the settings from the world-config.
+ *
+ * @param world The {@link MultiverseWorld}.
+ */
+ void purgeWorld(MultiverseWorld world);
+
+ /**
+ * Clear all animals/monsters that do not belong to a world according to the config.
+ *
+ * @param mvworld The {@link MultiverseWorld}.
+ * @param thingsToKill A {@link List} of animals/monsters to be killed.
+ * @param negateAnimals Whether the monsters in the list should be negated.
+ * @param negateMonsters Whether the animals in the list should be negated.
+ */
+ void purgeWorld(MultiverseWorld mvworld, List thingsToKill, boolean negateAnimals,
+ boolean negateMonsters);
+
+ /**
+ * Clear all animals/monsters that do not belong to a world according to the config.
+ *
+ * @param mvworld The {@link MultiverseWorld}.
+ * @param thingsToKill A {@link List} of animals/monsters to be killed.
+ * @param negateAnimals Whether the monsters in the list should be negated.
+ * @param negateMonsters Whether the animals in the list should be negated.
+ * @param sender The {@link CommandSender} that initiated the action. He will/should be notified.
+ */
+ void purgeWorld(MultiverseWorld mvworld, List thingsToKill, boolean negateAnimals,
+ boolean negateMonsters, CommandSender sender);
+
+}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java
index f2d09887..944d8029 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java
@@ -10,7 +10,6 @@ package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
-import com.onarandombox.MultiverseCore.utils.LocationManipulation;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
@@ -61,8 +60,8 @@ public class CoordCommand extends MultiverseCommand {
DecimalFormat df = new DecimalFormat();
df.setMinimumFractionDigits(0);
df.setMaximumFractionDigits(2);
- p.sendMessage(ChatColor.AQUA + "Coordinates: " + ChatColor.WHITE + LocationManipulation.strCoords(p.getLocation()));
- p.sendMessage(ChatColor.AQUA + "Direction: " + ChatColor.WHITE + LocationManipulation.getDirection(p.getLocation()));
+ p.sendMessage(ChatColor.AQUA + "Coordinates: " + ChatColor.WHITE + plugin.getLocationManipulation().strCoords(p.getLocation()));
+ p.sendMessage(ChatColor.AQUA + "Direction: " + ChatColor.WHITE + plugin.getLocationManipulation().getDirection(p.getLocation()));
p.sendMessage(ChatColor.AQUA + "Block: " + ChatColor.WHITE + Material.getMaterial(world.getBlockTypeIdAt(p.getLocation())));
} else {
sender.sendMessage("This command needs to be used from a Player.");
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java
index dffbd882..c33b06ec 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java
@@ -14,7 +14,6 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.utils.FancyColorScheme;
import com.onarandombox.MultiverseCore.utils.FancyHeader;
import com.onarandombox.MultiverseCore.utils.FancyMessage;
-import com.onarandombox.MultiverseCore.utils.LocationManipulation;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
@@ -113,7 +112,7 @@ public class InfoCommand extends MultiverseCommand {
message.add(new FancyMessage("World Type: ", world.getWorldType().toString(), colors));
//message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors));
Location spawn = world.getSpawnLocation();
- message.add(new FancyMessage("Spawn Location: ", LocationManipulation.strCoords(spawn), colors));
+ message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors));
message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors));
if (world.getPrice() > 0) {
message.add(new FancyMessage("Price to enter this world: ",
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java
index 9790b110..ae54a9b8 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java
@@ -8,7 +8,7 @@
package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
-import com.onarandombox.MultiverseCore.utils.MVMessaging;
+import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
import com.pneumaticraft.commandhandler.Command;
import org.bukkit.command.CommandSender;
@@ -24,9 +24,9 @@ public abstract class MultiverseCommand extends Command {
*/
protected MultiverseCore plugin;
/**
- * The reference to {@link MVMessaging}.
+ * The reference to {@link MultiverseMessaging}.
*/
- protected MVMessaging messaging;
+ protected MultiverseMessaging messaging;
public MultiverseCommand(MultiverseCore plugin) {
super(plugin);
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java
index 89950d5b..8112fd0f 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java
@@ -10,7 +10,7 @@ package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
-import com.onarandombox.MultiverseCore.utils.PurgeWorlds;
+import com.onarandombox.MultiverseCore.api.WorldPurger;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -78,7 +78,7 @@ public class PurgeCommand extends MultiverseCommand {
worldsToRemoveEntitiesFrom.add(this.worldManager.getMVWorld(worldName));
}
- PurgeWorlds purger = this.worldManager.getWorldPurger();
+ WorldPurger purger = this.worldManager.getTheWorldPurger();
ArrayList thingsToKill = new ArrayList();
if (deathName.equalsIgnoreCase("all") || deathName.equalsIgnoreCase("animals") || deathName.equalsIgnoreCase("monsters")) {
thingsToKill.add(deathName.toUpperCase());
@@ -86,7 +86,7 @@ public class PurgeCommand extends MultiverseCommand {
Collections.addAll(thingsToKill, deathName.toUpperCase().split(","));
}
for (MultiverseWorld w : worldsToRemoveEntitiesFrom) {
- purger.purgeWorld(sender, w, thingsToKill, false, false);
+ purger.purgeWorld(w, thingsToKill, false, false, sender);
}
}
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/SetSpawnCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/SetSpawnCommand.java
index ba8863e9..0e0cd96d 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/SetSpawnCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/SetSpawnCommand.java
@@ -8,9 +8,8 @@
package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
+import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
-import com.onarandombox.MultiverseCore.utils.BlockSafety;
-import com.onarandombox.MultiverseCore.utils.LocationManipulation;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@@ -56,7 +55,7 @@ public class SetSpawnCommand extends MultiverseCommand {
MultiverseWorld foundWorld = this.plugin.getMVWorldManager().getMVWorld(w.getName());
if (foundWorld != null) {
foundWorld.setSpawnLocation(p.getLocation());
- BlockSafety bs = new BlockSafety();
+ BlockSafety bs = this.plugin.getBlockSafety();
if (!bs.playerCanSpawnHereSafely(p.getLocation()) && foundWorld.getAdjustSpawn()) {
sender.sendMessage("It looks like that location would normally be unsafe. But I trust you.");
sender.sendMessage("I'm turning off the Safe-T-Teleporter for spawns to this world.");
@@ -64,7 +63,7 @@ public class SetSpawnCommand extends MultiverseCommand {
sender.sendMessage(ChatColor.AQUA + "/mvm set adjustspawn true " + foundWorld.getAlias());
foundWorld.setAdjustSpawn(false);
}
- sender.sendMessage("Spawn was set to: " + LocationManipulation.strCoords(p.getLocation()));
+ sender.sendMessage("Spawn was set to: " + plugin.getLocationManipulation().strCoords(p.getLocation()));
} else {
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set. Please import it to set the spawn fully (Pitch/Yaws).");
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/SpawnCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/SpawnCommand.java
index 80620b78..5925d887 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/SpawnCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/SpawnCommand.java
@@ -85,6 +85,6 @@ public class SpawnCommand extends MultiverseCommand {
} else {
spawnLocation = player.getWorld().getSpawnLocation();
}
- this.plugin.getTeleporter().safelyTeleport(player, player, spawnLocation, false);
+ this.plugin.getSafeTTeleporter().safelyTeleport(player, player, spawnLocation, false);
}
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java
index 8adc91ac..8232c5bb 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java
@@ -14,8 +14,7 @@ import com.onarandombox.MultiverseCore.destination.InvalidDestination;
import com.onarandombox.MultiverseCore.destination.WorldDestination;
import com.onarandombox.MultiverseCore.enums.TeleportResult;
import com.onarandombox.MultiverseCore.event.MVTeleportEvent;
-import com.onarandombox.MultiverseCore.utils.LocationManipulation;
-import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
+import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@@ -43,7 +42,7 @@ public class TeleportCommand extends MultiverseCommand {
this.setArgRange(1, 2);
this.addKey("mvtp");
this.addKey("mv tp");
- this.playerTeleporter = new SafeTTeleporter(this.plugin);
+ this.playerTeleporter = this.plugin.getSafeTTeleporter();
this.setPermission(menu);
}
@@ -163,7 +162,8 @@ public class TeleportCommand extends MultiverseCommand {
}
TeleportResult result = this.playerTeleporter.safelyTeleport(teleporter, teleportee, d);
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 " + plugin.getLocationManipulation().strCoordsRaw(d.getLocation(teleportee)));
this.plugin.log(Level.FINE, "Queueing Command");
Class>[] paramTypes = { CommandSender.class, Player.class, Location.class };
List