mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-29 23:17:41 +02:00
Integrate current look into flying queue checking. Include invalidation.
This commit is contained in:
parent
54f9d42ca1
commit
e5f6370705
@ -77,11 +77,11 @@ public class Reach extends Check {
|
|||||||
final ViolationData vd = new ViolationData(this, player, data.reachVL, distance, cc.reachActions);
|
final ViolationData vd = new ViolationData(this, player, data.reachVL, distance, cc.reachActions);
|
||||||
vd.setParameter(ParameterName.REACH_DISTANCE, String.valueOf(Math.round(data.reachDistance)));
|
vd.setParameter(ParameterName.REACH_DISTANCE, String.valueOf(Math.round(data.reachDistance)));
|
||||||
cancel = executeActions(vd).willCancel();
|
cancel = executeActions(vd).willCancel();
|
||||||
} else
|
} else {
|
||||||
// Player passed the check, reward them.
|
// Player passed the check, reward them.
|
||||||
data.reachVL *= 0.9D;
|
data.reachVL *= 0.9D;
|
||||||
data.addPassedCheck(this.type);
|
data.addPassedCheck(this.type);
|
||||||
|
}
|
||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,26 +132,14 @@ public class Visible extends Check {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Ray-tracing.
|
// Ray-tracing.
|
||||||
Vector direction = loc.getDirection();
|
|
||||||
// Initialize.
|
// Initialize.
|
||||||
final BlockCache blockCache = this.wrapBlockCache.getBlockCache();
|
final BlockCache blockCache = this.wrapBlockCache.getBlockCache();
|
||||||
blockCache.setAccess(loc.getWorld());
|
blockCache.setAccess(loc.getWorld());
|
||||||
rayTracing.setBlockCache(blockCache);
|
rayTracing.setBlockCache(blockCache);
|
||||||
collides = checkRayTracing(eyeX, eyeY, eyeZ, direction.getX(), direction.getY(), direction.getZ(), blockX, blockY, blockZ, face, tags, data.debug);
|
collides = !checker.checkFlyingQueue(eyeX, eyeY, eyeZ, loc.getYaw(), loc.getPitch(),
|
||||||
if (collides) {
|
blockX, blockY, blockZ, flyingHandle, face, tags, data.debug, player);
|
||||||
// Debug output.
|
checker.cleanup();
|
||||||
if (data.debug) {
|
useLoc.setWorld(null);
|
||||||
debug(player, "pitch=" + loc.getPitch() + ",yaw=" + loc.getYaw() + " tags=" + StringUtil.join(tags, "+"));
|
|
||||||
}
|
|
||||||
// Re-check with flying packets.
|
|
||||||
if (checker.checkFlyingQueue(eyeX, eyeY, eyeZ, useLoc.getYaw(), useLoc.getPitch(),
|
|
||||||
blockX, blockY, blockZ, flyingHandle, face, tags, data.debug, player)) {
|
|
||||||
// Check passed.
|
|
||||||
collides = false;
|
|
||||||
}
|
|
||||||
checker.cleanup();
|
|
||||||
useLoc.setWorld(null);
|
|
||||||
}
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
rayTracing.cleanup();
|
rayTracing.cleanup();
|
||||||
blockCache.cleanup();
|
blockCache.cleanup();
|
||||||
|
@ -122,15 +122,13 @@ public abstract class AbstractBlockDirectionCheck<D extends ICheckData, C extend
|
|||||||
final int blockY = block.getY();
|
final int blockY = block.getY();
|
||||||
final int blockZ = block.getZ();
|
final int blockZ = block.getZ();
|
||||||
// The distance is squared initially.
|
// The distance is squared initially.
|
||||||
double distance = checkBoulder(x, y, z, loc.getYaw(), loc.getPitch(), blockX, blockY, blockZ);
|
double distance;
|
||||||
if (distance != Double.MAX_VALUE) {
|
if (checker.checkFlyingQueue(x, y, z, loc.getYaw(), loc.getPitch(),
|
||||||
if (checker.checkFlyingQueue(x, y, z, loc.getYaw(), loc.getPitch(),
|
blockX, blockY, blockZ, flyingHandle)) {
|
||||||
blockX, blockY, blockZ, flyingHandle)) {
|
distance = Double.MAX_VALUE;
|
||||||
distance = Double.MAX_VALUE;
|
}
|
||||||
}
|
else {
|
||||||
else {
|
distance = checker.getMinDistance();
|
||||||
distance = Math.min(distance, checker.getMinDistance());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Consider a protected field with a tolerance value.
|
// TODO: Consider a protected field with a tolerance value.
|
||||||
|
@ -20,6 +20,11 @@ public class FlyingQueueHandle implements IHandle<DataPacketFlying[]> {
|
|||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private DataPacketFlying[] queue;
|
private DataPacketFlying[] queue;
|
||||||
|
/**
|
||||||
|
* Convenience flag for keeping track amongst multiple checks, which all get
|
||||||
|
* passed this FlyingQueueHandle.
|
||||||
|
*/
|
||||||
|
private boolean currentLocationValid = true;
|
||||||
|
|
||||||
public FlyingQueueHandle(Player player) {
|
public FlyingQueueHandle(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -86,4 +91,24 @@ public class FlyingQueueHandle implements IHandle<DataPacketFlying[]> {
|
|||||||
return queue == null ? -1 : queue.length;
|
return queue == null ? -1 : queue.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the currentLocationValid flag (convenience to keep track of a custom
|
||||||
|
* flag).
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isCurrentLocationValid() {
|
||||||
|
return currentLocationValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the currentLocationValid flag (convenience to keep track of a custom
|
||||||
|
* flag).
|
||||||
|
*
|
||||||
|
* @param currentLocationValid
|
||||||
|
*/
|
||||||
|
public void setCurrentLocationValid(boolean currentLocationValid) {
|
||||||
|
this.currentLocationValid = currentLocationValid;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,28 @@ public abstract class FlyingQueueLookBlockChecker {
|
|||||||
* Override to prevent setting elements that can't be used or for which
|
* Override to prevent setting elements that can't be used or for which
|
||||||
* check returned false to null.
|
* check returned false to null.
|
||||||
*/
|
*/
|
||||||
protected boolean setUnusableToNull = true;
|
protected boolean invalidateFailed = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the check with the given oldPitch and oldYaw, unless invalidated.
|
||||||
|
* invalidateFailed applies.
|
||||||
|
*/
|
||||||
|
protected boolean checkOldLook = true;
|
||||||
|
|
||||||
protected abstract boolean check(final double x, final double y, final double z,
|
protected abstract boolean check(final double x, final double y, final double z,
|
||||||
final float yaw, final float pitch,
|
final float yaw, final float pitch,
|
||||||
final int blockX, final int blockY, final int blockZ);
|
final int blockX, final int blockY, final int blockZ);
|
||||||
|
|
||||||
|
public FlyingQueueLookBlockChecker setInvalidateFailed(boolean invalidatedFailed) {
|
||||||
|
this.invalidateFailed = invalidatedFailed;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlyingQueueLookBlockChecker setCheckOldLook(boolean checkOldLook) {
|
||||||
|
this.checkOldLook = checkOldLook;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run check with the given start position (e.g. eye coordinates), but use
|
* Run check with the given start position (e.g. eye coordinates), but use
|
||||||
* yaw and pitch from the flying queue. Non matching entries are nulled,
|
* yaw and pitch from the flying queue. Non matching entries are nulled,
|
||||||
@ -41,6 +57,15 @@ public abstract class FlyingQueueLookBlockChecker {
|
|||||||
public boolean checkFlyingQueue(final double x, final double y, final double z,
|
public boolean checkFlyingQueue(final double x, final double y, final double z,
|
||||||
final float oldYaw, final float oldPitch,
|
final float oldYaw, final float oldPitch,
|
||||||
final int blockX, final int blockY, final int blockZ, final FlyingQueueHandle flyingHandle) {
|
final int blockX, final int blockY, final int blockZ, final FlyingQueueHandle flyingHandle) {
|
||||||
|
if (checkOldLook && flyingHandle.isCurrentLocationValid()) {
|
||||||
|
if (check(x, y, z, oldYaw, oldPitch, blockX, blockY, blockZ)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Invalidate.
|
||||||
|
flyingHandle.setCurrentLocationValid(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
final DataPacketFlying[] queue = flyingHandle.getHandle();
|
final DataPacketFlying[] queue = flyingHandle.getHandle();
|
||||||
if (queue.length == 0) {
|
if (queue.length == 0) {
|
||||||
return false;
|
return false;
|
||||||
@ -51,7 +76,7 @@ public abstract class FlyingQueueLookBlockChecker {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!packetData.hasLook) {
|
if (!packetData.hasLook) {
|
||||||
if (setUnusableToNull) {
|
if (invalidateFailed) {
|
||||||
queue[i] = null;
|
queue[i] = null;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -61,7 +86,7 @@ public abstract class FlyingQueueLookBlockChecker {
|
|||||||
// Simple heuristic: reduce impact of checking by skipping redundant entries.
|
// Simple heuristic: reduce impact of checking by skipping redundant entries.
|
||||||
// TODO: Other heuristic / what's typical?
|
// TODO: Other heuristic / what's typical?
|
||||||
if (yaw == oldYaw && pitch == oldPitch) {
|
if (yaw == oldYaw && pitch == oldPitch) {
|
||||||
if (setUnusableToNull) {
|
if (invalidateFailed) {
|
||||||
queue[i] = null;
|
queue[i] = null;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -72,7 +97,7 @@ public abstract class FlyingQueueLookBlockChecker {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (setUnusableToNull) {
|
if (invalidateFailed) {
|
||||||
queue[i] = null;
|
queue[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user