Skip to content

Commit

Permalink
Unify locations on debugging (DebugUtil). Remove formatted locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Apr 26, 2016
1 parent 60a00bf commit 9249cb2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 109 deletions.
Expand Up @@ -1619,7 +1619,7 @@ public void playerLeaves(final Player player) {
StaticLog.logWarning("SKIP set-back for " + player.getName() + ", because distance is too high (risk of false positives): " + d);
}
else {
StaticLog.logInfo("Set back player " + player.getName() + ": " + DebugUtil.formatLocation(refLoc));
StaticLog.logInfo("Set back player " + player.getName() + ": " + LocUtil.simpleFormat(refLoc));
data.prepareSetBack(refLoc);
if (!player.teleport(refLoc)) {
StaticLog.logWarning("FAILED to set back player " + player.getName());
Expand Down Expand Up @@ -1927,15 +1927,31 @@ private void outputMoveDebug(final Player player, final PlayerLocation from, fin
builder.setLength(0);
// Note: the block flags are for normal on-ground checking, not with yOnGrond set to 0.5.
from.collectBlockFlags(maxYOnGround);
if (from.getBlockFlags() != 0) builder.append("\nfrom flags: " + StringUtil.join(BlockProperties.getFlagNames(from.getBlockFlags()), "+"));
if (from.getTypeId() != 0) DebugUtil.addBlockInfo(builder, from, "\nfrom");
if (from.getTypeIdBelow() != 0) DebugUtil.addBlockBelowInfo(builder, from, "\nfrom");
if (!from.isOnGround() && from.isOnGround(0.5)) builder.append(" (ground within 0.5)");
if (from.getBlockFlags() != 0) {
builder.append("\nfrom flags: " + StringUtil.join(BlockProperties.getFlagNames(from.getBlockFlags()), "+"));
}
if (from.getTypeId() != 0) {
DebugUtil.addBlockInfo(builder, from, "\nfrom");
}
if (from.getTypeIdBelow() != 0) {
DebugUtil.addBlockBelowInfo(builder, from, "\nfrom");
}
if (!from.isOnGround() && from.isOnGround(0.5)) {
builder.append(" (ground within 0.5)");
}
to.collectBlockFlags(maxYOnGround);
if (to.getBlockFlags() != 0) builder.append("\nto flags: " + StringUtil.join(BlockProperties.getFlagNames(to.getBlockFlags()), "+"));
if (to.getTypeId() != 0) DebugUtil.addBlockInfo(builder, to, "\nto");
if (to.getTypeIdBelow() != 0) DebugUtil.addBlockBelowInfo(builder, to, "\nto");
if (!to.isOnGround() && to.isOnGround(0.5)) builder.append(" (ground within 0.5)");
if (to.getBlockFlags() != 0) {
builder.append("\nto flags: " + StringUtil.join(BlockProperties.getFlagNames(to.getBlockFlags()), "+"));
}
if (to.getTypeId() != 0) {
DebugUtil.addBlockInfo(builder, to, "\nto");
}
if (to.getTypeIdBelow() != 0) {
DebugUtil.addBlockBelowInfo(builder, to, "\nto");
}
if (!to.isOnGround() && to.isOnGround(0.5)) {
builder.append(" (ground within 0.5)");
}
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, builder.toString());
}
}
Expand Down
Expand Up @@ -3,35 +3,24 @@
import org.bukkit.Location;

import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.moving.location.LocUtil;
import fr.neatmonster.nocheatplus.logging.Streams;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
import fr.neatmonster.nocheatplus.utilities.TrigUtil;

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

// TODO: Add useLoc1 and useLoc2.

/**
* Just the coordinates.
* @param loc
* @return
*/
public static String formatLocation(final Location loc) {
StringBuilder b = new StringBuilder(128);
addLocation(loc, b);
return b.toString();
}

/**
* Just the coordinates.
* Coordinates and pitch/yaw, no extras.
*
* @param from
* @param to
* @return
Expand All @@ -42,127 +31,82 @@ public static String formatMove(Location from, Location to) {
return builder.toString();
}

public static void addLocation(final double x, final double y, final double z, final StringBuilder builder){
builder.append(x + ", " + y + ", " + z);
}

public static void addLocation(final Location loc, final StringBuilder builder){
addLocation(loc.getX(), loc.getY(), loc.getZ(), builder);
builder.append(LocUtil.simpleFormat(loc));
}

public static void addLocation(final PlayerLocation loc, final StringBuilder builder){
addLocation(loc.getX(), loc.getY(), loc.getZ(), builder);
}

public static void addFormattedLocation(final double x, final double y, final double z, final StringBuilder builder){
builder.append(StringUtil.fdec3.format(x) + ", " + StringUtil.fdec3.format(y) + ", " + StringUtil.fdec3.format(z));
}

public static void addFormattedLocation(final Location loc, final StringBuilder builder){
addFormattedLocation(loc.getX(), loc.getY(), loc.getZ(), builder);
}

public static void addFormattedLocation(final PlayerLocation loc, final StringBuilder builder){
addFormattedLocation(loc.getX(), loc.getY(), loc.getZ(), builder);
}


/**
* With line break between from and to.
* @param fromX
* @param fromY
* @param fromZ
* @param toX
* @param toY
* @param toZ
* @param builder
*/
public static void addMove(final double fromX, final double fromY, final double fromZ, final double toX, final double toY, final double toZ, final StringBuilder builder){
builder.append("from: ");
addLocation(fromX, fromY, fromZ, builder);
builder.append("\nto: ");
addLocation(toX, toY, toZ, builder);
}

/**
* No line breaks, max. 3 digits after comma.
* @param fromX
* @param fromY
* @param fromZ
* @param toX
* @param toY
* @param toZ
* @param builder
*/
public static void addFormattedMove(final double fromX, final double fromY, final double fromZ, final double toX, final double toY, final double toZ, final StringBuilder builder){
addFormattedLocation(fromX, fromY, fromZ, builder);
builder.append(" -> ");
addFormattedLocation(toX, toY, toZ, builder);
builder.append(LocUtil.simpleFormat(loc));
}

/**
* 3 decimal digits after comma (StringUtil.fdec3). No leading new line.
* Add exact coordinates and pitch/yaw, multiple lines. No leading/trailing
* new lines.
*
* @param from
* @param to
* @param loc Reference location for from, usually Player.getLocation(). May be null.
* @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){
public static void addMove(final PlayerLocation from, final PlayerLocation to, final Location loc, final StringBuilder builder){
if (loc != null && !from.isSamePos(loc)){
builder.append("(");
addFormattedLocation(loc, builder);
builder.append(") ");
builder.append("Location: ");
addLocation(loc, builder);
builder.append("\n");
}
addFormattedMove(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), builder);
addMove(from, to, builder);
}

/**
* Add exact coordinates, multiple lines. No leading new line.
* Add exact coordinates and pitch/yaw, multiple lines. No leading/trailing
* new lines.
*
* @param from
* @param to
* @param loc Reference location for from, usually Player.getLocation().
* @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){
if (loc != null && !from.isSamePos(loc)){
public static void addMove(final Location from, final Location to, final Location loc, final StringBuilder builder){
if (loc != null && !TrigUtil.isSamePos(from, loc)){
builder.append("Location: ");
addLocation(loc, builder);
builder.append("\n");
}
addMove(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), builder);
addMove(from, to, builder);
}

/**
* 3 decimal digits after comma (StringUtil.fdec3). No leading new line.
* Add exact coordinates and pitch/yaw, multiple lines. No leading/trailing
* newlines.
*
* @param from
* @param to
* @param loc Reference location for from, usually Player.getLocation().
* @param builder
* @return
*/
public static void addFormattedMove(final Location from, final Location to, final Location loc, final StringBuilder builder){
if (loc != null && !TrigUtil.isSamePos(from, loc)){
builder.append("(");
addFormattedLocation(loc, builder);
builder.append(") ");
}
addFormattedMove(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), builder); }
public static void addMove(final PlayerLocation from, final PlayerLocation to, final StringBuilder builder) {
builder.append("From: ");
addLocation(from, builder);
builder.append("\n");
builder.append("To: ");
addLocation(to, builder);
}

/**
* Add exact coordinates, multiple lines. No leading new line.
* Add exact coordinates and pitch/yaw, multiple lines. No leading/trailing
* newlines.
*
* @param from
* @param to
* @param loc Reference location for from, usually Player.getLocation().
* @param builder
*/
public static void addMove(final Location from, final Location to, final Location loc, final StringBuilder builder){
if (loc != null && !TrigUtil.isSamePos(from, loc)){
builder.append("Location: ");
addLocation(loc, builder);
builder.append("\n");
}
addMove(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), builder);
public static void addMove(final Location from, final Location to, final StringBuilder builder) {
builder.append("From: ");
addLocation(from, builder);
builder.append("\n");
builder.append("To: ");
addLocation(to, builder);
}

public static void addBlockBelowInfo(final StringBuilder builder, final PlayerLocation loc, final String tag) {
Expand Down

0 comments on commit 9249cb2

Please sign in to comment.