mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-19 10:21:27 +02:00
Fix for flags + adjust debug output to show flags and exact coordinates
on higher debugLevel.
This commit is contained in:
parent
354511b88f
commit
de44ea43a4
@ -6,6 +6,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||||
|
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||||
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||||
import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
||||||
import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;
|
import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;
|
||||||
@ -17,6 +18,36 @@ import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;
|
|||||||
*/
|
*/
|
||||||
public class DebugUtil {
|
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
|
* @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) {
|
public static void outputMoveDebug(final Player player, final PlayerLocation from, final PlayerLocation to, final MCAccess mcAccess) {
|
||||||
final StringBuilder builder = new StringBuilder(250);
|
final StringBuilder builder = new StringBuilder(250);
|
||||||
final Location loc = player.getLocation();
|
final Location loc = player.getLocation();
|
||||||
|
// TODO: Differentiate debug levels (needs setting up some policy + document in BuildParamteres)?
|
||||||
builder.append(player.getName());
|
builder.append(player.getName());
|
||||||
builder.append(" " + from.getWorld().getName() + " " + StringUtil.fdec3.format(from.getX()) + (from.getX() == loc.getX() ? "" : ("(" + StringUtil.fdec3.format(loc.getX()) + ")")));
|
if (BuildParameters.debugLevel > 0) {
|
||||||
builder.append(", " + StringUtil.fdec3.format(from.getY()) + (from.getY() == loc.getY() ? "" : ("(" + StringUtil.fdec3.format(loc.getY()) + ")")));
|
addMove(from, to, loc, builder);
|
||||||
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()));
|
else {
|
||||||
|
addFormattedMove(from, to, loc, builder);
|
||||||
|
}
|
||||||
final double jump = mcAccess.getJumpAmplifier(player);
|
final double jump = mcAccess.getJumpAmplifier(player);
|
||||||
final double speed = mcAccess.getFasterMovementAmplifier(player);
|
final double speed = mcAccess.getFasterMovementAmplifier(player);
|
||||||
if (speed != Double.NEGATIVE_INFINITY || jump != Double.NEGATIVE_INFINITY){
|
if (speed != Double.NEGATIVE_INFINITY || jump != Double.NEGATIVE_INFINITY){
|
||||||
@ -39,9 +73,14 @@ public class DebugUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (BuildParameters.debugLevel > 0){
|
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.getTypeId() != 0) addBlockInfo(builder, from, "\nfrom");
|
||||||
if (from.getTypeIdBelow() != 0) addBlockBelowInfo(builder, from, "\nfrom");
|
if (from.getTypeIdBelow() != 0) addBlockBelowInfo(builder, from, "\nfrom");
|
||||||
if (!from.isOnGround() && from.isOnGround(0.5)) builder.append(" (ground within 0.5)");
|
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.getTypeId() != 0) addBlockInfo(builder, to, "\nto");
|
||||||
if (to.getTypeIdBelow() != 0) addBlockBelowInfo(builder, to, "\nto");
|
if (to.getTypeIdBelow() != 0) addBlockBelowInfo(builder, to, "\nto");
|
||||||
if (!to.isOnGround() && to.isOnGround(0.5)) builder.append(" (ground within 0.5)");
|
if (!to.isOnGround() && to.isOnGround(0.5)) builder.append(" (ground within 0.5)");
|
||||||
|
@ -670,8 +670,9 @@ public class BlockProperties {
|
|||||||
* @param flags
|
* @param flags
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Collection<String> getFlagNames(final long flags) {
|
public static Collection<String> getFlagNames(final Long flags) {
|
||||||
final ArrayList<String> tags = new ArrayList<String>(flagNameMap.size());
|
final ArrayList<String> tags = new ArrayList<String>(flagNameMap.size());
|
||||||
|
if (flags == null) return tags;
|
||||||
addFlagNames(flags, tags);
|
addFlagNames(flags, tags);
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
@ -1615,7 +1616,12 @@ public class BlockProperties {
|
|||||||
continue;
|
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) ?
|
// 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 int aboveId = access.getTypeId(x, y + 1, z);
|
||||||
final long aboveFlags = blockFlags[aboveId];
|
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).
|
// Ignore these (Note for above block check before ground property).
|
||||||
// TODO: Should this always apply ?
|
// TODO: Should this always apply ?
|
||||||
return true;
|
return true;
|
||||||
|
@ -771,4 +771,12 @@ public class PlayerLocation {
|
|||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the collected block-flags. This will return null if collectBlockFlags has not been called.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Long getBlockFlags() {
|
||||||
|
return blockFlags;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user