diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVPermissions.java b/src/main/java/com/onarandombox/MultiverseCore/MVPermissions.java index de9cb264..07191799 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVPermissions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVPermissions.java @@ -90,7 +90,7 @@ public class MVPermissions implements PermissionsInterface { if (!this.plugin.isMVWorld(worldName)) { return false; } - if(!canEnterLocation(p, d.getLocation(p))) { + if (!canEnterLocation(p, d.getLocation(p))) { return false; } return this.hasPermission(p, d.getRequiredPermission(), false); @@ -105,31 +105,31 @@ public class MVPermissions implements PermissionsInterface { if (!(sender instanceof Player)) { return true; } - + // NO one can access a null permission (mainly used for destinations):w - if(node == null) { + if (node == null) { return false; } // Everyone can access an empty permission // Currently used for the PlayerDestination - if(node.equals("")) { + if (node.equals("")) { return true; } Player player = (Player) sender; - + this.plugin.log(Level.FINEST, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]"); boolean opFallback = this.plugin.getConfig().getBoolean("opfallback", true); if (this.permissions != null && this.permissions.has(player, node)) { // If Permissions is enabled we check against them. - // this.plugin.log(Level.WARNING, "Allowed by P3/P2 "); + this.plugin.log(Level.FINEST, "Allowed by Permissions or something that looked like it."); return true; } else if (sender.hasPermission(node)) { // If Now check the bukkit permissions - // this.plugin.log(Level.WARNING, "Allowed by BukkitPerms"); + this.plugin.log(Level.FINEST, "Allowed by the built in Permissions."); return true; } else if (player.isOp() && opFallback) { // If Player is Op we always let them use it if they have the fallback enabled! - // this.plugin.log(Level.WARNING, "Allowed by OP"); + this.plugin.log(Level.FINEST, "Allowed by OP (opfallback was on)."); return true; } @@ -138,19 +138,22 @@ public class MVPermissions implements PermissionsInterface { // This allows us to act as a default permission guidance // If they have the op fallback disabled, NO commands will work without a permissions plugin. + if (!isOpRequired && opFallback) { + this.plugin.log(Level.FINEST, "Allowed because opfallback was set to true."); + } return !isOpRequired && opFallback; } public String getType() { String opsfallback = ""; - if(this.plugin.getConfig().getBoolean("opfallback", true)) { - opsfallback = " WITH OPs.txt fallback"; + if (this.plugin.getConfig().getBoolean("opfallback", true)) { + opsfallback = " WITH OPs.txt fallback"; } if (this.permissions != null) { return "Permissions " + this.plugin.getServer().getPluginManager().getPlugin("Permissions").getDescription().getVersion() + opsfallback; } - + return "Bukkit Permissions" + opsfallback; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java b/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java index e329690c..dde31f6b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java @@ -9,15 +9,17 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Vehicle; import com.onarandombox.utils.BlockSafety; +import com.onarandombox.utils.LocationManipulation; public class MVTeleport { MultiverseCore plugin; - BlockSafety bs = new BlockSafety(); + BlockSafety bs; public MVTeleport(MultiverseCore plugin) { this.plugin = plugin; + this.bs = new BlockSafety(this.plugin); } /** @@ -47,17 +49,23 @@ public class MVTeleport { if (safe != null) { safe.setX(safe.getBlockX() + .5); safe.setZ(safe.getBlockZ() + .5); + this.plugin.log(Level.FINE, "Hey! I found one: " + LocationManipulation.strCoordsRaw(safe)); + } else { + this.plugin.log(Level.FINE, "Uh oh! No safe place found!"); } return safe; } private Location checkAboveAndBelowLocation(Location l, int tolerance, int radius) { + // Tolerance must be an even number: if (tolerance % 2 != 0) { tolerance += 1; } // We want half of it, so we can go up and down tolerance /= 2; + this.plugin.log(Level.FINER, "Given Location of: " + LocationManipulation.strCoordsRaw(l)); + this.plugin.log(Level.FINER, "Checking +-" + tolerance + " with a radius of " + radius); // For now this will just do a straight up block. Location locToCheck = l.clone(); @@ -176,40 +184,43 @@ public class MVTeleport { public boolean safelyTeleport(Entity e, Location l) { if (this.bs.playerCanSpawnHereSafely(l)) { e.teleport(l); - //this.plugin.log(Level.WARNING, "The first location you gave me was safe."); + plugin.log(Level.FINE, "The first location you gave me was safe."); return true; } - if(e instanceof Minecart) { - Minecart m = (Minecart)e; - if(!this.bs.canSpawnCartSafely(m)) { + if (e instanceof Minecart) { + Minecart m = (Minecart) e; + if (!this.bs.canSpawnCartSafely(m)) { return false; } } - else if(e instanceof Vehicle) { - Vehicle v = (Vehicle)e; - if(!this.bs.canSpawnVehicleSafely(v)) { + else if (e instanceof Vehicle) { + Vehicle v = (Vehicle) e; + if (!this.bs.canSpawnVehicleSafely(v)) { return false; } } Location safeLocation = this.getSafeLocation(l); if (safeLocation != null) { // Add offset to account for a vehicle on dry land! - if (!this.bs.isEntitiyOnTrack(e, safeLocation)) { + if (e instanceof Minecart && !this.bs.isEntitiyOnTrack(e, safeLocation)) { safeLocation.setY(safeLocation.getBlockY() + .5); + this.plugin.log(Level.FINER, "Player was inside a minecart. Offsetting Y location."); } e.teleport(safeLocation); - //this.plugin.log(Level.WARNING, "Had to look for a bit, but I found a safe place for ya!"); + this.plugin.log(Level.FINE, "Had to look for a bit, but I found a safe place for ya!"); return true; } if (e instanceof Player) { Player p = (Player) e; p.sendMessage("No safe locations found!"); + this.plugin.log(Level.FINER, "No safe location found for " + p.getName()); } else if (e.getPassenger() instanceof Player) { Player p = (Player) e.getPassenger(); p.sendMessage("No safe locations found!"); + this.plugin.log(Level.FINER, "No safe location found for " + p.getName()); } - this.plugin.log(Level.WARNING, "Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now."); + this.plugin.log(Level.FINE, "Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now."); return false; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index db867c19..d151a97d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -35,6 +35,7 @@ import com.fernferret.allpay.GenericBank; import com.onarandombox.MultiverseCore.commands.ConfirmCommand; import com.onarandombox.MultiverseCore.commands.CoordCommand; import com.onarandombox.MultiverseCore.commands.CreateCommand; +import com.onarandombox.MultiverseCore.commands.DebugCommand; import com.onarandombox.MultiverseCore.commands.DeleteCommand; import com.onarandombox.MultiverseCore.commands.EnvironmentCommand; import com.onarandombox.MultiverseCore.commands.HelpCommand; @@ -104,6 +105,8 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { public UpdateChecker updateCheck; + public static int GlobalDebug = 0; + // HashMap to contain all the Worlds which this Plugin will manage. private HashMap worlds = new HashMap(); @@ -265,6 +268,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { // Misc Commands this.commandHandler.registerCommand(new EnvironmentCommand(this)); + this.commandHandler.registerCommand(new DebugCommand(this)); this.commandHandler.registerCommand(new SleepCommand(this)); } @@ -467,9 +471,9 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { * @return True if success, false if failure. */ public Boolean deleteWorld(String name) { - + if (this.getServer().getWorld(name) != null) { - if(!unloadWorld(name, false)) { + if (!unloadWorld(name, false)) { // If the world was loaded, and we couldn't unload it, return false. DON"T DELTEE return false; } @@ -622,8 +626,20 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { * @param msg */ public void log(Level level, String msg) { - log.log(level, this.tag + " " + msg); - debugLog.log(level, this.tag + " " + msg); + // We're using Config as debug + if (level == Level.FINE && GlobalDebug >= 1) { + this.debugLog(Level.INFO, msg); + return; + } else if (level == Level.FINER && GlobalDebug >= 2) { + this.debugLog(Level.INFO, msg); + return; + } else if (level == Level.FINEST && GlobalDebug >= 3) { + this.debugLog(Level.INFO, msg); + return; + } else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) { + log.log(level, this.tag + " " + msg); + debugLog.log(level, this.tag + " " + msg); + } } /** @@ -633,10 +649,8 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { * @param msg */ public void debugLog(Level level, String msg) { - if (this.debug) { - log.log(level, "[Debug] " + msg); - } - debugLog.log(level, "[Debug] " + msg); + log.log(level, "[MVCore-Debug] " + msg); + debugLog.log(level, "[MVCore-Debug] " + msg); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java new file mode 100644 index 00000000..de630728 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java @@ -0,0 +1,54 @@ +package com.onarandombox.MultiverseCore.commands; + +import java.util.List; +import java.util.logging.Level; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.permissions.PermissionDefault; + +import com.onarandombox.MultiverseCore.MultiverseCore; + +public class DebugCommand extends MultiverseCommand { + + public DebugCommand(MultiverseCore plugin) { + super(plugin); + this.setName("Turn Debug on/off?"); + this.setCommandUsage("/mv who" + ChatColor.GOLD + " [1|2|3|off]"); + this.setArgRange(0, 1); + this.addKey("mv debug"); + this.addKey("mv d"); + this.addKey("mvdebug"); + this.setPermission("multiverse.core.debug", "Spams the console a bunch.", PermissionDefault.OP); + } + + @Override + public void runCommand(CommandSender sender, List args) { + if (args.size() == 1) { + if (args.get(0).equalsIgnoreCase("off")) { + MultiverseCore.GlobalDebug = 0; + } else { + try { + int debugLevel = Integer.parseInt(args.get(0)); + if(debugLevel > 3 || debugLevel < 0) { + throw new NumberFormatException(); + } + MultiverseCore.GlobalDebug = debugLevel; + } catch (NumberFormatException e) { + sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE + " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)"); + } + + } + } + this.displayDebugMode(sender); + } + + private void displayDebugMode(CommandSender sender) { + if (MultiverseCore.GlobalDebug == 0) { + sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF"); + } else { + sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + MultiverseCore.GlobalDebug); + this.plugin.log(Level.FINE, "Multiverse Debug ENABLED"); + } + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java index 0c1d14dd..0a225098 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java @@ -2,6 +2,7 @@ package com.onarandombox.MultiverseCore.commands; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -111,6 +112,8 @@ public class TeleportCommand extends MultiverseCommand { return; } if (!this.playerTeleporter.safelyTeleport(teleportee, l)) { + this.plugin.log(Level.FINE, "Could not teleport " + teleportee.getName() + " to " + l); + this.plugin.log(Level.FINE, "Queueing Command"); Class paramTypes[] = { Player.class, Location.class }; List items = new ArrayList(); items.add(teleportee); diff --git a/src/main/java/com/onarandombox/utils/BlockSafety.java b/src/main/java/com/onarandombox/utils/BlockSafety.java index 14709e6f..553caa89 100644 --- a/src/main/java/com/onarandombox/utils/BlockSafety.java +++ b/src/main/java/com/onarandombox/utils/BlockSafety.java @@ -1,5 +1,7 @@ package com.onarandombox.utils; +import java.util.logging.Level; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -7,7 +9,15 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Minecart; import org.bukkit.entity.Vehicle; +import com.onarandombox.MultiverseCore.MultiverseCore; + public class BlockSafety { + private MultiverseCore plugin; + + public BlockSafety(MultiverseCore plugin) { + this.plugin = plugin; + } + /** * This function checks whether the block at the given coordinates are above air or not. * @@ -45,18 +55,25 @@ public class BlockSafety { downOne.setY(downOne.getY() - 1); if (this.isSolidBlock(actual.getBlock().getType()) || this.isSolidBlock(upOne.getBlock().getType())) { + this.plugin.log(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]"); + this.plugin.log(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]"); return false; } if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) { + this.plugin.log(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]"); + this.plugin.log(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]"); return false; } if (downOne.getBlock().getType() == Material.FIRE) { + this.plugin.log(Level.FINER, "There's fire below! (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]"); return false; } if (isBlockAboveAir(actual)) { + this.plugin.log(Level.FINER, "Is block above air [" + isBlockAboveAir(actual) + "]"); + this.plugin.log(Level.FINER, "Has 2 blocks of water below [" + this.hasTwoBlocksofWaterBelow(actual) + "]"); return this.hasTwoBlocksofWaterBelow(actual); } return true; @@ -122,6 +139,12 @@ public class BlockSafety { return false; case SIGN_POST: return false; + case WOODEN_DOOR: + return false; + case STATIONARY_WATER: + return false; + case WATER: + return false; } return true; } @@ -145,41 +168,43 @@ public class BlockSafety { System.out.print("Location Down: " + downOne.getBlock().getType()); System.out.print(" " + downOne); } + /** * Checks recursively below location L for 2 blocks of water + * * @param l * @return */ public boolean hasTwoBlocksofWaterBelow(Location l) { - if(l.getBlockY() < 0) { + if (l.getBlockY() < 0) { return false; } Location oneBelow = l.clone(); oneBelow.subtract(0, 1, 0); - if(oneBelow.getBlock().getType() == Material.WATER || oneBelow.getBlock().getType() == Material.STATIONARY_WATER) { + if (oneBelow.getBlock().getType() == Material.WATER || oneBelow.getBlock().getType() == Material.STATIONARY_WATER) { Location twoBelow = oneBelow.clone(); twoBelow.subtract(0, 1, 0); return (oneBelow.getBlock().getType() == Material.WATER || oneBelow.getBlock().getType() == Material.STATIONARY_WATER); } - if(oneBelow.getBlock().getType() != Material.AIR) { + if (oneBelow.getBlock().getType() != Material.AIR) { return false; } return hasTwoBlocksofWaterBelow(oneBelow); } - + public boolean canSpawnCartSafely(Minecart cart) { - - if(this.isBlockAboveAir(cart.getLocation())) { + + if (this.isBlockAboveAir(cart.getLocation())) { return true; } - if(this.isEntitiyOnTrack(cart, LocationManipulation.getNextBlock(cart))) { - return true; + if (this.isEntitiyOnTrack(cart, LocationManipulation.getNextBlock(cart))) { + return true; } return false; } - + public boolean canSpawnVehicleSafely(Vehicle vehicle) { - if(this.isBlockAboveAir(vehicle.getLocation())) { + if (this.isBlockAboveAir(vehicle.getLocation())) { return true; } return false; diff --git a/src/main/java/com/onarandombox/utils/LocationManipulation.java b/src/main/java/com/onarandombox/utils/LocationManipulation.java index 9893b1b0..12bf936f 100644 --- a/src/main/java/com/onarandombox/utils/LocationManipulation.java +++ b/src/main/java/com/onarandombox/utils/LocationManipulation.java @@ -30,7 +30,7 @@ public class LocationManipulation { * @param location * @return */ - public String locationToString(Location location) { + public static String locationToString(Location location) { StringBuilder l = new StringBuilder(); l.append(location.getBlockX() + ":"); l.append(location.getBlockY() + ":"); @@ -78,6 +78,19 @@ public class LocationManipulation { return result; } + public static String strCoordsRaw(Location l) { + String result = ""; + DecimalFormat df = new DecimalFormat(); + df.setMinimumFractionDigits(0); + df.setMaximumFractionDigits(2); + result += "X: " + df.format(l.getX()) + " "; + result += "Y: " + df.format(l.getY()) + " "; + result += "Z: " + df.format(l.getZ()) + " "; + result += "P: " + df.format(l.getPitch()) + " "; + result += "Y: " + df.format(l.getYaw()) + " "; + return result; + } + /** * Return the NESW Direction a Location is facing. * diff --git a/src/main/java/com/onarandombox/utils/MVLevel.java b/src/main/java/com/onarandombox/utils/MVLevel.java new file mode 100644 index 00000000..e9b05b24 --- /dev/null +++ b/src/main/java/com/onarandombox/utils/MVLevel.java @@ -0,0 +1,5 @@ +package com.onarandombox.utils; + +public class MVLevel { + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b9f9aac2..e9727b49 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -180,5 +180,9 @@ commands: / mvhelp: description: Prints out version invo. + usage: | + / + mvdebug: + description: Turns on debugging. usage: | / \ No newline at end of file