Skip to content

Commit

Permalink
Pass a handle for the flying queue to sub checks of blockinteract.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
asofold committed Apr 27, 2017
1 parent 1655a90 commit 956c7ca
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -106,7 +107,7 @@ else if (MovingUtil.hasScheduledPlayerSetBack(player)) {
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);
Expand Down Expand Up @@ -148,6 +149,7 @@ else if (MovingUtil.hasScheduledPlayerSetBack(player)) {
boolean preventUseItem = false;

final Location loc = player.getLocation(useLoc);
final FlyingQueueHandle flyingHandle = new FlyingQueueHandle(player);

// TODO: Always run all checks, also for !isBlock ?

Expand All @@ -159,17 +161,20 @@ else if (MovingUtil.hasScheduledPlayerSetBack(player)) {

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;
}
}
Expand Down
Expand Up @@ -21,6 +21,7 @@

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;
Expand Down Expand Up @@ -48,7 +49,8 @@ public Direction() {
* 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;

Expand Down
Expand Up @@ -23,6 +23,7 @@
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;

/**
Expand Down Expand Up @@ -52,7 +53,8 @@ public Reach() {
* 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;

Expand Down
Expand Up @@ -27,7 +27,7 @@
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;
Expand Down Expand Up @@ -56,7 +56,9 @@ public Visible() {
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;
Expand Down Expand Up @@ -87,7 +89,7 @@ public boolean check(final Player player, final Location loc, final Block block,
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();
Expand Down
@@ -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;
}

}
Expand Up @@ -149,6 +149,11 @@ public void clearFlyingQueue() {
*/
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;
Expand Down

0 comments on commit 956c7ca

Please sign in to comment.