mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-19 22:12:11 +01:00
Add MV Debug, Attempted fix for Portal teleportation fail, Water and Doors are now safe materials
This commit is contained in:
parent
eb4f9700bc
commit
92a762e5e4
@ -117,19 +117,19 @@ public class MVPermissions implements PermissionsInterface {
|
||||
}
|
||||
|
||||
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,6 +138,9 @@ 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;
|
||||
|
||||
}
|
||||
|
@ -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,7 +184,7 @@ 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) {
|
||||
@ -194,22 +202,25 @@ public class MVTeleport {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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<String, MVWorld> worlds = new HashMap<String, MVWorld>();
|
||||
|
||||
@ -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));
|
||||
|
||||
}
|
||||
@ -622,9 +626,21 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
|
||||
* @param msg
|
||||
*/
|
||||
public void log(Level level, String 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print messages to the Debug Log, if the servers in Debug Mode then we also wan't to print the messages to the standard Server Console.
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<String> 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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Object> items = new ArrayList<Object>();
|
||||
items.add(teleportee);
|
||||
|
@ -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,8 +168,10 @@ 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
|
||||
*/
|
||||
|
@ -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.
|
||||
*
|
||||
|
5
src/main/java/com/onarandombox/utils/MVLevel.java
Normal file
5
src/main/java/com/onarandombox/utils/MVLevel.java
Normal file
@ -0,0 +1,5 @@
|
||||
package com.onarandombox.utils;
|
||||
|
||||
public class MVLevel {
|
||||
|
||||
}
|
@ -182,3 +182,7 @@ commands:
|
||||
description: Prints out version invo.
|
||||
usage: |
|
||||
/<command>
|
||||
mvdebug:
|
||||
description: Turns on debugging.
|
||||
usage: |
|
||||
/<command>
|
Loading…
Reference in New Issue
Block a user