Let's go ahead and see if everything explodes.

This commit is contained in:
main() 2012-01-03 16:26:26 +01:00
parent 940dfa4a7e
commit 120009c6b4
19 changed files with 373 additions and 149 deletions

View File

@ -98,12 +98,16 @@
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber">
<property name="ignoreNumbers" value="-1, 0, 0.5, 1, 2, 3, 4, 5 7, 8, 5000"/>
<property name="ignoreNumbers" value="-1, 0, 0.5, 1, 2, 3, 4, 5 7, 8, 127, 45, 90, 135, 180, 225, 270, 315, 22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, 337.5, 180, 360, 5000"/>
<!-- Explanations why we ignore certain magic numbers: -->
<!-- 3: Log-level -->
<!-- 4, 5: Array-indexes in Destinations -->
<!-- 8: Default nether scale in MVWorld -->
<!-- 7: max number of args in CreateCommand -->
<!-- 127: max Y-coord in BlockSafety -->
<!-- 45, 90, 135, 180, 225, 270, 315: Orientation-degrees in LocationManipulation -->
<!-- 22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, 337.5: Orientation-degrees in LocationManipulation -->
<!-- 180, 360: Orientation-degrees in LocationManipulation -->
<!-- 5000: Default messagecooldown in MultiverseCore -->
</module>
<module name="MissingSwitchDefault"/>

View File

@ -17,12 +17,16 @@ import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
/**
* Manages anchors.
*/
public class AnchorManager {
private MultiverseCore plugin;
private Map<String, Location> anchors;
@ -33,15 +37,18 @@ public class AnchorManager {
this.anchors = new HashMap<String, Location>();
}
/**
* Loads all anchors.
*/
public void loadAnchors() {
this.anchors = new HashMap<String, Location>();
this.anchorConfig = YamlConfiguration.loadConfiguration(new File(this.plugin.getDataFolder(), "anchors.yml"));
this.ensureConfigIsPrepared();
ConfigurationSection anchors = this.anchorConfig.getConfigurationSection("anchors");
Set<String> anchorKeys = anchors.getKeys(false);
ConfigurationSection anchorsSection = this.anchorConfig.getConfigurationSection("anchors");
Set<String> anchorKeys = anchorsSection.getKeys(false);
for (String key : anchorKeys) {
//world:x,y,z:pitch:yaw
Location anchorLocation = LocationManipulation.stringToLocation(anchors.getString(key, ""));
Location anchorLocation = LocationManipulation.stringToLocation(anchorsSection.getString(key, ""));
if (anchorLocation != null) {
MultiverseCore.staticLog(Level.INFO, "Loading anchor: '" + key + "'...");
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() {
try {
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) {
if (this.anchors.containsKey(anchor)) {
return this.anchors.get(anchor);
@ -75,11 +91,23 @@ public class AnchorManager {
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) {
Location parsed = LocationManipulation.stringToLocation(location);
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) {
if (l == null) {
return false;
@ -89,29 +117,43 @@ public class AnchorManager {
return this.saveAnchors();
}
/**
* Gets all anchors.
* @return An unmodifiable {@link Set} containing all anchors.
*/
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) {
if (p == null) {
return this.anchors.keySet();
}
Set<String> anchors = new HashSet<String>();
for(String anchor : this.anchors.keySet()) {
Set<String> myAnchors = new HashSet<String>();
for (String anchor : this.anchors.keySet()) {
Location ancLoc = this.anchors.get(anchor);
if(ancLoc == null) {
if (ancLoc == null) {
continue;
}
if(p.hasPermission("multiverse.access." + ancLoc.getWorld().getName())) {
anchors.add(anchor);
if (p.hasPermission("multiverse.access." + ancLoc.getWorld().getName())) {
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) {
if(this.anchors.containsKey(s)) {
if (this.anchors.containsKey(s)) {
this.anchors.remove(s);
this.anchorConfig.set("anchors." + s, null);
return this.saveAnchors();

View File

@ -11,32 +11,40 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Vehicle;
import java.util.logging.Level;
/**
* Used to determine block/location-related facts.
*/
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.
* @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) {
Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
Location downOne = l.clone();
downOne.setY(downOne.getY() - 1);
return (downOne.getBlock().getType() == Material.AIR);
}
public boolean blockIsNotSafe(World world, double x, double y, double z) {
Location l = new Location(world, x, y, z);
return !playerCanSpawnHereSafely(l);
// TODO maybe remove this?
private boolean blockIsNotSafe(World world, double x, double y, double z) {
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) {
Location l = new Location(world, x, y, z);
return playerCanSpawnHereSafely(l);
@ -50,7 +58,7 @@ public class BlockSafety {
* @return Whether the player can spawn safely at the given {@link Location}
*/
public boolean playerCanSpawnHereSafely(Location l) {
if(l == null) {
if (l == null) {
// Can't safely spawn at a null location!
return false;
}
@ -62,20 +70,24 @@ public class BlockSafety {
upOne.setY(upOne.getY() + 1);
downOne.setY(downOne.getY() - 1);
if (this.isSolidBlock(world.getBlockAt(actual).getType()) ||
this.isSolidBlock(upOne.getBlock().getType())) {
MultiverseCore.staticLog(Level.FINER, "Error Here (Actual)? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
MultiverseCore.staticLog(Level.FINER, "Error Here (upOne)? (" + upOne.getBlock().getType() + ")[" + this.isSolidBlock(upOne.getBlock().getType()) + "]");
if (this.isSolidBlock(world.getBlockAt(actual).getType())
|| this.isSolidBlock(upOne.getBlock().getType())) {
MultiverseCore.staticLog(Level.FINER, "Error Here (Actual)? ("
+ actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
MultiverseCore.staticLog(Level.FINER, "Error Here (upOne)? ("
+ upOne.getBlock().getType() + ")[" + this.isSolidBlock(upOne.getBlock().getType()) + "]");
return false;
}
if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
MultiverseCore.staticLog(Level.FINER, "Error Here (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;
}
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;
}
@ -87,6 +99,11 @@ public class BlockSafety {
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) {
Location check = l.clone();
check.setY(127);
@ -99,10 +116,15 @@ public class BlockSafety {
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) {
Location check = l.clone();
check.setY(0);
while (check.getY() <= 126) {
while (check.getY() < 127) {
if (this.playerCanSpawnHereSafely(check)) {
return check;
}
@ -111,7 +133,7 @@ public class BlockSafety {
return null;
}
/**
/*
* If someone has a better way of this... Please either tell us, or submit a pull request!
*/
private boolean isSolidBlock(Material type) {
@ -174,16 +196,23 @@ public class BlockSafety {
return false;
case WATER:
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();
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 upOne = 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}
* @return Whether there are 2 blocks of water
*/
public boolean hasTwoBlocksofWaterBelow(Location l) {
private boolean hasTwoBlocksofWaterBelow(Location l) {
if (l.getBlockY() < 0) {
return false;
}
@ -221,17 +250,26 @@ public class BlockSafety {
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) {
if (this.isBlockAboveAir(cart.getLocation())) {
return true;
}
if (this.isEntitiyOnTrack(cart, LocationManipulation.getNextBlock(cart))) {
if (this.isEntitiyOnTrack(LocationManipulation.getNextBlock(cart))) {
return true;
}
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) {
if (this.isBlockAboveAir(vehicle.getLocation())) {
return true;

View File

@ -18,6 +18,9 @@ import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
/**
* The Multiverse debug-logger.
*/
public class DebugLog {
private FileHandler fh;
@ -51,13 +54,16 @@ public class DebugLog {
/**
* Log a message at a certain level.
*
* @param level
* @param msg
* @param level The log-{@link Level}.
* @param msg the message.
*/
public void log(Level level, String msg) {
this.log.log(level, msg);
}
/**
* Our log-{@link Formatter}.
*/
private class LogFormatter extends Formatter {
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() {
this.fh.close();
}

View File

@ -9,6 +9,9 @@ package com.onarandombox.MultiverseCore.utils;
import org.bukkit.ChatColor;
/**
* A color-scheme.
*/
public class FancyColorScheme {
private ChatColor headerColor;
private ChatColor mainColor;
@ -22,22 +25,43 @@ public class FancyColorScheme {
this.defContentColor = defaultColor;
}
/**
* Gets the header's {@link ChatColor}.
* @return The header's {@link ChatColor}.
*/
public ChatColor getHeader() {
return this.headerColor;
}
/**
* Gets the main {@link ChatColor}.
* @return The main {@link ChatColor}.
*/
public ChatColor getMain() {
return this.mainColor;
}
/**
* Gets the alt {@link ChatColor}.
* @return The alt {@link ChatColor}.
*/
public ChatColor getAlt() {
return this.altColor;
}
/**
* Gets the default {@link ChatColor}.
* @return The default {@link ChatColor}.
*/
public ChatColor getDefault() {
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) {
return main ? this.getMain() : this.getAlt();
}

View File

@ -9,23 +9,30 @@ package com.onarandombox.MultiverseCore.utils;
import com.onarandombox.MultiverseCore.api.FancyText;
/**
* A colored text-header.
*/
public class FancyHeader implements FancyText {
private FancyColorScheme colors;
private String text;
private StringBuilder text;
public FancyHeader(String text, FancyColorScheme scheme) {
this.colors = scheme;
this.text = text;
this.text = new StringBuilder(text);
}
@Override
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) {
this.text += string;
this.text.append(string);
}
}

View File

@ -9,6 +9,9 @@ package com.onarandombox.MultiverseCore.utils;
import com.onarandombox.MultiverseCore.api.FancyText;
/**
* A colored text-message.
*/
public class FancyMessage implements FancyText {
private String title;
private String message;
@ -27,10 +30,16 @@ public class FancyMessage implements FancyText {
this.colors = scheme;
}
/**
* Makes this {@link FancyMessage} use the main-color.
*/
public void setColorMain() {
this.main = true;
}
/**
* Makes this {@link FancyMessage} use the alt-color.
*/
public void setColorAlt() {
this.main = false;
}
@ -40,10 +49,18 @@ public class FancyMessage implements FancyText {
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) {
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) {
this.main = mainColor;
}

View File

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

View File

@ -15,10 +15,13 @@ import org.bukkit.entity.Vehicle;
import org.bukkit.util.Vector;
import java.text.DecimalFormat;
import java.util.Formatter;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Utility class to manipulate locations.
*/
public class LocationManipulation {
private LocationManipulation() { }
@ -33,6 +36,9 @@ public class LocationManipulation {
orientationInts.put("sw", 45);
orientationInts.put("w", 90);
orientationInts.put("nw", 135);
// "freeze" the map:
orientationInts = Collections.unmodifiableMap(orientationInts);
}
/**
@ -49,10 +55,8 @@ public class LocationManipulation {
if (location == null) {
return "";
}
StringBuilder l = new StringBuilder();
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();
return String.format("%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(),
location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
/**

View File

@ -7,13 +7,15 @@
package com.onarandombox.MultiverseCore.utils;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
/**
* Utility-class for messaging.
*/
public class MVMessaging {
private Map<String, Long> sentList;
private int cooldown;
@ -23,6 +25,10 @@ public class MVMessaging {
this.cooldown = 5000;
}
/**
* Sets the message-cooldown.
* @param milliseconds The new message-cooldown in milliseconds.
*/
public void setCooldown(int milliseconds) {
this.cooldown = milliseconds;
}
@ -70,16 +76,16 @@ public class MVMessaging {
return false;
}
private void sendMessage(CommandSender sender, String message) {
sender.sendMessage(message);
}
private void sendMessages(CommandSender sender, String[] messages) {
for (String s : messages) {
sender.sendMessage(s);
}
}
/**
* Gets the message-cooldown.
* @return The message-cooldown.
*/
public int getCooldown() {
return cooldown;
}

View File

@ -21,6 +21,9 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List;
import java.util.logging.Level;
/**
* Multiverse's {@link PermissionsInterface}.
*/
public class MVPermissions implements PermissionsInterface {
private MultiverseCore plugin;
@ -45,7 +48,7 @@ public class MVPermissions implements PermissionsInterface {
this.plugin.log(Level.FINER, "Enforce gamemodes is OFF, all players roam freely!");
return true;
}
if(p.hasPermission("mv.bypass.gamemode.*")) {
if (p.hasPermission("mv.bypass.gamemode.*")) {
this.plugin.log(Level.FINER, "Player has mv.bypass.gamemode.* their gamemode is ignored!");
return true;
}
@ -74,6 +77,12 @@ public class MVPermissions implements PermissionsInterface {
return returnValue;
}
/**
* Checks if the specified {@link CommandSender} can travel to the specified {@link Location}.
* @param sender The {@link CommandSender}.
* @param location The {@link Location}.
* @return Whether the {@link CommandSender} can travel to the specified {@link Location}.
*/
public boolean canTravelFromLocation(CommandSender sender, Location location) {
if (!(sender instanceof Player)) {
return true;
@ -100,7 +109,7 @@ public class MVPermissions implements PermissionsInterface {
return this.hasPermission(p, "multiverse.access." + w.getName(), false);
}
public boolean canEnterLocation(Player p, Location l) {
private boolean canEnterLocation(Player p, Location l) {
if (l == null) {
return false;
}
@ -223,11 +232,17 @@ public class MVPermissions implements PermissionsInterface {
return null;
}
/**
* Gets the type of this {@link PermissionsInterface}.
* @return The type of this {@link PermissionsInterface}.
*/
public String getType() {
return "Bukkit Permissions (SuperPerms)";
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasAnyPermission(CommandSender sender, List<String> nodes, boolean isOpRequired) {
for (String node : nodes) {
@ -238,6 +253,9 @@ public class MVPermissions implements PermissionsInterface {
return false;
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasAllPermission(CommandSender sender, List<String> nodes, boolean isOpRequired) {
for (String node : nodes) {
@ -248,7 +266,8 @@ public class MVPermissions implements PermissionsInterface {
return true;
}
public Permission addPermission(String string, PermissionDefault defaultValue) {
// TODO remove this?
private Permission addPermission(String string, PermissionDefault defaultValue) {
if (this.plugin.getServer().getPluginManager().getPermission(string) == null) {
Permission permission = new Permission(string, defaultValue);
this.plugin.getServer().getPluginManager().addPermission(permission);

View File

@ -13,12 +13,15 @@ import org.bukkit.entity.Player;
import java.util.Date;
/**
* A player-session.
*/
public class MVPlayerSession {
private Player player; // Player holder, may be unnecessary.
private Long teleportLast = 0L; // Timestamp for the Players last Portal Teleportation.
private Long messageLast = 0L; // Timestamp for the Players last Alert Message.
private long teleportLast = 0L; // Timestamp for the Players last Portal Teleportation.
private long messageLast = 0L; // Timestamp for the Players last Alert Message.
private Configuration config; // Configuration file to find out Cooldown Timers.
@ -35,13 +38,10 @@ public class MVPlayerSession {
/**
* Grab whether the cooldown on Portal use has expired or not.
* @return True if the {@link Player} associated with this player-session is teleportable.
*/
public boolean getTeleportable() {
Long time = (new Date()).getTime();
if ((time - this.teleportLast) > this.config.getInt("portalcooldown", 5000)) {
return true;
} else {
return false;
}
long time = (new Date()).getTime();
return ((time - this.teleportLast) > this.config.getInt("portalcooldown", 5000));
}
}

View File

@ -16,6 +16,9 @@ import org.bukkit.entity.Player;
import java.util.logging.Level;
/**
* The Multiverse-{@link TravelAgent}.
*/
public class MVTravelAgent implements TravelAgent {
private MVDestination destination;
private MultiverseCore core;
@ -27,45 +30,72 @@ public class MVTravelAgent implements TravelAgent {
this.player = p;
}
/**
* {@inheritDoc}
*/
@Override
public TravelAgent setSearchRadius(int radius) {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int getSearchRadius() {
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public TravelAgent setCreationRadius(int radius) {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int getCreationRadius() {
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public boolean getCanCreatePortal() {
return false;
}
/**
* {@inheritDoc}
*/
@Override
public void setCanCreatePortal(boolean create) {
}
/**
* {@inheritDoc}
*/
@Override
public Location findOrCreate(Location location) {
return this.getSafeLocation();
}
/**
* {@inheritDoc}
*/
@Override
public Location findPortal(Location location) {
return this.getSafeLocation();
}
/**
* {@inheritDoc}
*/
@Override
public boolean createPortal(Location location) {
return false;

View File

@ -16,6 +16,9 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
/**
* Utility-class for permissions.
*/
public class PermissionTools {
private MultiverseCore plugin;
@ -23,6 +26,10 @@ public class PermissionTools {
this.plugin = plugin;
}
/**
* Adds a permission to the parent-permissions.
* @param permString The new permission as {@link String}.
*/
public void addToParentPerms(String permString) {
String permStringChopped = permString.replace(".*", "");
@ -82,6 +89,15 @@ public class PermissionTools {
return returnString + "*";
}
/**
* Checks if the given {@link Player} has enough money to enter the specified {@link MultiverseWorld}.
* @param fromWorld The {@link MultiverseWorld} the player is coming from.
* @param toWorld The {@link MultiverseWorld} the player is going to.
* @param teleporter The teleporter.
* @param teleportee The teleportee.
* @param pay If the player has to pay the money.
* @return True if the player can enter the world.
*/
public boolean playerHasMoneyToEnter(MultiverseWorld fromWorld, MultiverseWorld toWorld, CommandSender teleporter, Player teleportee, boolean pay) {
Player teleporterPlayer;
if (MultiverseCore.TeleportIntercept) {
@ -117,13 +133,15 @@ public class PermissionTools {
return true;
}
GenericBank bank = plugin.getBank();
String errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()) + " to send " + teleportee + " to " + toWorld.getColoredWorldString();
String errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency())
+ " to send " + teleportee + " to " + toWorld.getColoredWorldString();
if (teleportee.equals(teleporter)) {
errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()) + " to enter " + toWorld.getColoredWorldString();
errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency())
+ " to enter " + toWorld.getColoredWorldString();
}
if (!bank.hasEnough(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency(), errString)) {
return false;
} else if(pay) {
} else if (pay) {
bank.pay(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency());
}
}
@ -147,7 +165,7 @@ public class PermissionTools {
this.plugin.log(Level.FINEST, "Checking '" + teleporter + "' can send '" + teleportee + "' somewhere");
Player teleporterPlayer;
if(MultiverseCore.TeleportIntercept) {
if (MultiverseCore.TeleportIntercept) {
// The console can send anyone anywhere
if (teleporter instanceof ConsoleCommandSender) {
return true;
@ -188,7 +206,7 @@ public class PermissionTools {
return false;
}
} else {
//TODO: Determine if this value is false because a world didn't exist
// TODO: Determine if this value is false because a world didn't exist
// or if it was because a world wasn't imported.
return true;
}
@ -197,7 +215,8 @@ public class PermissionTools {
if (teleportee.equals(teleporter)) {
teleporter.sendMessage("You don't have access to go to " + toWorld.getColoredWorldString() + " from " + fromWorld.getColoredWorldString());
} else {
teleporter.sendMessage("You don't have access to send " + teleportee.getName() + " from " + fromWorld.getColoredWorldString() + " to " + toWorld.getColoredWorldString());
teleporter.sendMessage("You don't have access to send " + teleportee.getName() + " from "
+ fromWorld.getColoredWorldString() + " to " + toWorld.getColoredWorldString());
}
return false;
}
@ -216,7 +235,7 @@ public class PermissionTools {
if (toWorld != null) {
return this.plugin.getMVPerms().canIgnoreGameModeRestriction(teleportee, toWorld);
} else {
//TODO: Determine if this value is false because a world didn't exist
// TODO: Determine if this value is false because a world didn't exist
// or if it was because a world wasn't imported.
return true;
}

View File

@ -11,12 +11,21 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
import org.bukkit.entity.Animals;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Squid;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
/**
* Utility class that removes animals from worlds that don't belong there.
*/
public class PurgeWorlds {
private MultiverseCore plugin;
@ -41,10 +50,10 @@ public class PurgeWorlds {
}
/**
* Convince method for clearing all the animals that do not belong according to the config.
* Convenience method for {@link #purgeWorld(CommandSender, MultiverseWorld, List, boolean, boolean)} that takes the settings from the world-config.
*
* @param sender
* @param world
* @param sender The {@link CommandSender} that initiated the action (TODO: Do we really need this?)
* @param world The {@link MultiverseWorld}.
*/
public void purgeWorld(CommandSender sender, MultiverseWorld world) {
if (world == null) {
@ -55,6 +64,14 @@ public class PurgeWorlds {
purgeWorld(sender, world, allMobs, !world.canAnimalsSpawn(), !world.canMonstersSpawn());
}
/**
* Clear all animals/monsters that do not belong to a world according to the config.
* @param sender The {@link CommandSender} that initiated the action. (TODO: Do we really need this?)
* @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.
*/
public void purgeWorld(CommandSender sender, MultiverseWorld mvworld, List<String> thingsToKill, boolean negateAnimals, boolean negateMonsters) {
if (mvworld == null) {
return;
@ -103,12 +120,6 @@ public class PurgeWorlds {
/**
* Will kill the monster if it's in the list UNLESS the NEGATE boolean is set, then it will kill it if it's NOT.
*
* @param mvworld
* @param e
* @param creaturesToKill
* @param negate
* @return
*/
private boolean killMonster(MultiverseWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
String entityName = "";

View File

@ -24,6 +24,9 @@ import org.bukkit.util.Vector;
import java.util.logging.Level;
/**
* The {@link SafeTTeleporter}.
*/
public class SafeTTeleporter {
private MultiverseCore plugin;
@ -34,12 +37,26 @@ public class SafeTTeleporter {
this.bs = new BlockSafety();
}
private static final int DEFAULT_TOLERANCE = 6;
private static final int DEFAULT_RADIUS = 9;
/**
* Gets the next safe location around the given location.
* @param l A {@link Location}.
* @return A safe {@link Location}.
*/
public Location getSafeLocation(Location l) {
return this.getSafeLocation(l, 6, 9);
return this.getSafeLocation(l, DEFAULT_TOLERANCE, DEFAULT_RADIUS);
}
/**
* 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}.
*/
public Location getSafeLocation(Location l, int tolerance, int radius) {
// Check around the player first in a configurable radius:
// TODO: Make this configurable
Location safe = checkAboveAndBelowLocation(l, tolerance, radius);
@ -54,7 +71,6 @@ public class SafeTTeleporter {
}
private Location checkAboveAndBelowLocation(Location l, int tolerance, int radius) {
// Tolerance must be an even number:
if (tolerance % 2 != 0) {
tolerance += 1;
@ -95,12 +111,8 @@ public class SafeTTeleporter {
return null;
}
/**
/*
* For my crappy algorithm, radius MUST be odd.
*
* @param l
* @param diameter
* @return
*/
private Location checkAroundLocation(Location l, int diameter) {
if (diameter % 2 == 0) {
@ -273,7 +285,7 @@ public class SafeTTeleporter {
Location safeLocation = this.getSafeLocation(l);
if (safeLocation != null) {
// Add offset to account for a vehicle on dry land!
if (e instanceof Minecart && !this.bs.isEntitiyOnTrack(e, safeLocation)) {
if (e instanceof Minecart && !this.bs.isEntitiyOnTrack(safeLocation)) {
safeLocation.setY(safeLocation.getBlockY() + .5);
this.plugin.log(Level.FINER, "Player was inside a minecart. Offsetting Y location.");
}
@ -293,7 +305,11 @@ public class SafeTTeleporter {
return null;
}
/**
* Finds a portal-block next to the specified {@link Location}.
* @param l The {@link Location}
* @return The next portal-block's {@link Location}.
*/
public static Location findPortalBlockNextTo(Location l) {
Block b = l.getWorld().getBlockAt(l);
Location foundLocation = null;

View File

@ -9,6 +9,9 @@ package com.onarandombox.MultiverseCore.utils;
import org.getspout.spoutapi.SpoutManager;
/**
* A helper-class holding the {@link SpoutManager}.
*/
public class SpoutInterface {
private SpoutManager spoutManager;
@ -16,6 +19,10 @@ public class SpoutInterface {
this.spoutManager = SpoutManager.getInstance();
}
/**
* Gets the {@link SpoutManager}.
* @return The {@link SpoutManager}.
*/
public SpoutManager getManager() {
return this.spoutManager;
}

View File

@ -26,7 +26,12 @@ import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
/**
@ -131,7 +136,8 @@ public class WorldManager implements MVWorldManager {
return false;
}
MultiverseWorld mvworld = new MVWorld(world, this.configWorlds, this.plugin, this.plugin.getServer().getWorld(name).getSeed(), generator, useSpawnAdjust);
MultiverseWorld mvworld = new MVWorld(world, this.configWorlds, this.plugin,
this.plugin.getServer().getWorld(name).getSeed(), generator, useSpawnAdjust);
this.worldPurger.purgeWorld(null, mvworld);
this.worlds.put(name, mvworld);
if (this.unloadedWorlds.contains(name)) {
@ -147,8 +153,8 @@ public class WorldManager implements MVWorldManager {
* @return True if the plugin exists and is enabled, false if not.
*/
private boolean pluginExists(String generator) {
Plugin plugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
return plugin != null && plugin.isEnabled();
Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
return myPlugin != null && myPlugin.isEnabled();
}
/**
@ -160,12 +166,11 @@ public class WorldManager implements MVWorldManager {
return null;
}
Plugin plugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
if (plugin == null) {
Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
if (myPlugin == null) {
return null;
} else {
return plugin.getDefaultWorldGenerator(worldName, generatorID);
return myPlugin.getDefaultWorldGenerator(worldName, generatorID);
}
}
@ -452,9 +457,9 @@ public class WorldManager implements MVWorldManager {
@Override
public void loadDefaultWorlds() {
this.ensureConfigIsPrepared();
List<World> worlds = this.plugin.getServer().getWorlds();
List<World> myWorlds = this.plugin.getServer().getWorlds();
Set<String> worldStrings = this.configWorlds.getConfigurationSection("worlds").getKeys(false);
for (World w : worlds) {
for (World w : myWorlds) {
String name = w.getName();
if (!worldStrings.contains(name)) {
if (this.defaultGens.containsKey(name)) {
@ -611,6 +616,10 @@ public class WorldManager implements MVWorldManager {
return this.unloadedWorlds;
}
/**
* Gets the {@link FileConfiguration} that this {@link WorldManager} is using.
* @return The {@link FileConfiguration} that this {@link WorldManager} is using.
*/
public FileConfiguration getConfigWorlds() {
return this.configWorlds;
}

View File

@ -1,39 +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.utils;
/**
* Multiverse 2
* Currently Unused
*/
public class WorldProperty<T> {
private Class<T> type;
private Object value;
public WorldProperty(Class<T> type, Object two, String propertyLocation) {
this.type = type;
this.value = two;
}
public Class<T> getType() {
return this.type;
}
public Object getValue() {
return this.value;
}
public boolean setValue(Object value) {
if (value.getClass().equals(this.type)) {
this.value = value;
return true;
}
return false;
}
}