Skip to content

Commit

Permalink
Move some debugging code to a utility.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Feb 20, 2013
1 parent 354e7e4 commit e6961a7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
@@ -0,0 +1,55 @@
package fr.neatmonster.nocheatplus.logging;

import java.util.Arrays;

import org.bukkit.Location;
import org.bukkit.entity.Player;

import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
import fr.neatmonster.nocheatplus.utilities.StringUtil;

/**
* Some auxiliary specialized static-access methods.
* @author mc_dev
*
*/
public class DebugUtil {

/**
*
* @param player
* @param from
* @param to
* @param mcAccess
*/
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();
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()));
final double jump = mcAccess.getJumpAmplifier(player);
final double speed = mcAccess.getFasterMovementAmplifier(player);
if (speed != Double.NEGATIVE_INFINITY || jump != Double.NEGATIVE_INFINITY){
builder.append(" (" + (speed != Double.NEGATIVE_INFINITY ? ("speed=" + speed) : "") + (jump != Double.NEGATIVE_INFINITY ? ("jump=" + jump) : "") + ")");
}

// // TEMP: Dump block shapes:
// addBlockBelowInfo(builder, from, "\nfrom");
// addBlockBelowInfo(builder, to, "\nto");

System.out.print(builder.toString());
}

public static void addBlockBelowInfo(final StringBuilder builder, final PlayerLocation loc, final String tag) {
builder.append(tag + " below id= " + loc.getTypeIdBelow() + " shape=" + Arrays.toString(loc.getBlockCache().getBounds(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())));
}

public static void addBlockInfo(final StringBuilder builder, final PlayerLocation loc, final String tag) {
builder.append(tag + " id= " + loc.getTypeId() + " shape=" + Arrays.toString(loc.getBlockCache().getBounds(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
}

}
Expand Up @@ -54,6 +54,7 @@
import fr.neatmonster.nocheatplus.components.IRemoveData;
import fr.neatmonster.nocheatplus.components.TickListener;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.logging.DebugUtil;
import fr.neatmonster.nocheatplus.logging.LogUtil;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
Expand Down Expand Up @@ -489,7 +490,7 @@ public void onPlayerMove(final PlayerMoveEvent event) {
moveInfo.set(player, from, to, cc.yOnGround);

if (cc.debug) {
outputMoveDebug(player, pFrom, pTo);
DebugUtil.outputMoveDebug(player, pFrom, pTo, mcAccess);
}

data.noFallAssumeGround = false;
Expand Down Expand Up @@ -670,23 +671,7 @@ else if (cc.creativeFlyCheck && !NCPExemptionManager.isExempted(player, CheckTyp
// event.setTo(event.getFrom()); // TODO: revise this (old!) strategy, cancelled events just teleport to from, basically.
// }

private void outputMoveDebug(final Player player, final PlayerLocation from, final PlayerLocation to) {
final StringBuilder builder = new StringBuilder(250);
final Location loc = player.getLocation();
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()));
final double jump = mcAccess.getJumpAmplifier(player);
final double speed = mcAccess.getFasterMovementAmplifier(player);
if (speed != Double.NEGATIVE_INFINITY || jump != Double.NEGATIVE_INFINITY){
builder.append(" (" + (speed != Double.NEGATIVE_INFINITY ? ("speed=" + speed) : "") + (jump != Double.NEGATIVE_INFINITY ? ("jump=" + jump) : "") + ")");
}
System.out.print(builder.toString());
}

/**
/**
* Monitor level PlayerMoveEvent.
* @param event
*/
Expand Down

0 comments on commit e6961a7

Please sign in to comment.