From de44ea43a43d4683294a8826f2d8f4c87a190e80 Mon Sep 17 00:00:00 2001 From: asofold Date: Tue, 5 Mar 2013 18:26:10 +0100 Subject: [PATCH] Fix for flags + adjust debug output to show flags and exact coordinates on higher debugLevel. --- .../nocheatplus/logging/DebugUtil.java | 47 +++++++++++++++++-- .../utilities/BlockProperties.java | 12 +++-- .../nocheatplus/utilities/PlayerLocation.java | 8 ++++ 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/logging/DebugUtil.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/logging/DebugUtil.java index fa032c0e..b91719be 100644 --- a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/logging/DebugUtil.java +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/logging/DebugUtil.java @@ -6,6 +6,7 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.compat.MCAccess; +import fr.neatmonster.nocheatplus.utilities.BlockProperties; import fr.neatmonster.nocheatplus.utilities.PlayerLocation; import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.build.BuildParameters; @@ -17,6 +18,36 @@ import fr.neatmonster.nocheatplus.utilities.build.BuildParameters; */ public class DebugUtil { + /** + * 3 decimal digits after comma (StringUtil.fdec3). + * @param from + * @param to + * @param loc Reference location for from, usually Player.getLocation(). + * @param builder + * @return + */ + public static void addFormattedMove(final PlayerLocation from, final PlayerLocation to, final Location loc, final StringBuilder builder){ + builder.append(" " + from.getWorld().getName() + " " + StringUtil.fdec3.format(from.getX()) + (from.getX() == loc.getX() ? "" : ("(" + StringUtil.fdec3.format(loc.getX()) + ")"))); + builder.append(", " + StringUtil.fdec3.format(from.getY()) + (from.getY() == loc.getY() ? "" : ("(" + StringUtil.fdec3.format(loc.getY()) + ")"))); + builder.append(", " + StringUtil.fdec3.format(from.getZ()) + (from.getZ() == loc.getZ() ? "" : ("(" + StringUtil.fdec3.format(loc.getZ()) + ")"))); + builder.append(" -> " + StringUtil.fdec3.format(to.getX()) + ", " + StringUtil.fdec3.format(to.getY()) + ", " + StringUtil.fdec3.format(to.getZ())); + + } + + /** + * Add exact coordinates, multiple lines. + * @param from + * @param to + * @param loc Reference location for from, usually Player.getLocation(). + * @param builder + */ + public static void addMove(final PlayerLocation from, final PlayerLocation to, final Location loc, final StringBuilder builder){ + builder.append(" " + from.getWorld().getName() + "moves:\nfrom: " + from.getX() + (from.getX() == loc.getX() ? "" : ("(" + loc.getX() + ")"))); + builder.append(", " + from.getY() + (from.getY() == loc.getY() ? "" : ("(" + loc.getY() + ")"))); + builder.append(", " + from.getZ() + (from.getZ() == loc.getZ() ? "" : ("(" + loc.getZ() + ")"))); + builder.append("\nto: " + to.getX() + ", " + to.getY() + ", " + to.getZ()); + } + /** * * @param player @@ -27,11 +58,14 @@ public class DebugUtil { public static void outputMoveDebug(final Player player, final PlayerLocation from, final PlayerLocation to, final MCAccess mcAccess) { final StringBuilder builder = new StringBuilder(250); final Location loc = player.getLocation(); + // TODO: Differentiate debug levels (needs setting up some policy + document in BuildParamteres)? builder.append(player.getName()); - builder.append(" " + from.getWorld().getName() + " " + StringUtil.fdec3.format(from.getX()) + (from.getX() == loc.getX() ? "" : ("(" + StringUtil.fdec3.format(loc.getX()) + ")"))); - builder.append(", " + StringUtil.fdec3.format(from.getY()) + (from.getY() == loc.getY() ? "" : ("(" + StringUtil.fdec3.format(loc.getY()) + ")"))); - builder.append(", " + StringUtil.fdec3.format(from.getZ()) + (from.getZ() == loc.getZ() ? "" : ("(" + StringUtil.fdec3.format(loc.getZ()) + ")"))); - builder.append(" -> " + StringUtil.fdec3.format(to.getX()) + ", " + StringUtil.fdec3.format(to.getY()) + ", " + StringUtil.fdec3.format(to.getZ())); + if (BuildParameters.debugLevel > 0) { + addMove(from, to, loc, builder); + } + else { + addFormattedMove(from, to, loc, builder); + } final double jump = mcAccess.getJumpAmplifier(player); final double speed = mcAccess.getFasterMovementAmplifier(player); if (speed != Double.NEGATIVE_INFINITY || jump != Double.NEGATIVE_INFINITY){ @@ -39,9 +73,14 @@ public class DebugUtil { } if (BuildParameters.debugLevel > 0){ + // Note: the block flags are for normal on-ground checking, not with yOnGrond set to 0.5. + from.collectBlockFlags(from.getyOnGround()); + if (from.getBlockFlags() != 0) builder.append("\nfrom flags: " + StringUtil.join(BlockProperties.getFlagNames(from.getBlockFlags()), "+")); if (from.getTypeId() != 0) addBlockInfo(builder, from, "\nfrom"); if (from.getTypeIdBelow() != 0) addBlockBelowInfo(builder, from, "\nfrom"); if (!from.isOnGround() && from.isOnGround(0.5)) builder.append(" (ground within 0.5)"); + to.collectBlockFlags(to.getyOnGround()); + if (to.getBlockFlags() != 0) builder.append("\nto flags: " + StringUtil.join(BlockProperties.getFlagNames(to.getBlockFlags()), "+")); if (to.getTypeId() != 0) addBlockInfo(builder, to, "\nto"); if (to.getTypeIdBelow() != 0) addBlockBelowInfo(builder, to, "\nto"); if (!to.isOnGround() && to.isOnGround(0.5)) builder.append(" (ground within 0.5)"); diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java index b45310fc..9735e89b 100644 --- a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java @@ -670,8 +670,9 @@ public class BlockProperties { * @param flags * @return */ - public static Collection getFlagNames(final long flags) { + public static Collection getFlagNames(final Long flags) { final ArrayList tags = new ArrayList(flagNameMap.size()); + if (flags == null) return tags; addFlagNames(flags, tags); return tags; } @@ -1615,7 +1616,12 @@ public class BlockProperties { continue; } - // TODO: Check passable workaround without checking ignore flag. +// // Check if the block can be passed through with the bounding box (disregard the ignore flag). +// if (isPassableWorkaround(access, x, y, z, minX - x, minY - y, minZ - z, id, maxX - minX, maxY - minY, maxZ - minZ, 1.0)){ +// // Spider ! +// System.out.println("*** Continue: passable workaround"); +// continue; +// } // TODO: Shortcut: if bounds[4] > fx return true (careful with fences) ? @@ -1626,7 +1632,7 @@ public class BlockProperties { } final int aboveId = access.getTypeId(x, y + 1, z); final long aboveFlags = blockFlags[aboveId]; - if ((flags & aboveFlags & F_IGN_PASSABLE) != 0){ + if ((aboveFlags & F_IGN_PASSABLE) != 0){ // flags & // Ignore these (Note for above block check before ground property). // TODO: Should this always apply ? return true; diff --git a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java index 6420776a..a336cc47 100644 --- a/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java +++ b/NCPCompat/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java @@ -770,5 +770,13 @@ public class PlayerLocation { // if (Math.abs(box.a) > 3.2E7D || Math.abs(box.b) > 3.2E7D || Math.abs(box.c) > 3.2E7D || Math.abs(box.d) > 3.2E7D || Math.abs(box.e) > 3.2E7D || Math.abs(box.f) > 3.2E7D) return true; else return false; } + + /** + * Get the collected block-flags. This will return null if collectBlockFlags has not been called. + * @return + */ + public Long getBlockFlags() { + return blockFlags; + } }