mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-27 14:13:11 +02:00
Pass a handle for the flying queue to sub checks of blockinteract.
To be done: * Use yaw and pitch of past packjets for Direction and Reach. * If block break mathes the last interacted block (+ moving sequence indicates no change), skip some checks like direction and reach there, possibly keep track if those were run at all.
This commit is contained in:
parent
1655a90b2b
commit
956c7ca803
@ -32,6 +32,7 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.combined.CombinedConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.util.MovingUtil;
|
||||
import fr.neatmonster.nocheatplus.checks.net.FlyingQueueHandle;
|
||||
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
|
||||
import fr.neatmonster.nocheatplus.compat.BridgeHealth;
|
||||
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
|
||||
@ -106,7 +107,7 @@ public class BlockInteractListener extends CheckListener {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Re-arrange for interact spamming.
|
||||
// TODO: Re-arrange for interact spamming. (With ProtocolLib something else is in place as well.)
|
||||
final Action action = event.getAction();
|
||||
final Block block = event.getClickedBlock();
|
||||
final BlockInteractData data = BlockInteractData.getData(player);
|
||||
@ -148,6 +149,7 @@ public class BlockInteractListener extends CheckListener {
|
||||
boolean preventUseItem = false;
|
||||
|
||||
final Location loc = player.getLocation(useLoc);
|
||||
final FlyingQueueHandle flyingHandle = new FlyingQueueHandle(player);
|
||||
|
||||
// TODO: Always run all checks, also for !isBlock ?
|
||||
|
||||
@ -159,17 +161,20 @@ public class BlockInteractListener extends CheckListener {
|
||||
|
||||
if (block != null) {
|
||||
// First the reach check.
|
||||
if (!cancelled && reach.isEnabled(player) && reach.check(player, loc, block, data, cc)) {
|
||||
if (!cancelled && reach.isEnabled(player)
|
||||
&& reach.check(player, loc, block, flyingHandle, data, cc)) {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// Second the direction check
|
||||
if (!cancelled && direction.isEnabled(player) && direction.check(player, loc, block, data, cc)) {
|
||||
if (!cancelled && direction.isEnabled(player)
|
||||
&& direction.check(player, loc, block, flyingHandle, data, cc)) {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// Ray tracing for freecam use etc.
|
||||
if (!cancelled && visible.isEnabled(player) && visible.check(player, loc, block, face, action, data, cc)) {
|
||||
if (!cancelled && visible.isEnabled(player)
|
||||
&& visible.check(player, loc, block, face, action, flyingHandle, data, cc)) {
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.net.FlyingQueueHandle;
|
||||
import fr.neatmonster.nocheatplus.utilities.collision.CollideRayVsAABB;
|
||||
import fr.neatmonster.nocheatplus.utilities.collision.ICollideRayVsAABB;
|
||||
import fr.neatmonster.nocheatplus.utilities.location.LocUtil;
|
||||
@ -48,7 +49,8 @@ public class Direction extends Check {
|
||||
* the location
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location loc, final Block block, final BlockInteractData data, final BlockInteractConfig cc) {
|
||||
public boolean check(final Player player, final Location loc, final Block block,
|
||||
final FlyingQueueHandle flyingHandle, final BlockInteractData data, final BlockInteractConfig cc) {
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
|
@ -23,6 +23,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.checks.net.FlyingQueueHandle;
|
||||
import fr.neatmonster.nocheatplus.utilities.location.TrigUtil;
|
||||
|
||||
/**
|
||||
@ -52,7 +53,8 @@ public class Reach extends Check {
|
||||
* the location
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location loc, final Block block, final BlockInteractData data, final BlockInteractConfig cc) {
|
||||
public boolean check(final Player player, final Location loc, final Block block,
|
||||
final FlyingQueueHandle flyingHandle, final BlockInteractData data, final BlockInteractConfig cc) {
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
|
@ -27,7 +27,7 @@ import org.bukkit.util.Vector;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.checks.net.NetData;
|
||||
import fr.neatmonster.nocheatplus.checks.net.FlyingQueueHandle;
|
||||
import fr.neatmonster.nocheatplus.checks.net.model.DataPacketFlying;
|
||||
import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
||||
import fr.neatmonster.nocheatplus.utilities.collision.InteractRayTracing;
|
||||
@ -56,7 +56,9 @@ public class Visible extends Check {
|
||||
rayTracing.setMaxSteps(60); // TODO: Configurable ?
|
||||
}
|
||||
|
||||
public boolean check(final Player player, final Location loc, final Block block, final BlockFace face, final Action action, final BlockInteractData data, final BlockInteractConfig cc) {
|
||||
public boolean check(final Player player, final Location loc, final Block block, final BlockFace face,
|
||||
final Action action, final FlyingQueueHandle flyingHandle,
|
||||
final BlockInteractData data, final BlockInteractConfig cc) {
|
||||
// TODO: This check might make parts of interact/blockbreak/... + direction (+?) obsolete.
|
||||
// TODO: Might confine what to check for (left/right-click, target blocks depending on item in hand, container blocks).
|
||||
boolean collides;
|
||||
@ -87,7 +89,7 @@ public class Visible extends Check {
|
||||
debug(player, "pitch=" + loc.getPitch() + " yaw=" + loc.getYaw() + " tags=" + StringUtil.join(tags, "+"));
|
||||
}
|
||||
// Re-check with flying packets.
|
||||
final DataPacketFlying[] flyingQueue = ((NetData) CheckType.NET.getDataFactory().getData(player)).copyFlyingQueue();
|
||||
final DataPacketFlying[] flyingQueue = flyingHandle.getHandle();
|
||||
// TODO: Maybe just the latest one does (!).
|
||||
LocUtil.set(useLoc, loc);
|
||||
final float oldPitch = useLoc.getPitch();
|
||||
|
@ -0,0 +1,34 @@
|
||||
package fr.neatmonster.nocheatplus.checks.net;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.net.model.DataPacketFlying;
|
||||
import fr.neatmonster.nocheatplus.components.registry.event.IHandle;
|
||||
|
||||
/**
|
||||
* Convenience for providing several checks with a lazy-init handle for fetching
|
||||
* queued flying packets. Future concept should be somehow linking follow-up
|
||||
* packets (flying->dig) to each other...
|
||||
*
|
||||
* @author asofold
|
||||
*
|
||||
*/
|
||||
public class FlyingQueueHandle implements IHandle<DataPacketFlying[]> {
|
||||
|
||||
private final Player player;
|
||||
private DataPacketFlying[] queue;
|
||||
|
||||
public FlyingQueueHandle(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataPacketFlying[] getHandle() {
|
||||
if (queue == null) {
|
||||
queue = ((NetData) CheckType.NET.getDataFactory().getData(player)).copyFlyingQueue();
|
||||
}
|
||||
return queue;
|
||||
}
|
||||
|
||||
}
|
@ -149,6 +149,11 @@ public class NetData extends ACheckData {
|
||||
*/
|
||||
public DataPacketFlying[] copyFlyingQueue() {
|
||||
lock.lock();
|
||||
/*
|
||||
* TODO: Add a method to synchronize with the current position at the
|
||||
* same time ? Packet inversion is acute on 1.11.2 (dig is processed
|
||||
* before flying).
|
||||
*/
|
||||
final DataPacketFlying[] out = flyingQueue.toArray(new DataPacketFlying[flyingQueue.size()]);
|
||||
lock.unlock();
|
||||
return out;
|
||||
|
Loading…
Reference in New Issue
Block a user