Spicy NoRotate module 1 files, 61 lines

Spicy NoRotate: Full Source Analysis

Spicy's NoRotate cancels the rotation half of server teleports.

info/spicyclient/modules/player/NoRotate.java · GitHub source ↗

Published 2026-08-13 · Updated 2026-08-13

Analysis

Overview

Spicy's NoRotate cancels the rotation half of server teleports. Its single event branch handles EventServerSetYawAndPitch, the wrapper around the yaw and pitch fields of an incoming S08PacketPlayerPosLook, and cancels it pre, with an optional Notify setting that surfaces a message when the server tries to rotate the player. The position half of the teleport still applies, so coordinates stay synchronized and only the aim is kept. The module sends no packets and produces no movement of its own; it exists to stop lag-back and checkpoint teleports from snapping the player's view.

Architecture

The module carries a single BooleanSetting (Notify, default false) and two empty lifecycle methods. All behavior lives in one event branch: when an EventServerSetYawAndPitch arrives in the pre phase, the handler calls event.setCanceled(true), which stops the client from applying the server's yaw and pitch, and optionally sets event.notify from the setting so the user sees a message when the server attempts a rotation. resetSettings re-registers the setting so config loads cannot add stale entries.

Key techniques

The effect is purely cosmetic control. After any server teleport with rotation, a lag-back, pearl, portal or checkpoint, the client keeps its own aim instead of snapping to the server's angles. The position half of the teleport still applies, so the player's coordinates stay synchronized and movement checks see no desync. The cancel happens before the rotation is written to the player, so no reverse-rotation packet is needed or sent; the module never constructs a packet and never touches position or velocity.

Detection surface

The module has no wire signature: it trims an inbound packet field, and the client's subsequent C03 stream carries whatever the player actually does. The S08/C03 listing reflects that stream: S08 is the teleport being trimmed, and C03 is the movement that continues from the retained rotation afterward. No server-side check can observe the cancel, because the rotation the server sent is never echoed back in comparable form; the enforcement that remains is the positional ledger and movement envelopes around the teleport.

source NoRotate.java (module)

NoRotate.java61 lines · JavaOriginal ↗
1
package info.spicyclient.modules.player;
2
3
import org.apache.commons.lang3.StringUtils;
4
import org.lwjgl.input.Keyboard;
5
6
import info.spicyclient.events.Event;
7
import info.spicyclient.events.listeners.EventChatmessage;
8
import info.spicyclient.events.listeners.EventMotion;
9
import info.spicyclient.events.listeners.EventServerSetYawAndPitch;
10
import info.spicyclient.events.listeners.EventUpdate;
11
import info.spicyclient.modules.Module;
12
import info.spicyclient.settings.BooleanSetting;
13
import info.spicyclient.settings.ModeSetting;
14
import info.spicyclient.settings.NumberSetting;
15
import info.spicyclient.ui.NewAltManager;
16
import net.minecraft.block.BlockAir;
17
import net.minecraft.network.play.client.C03PacketPlayer;
18
import net.minecraft.util.BlockPos;
19
import net.minecraft.util.MathHelper;
20
21
public class NoRotate extends Module {
22
	
23
	private BooleanSetting notify = new BooleanSetting("Notify", false);
24
	
25
	public NoRotate() {
26
		super("NoRotate", Keyboard.KEY_NONE, Category.PLAYER);
27
		resetSettings();
28
	}
29
	
30
	@Override
31
	public void resetSettings() {
32
		this.settings.clear();
33
		this.addSettings(notify);
34
	}
35
	
36
	public void onEnable() {
37
		
38
	}
39
	
40
	public void onDisable() {
41
		
42
	}
43
	
44
	public void onEvent(Event e) {
45
		
46
		if (e instanceof EventServerSetYawAndPitch) {
47
			
48
			if (e.isPre()) {
49
				
50
				EventServerSetYawAndPitch event = (EventServerSetYawAndPitch) e;
51
				
52
				event.setCanceled(true);
53
				event.notify = notify.enabled;
54
				
55
			}
56
			
57
		}
58
		
59
	}
60
	
61
}

What this file does

The module is one event branch with a single setting. EventServerSetYawAndPitch is Spicy's wrapper around the rotation half of an incoming S08PacketPlayerPosLook; the pre handler sets event.setCanceled(true), which stops the client from applying the server's yaw and pitch, and optionally sets event.notify from the Notify BooleanSetting so the user sees a message when the server tries to rotate them. onEnable and onDisable are empty, and resetSettings re-registers the single setting. The module never sends a packet and never touches position.

The effect is purely cosmetic control: after any server teleport with rotation, the client keeps its own aim instead of snapping to the server's angles. The position half of the teleport still applies, so the player's coordinates stay synchronized and movement checks see no desync. The cancel happens before the rotation is written to the player, so no reverse-rotation packet is needed or sent.

The wire signature is therefore none. The S08/C03 listing reflects the stream the module touches: S08 is the teleport it trims, and C03 is the movement that continues from the retained rotation afterward.

anticheat Countering Checks

The anticheat code that detects or counters the techniques this module uses. Full source, with the detection mechanism explained below each box.

anticheat TeleportQueue (S08 teleport ledger)

TeleportQueue.java370 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.net.model;
16
17
import java.util.Iterator;
18
import java.util.LinkedList;
19
import java.util.concurrent.locks.Lock;
20
import java.util.concurrent.locks.ReentrantLock;
21
22
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
23
24
/**
25
 * Queue outgoing teleport locations (DataPacketFlying), in order to cancel
26
 * other moving until the client acknowledges previous teleport locations. In
27
 * fact this might only queue a single location.
28
 * 
29
 * @author asofold
30
 *
31
 */
32
public class TeleportQueue {
33
34
    public static enum AckResolution {
35
        /** Waiting for ACK. */
36
        WAITING,
37
        /** Packet is ACK. */
38
        ACK,
39
        /** Not waiting for an ACK. */
40
        IDLE
41
    }
42
43
    public static class AckReference {
44
        public int lastOutgoingId = Integer.MIN_VALUE;
45
        /**
46
         * The maximum of confirmed ids. Once lastOutgoingId is reached, we
47
         * assume all teleports are done. Until then this id may get adjusted if
48
         * lower than lastOutgoingId. Note that the id will be circling within 0
49
         * to Integer.MAX_VALUE - 1, systematically increasing until back to 0,
50
         * thus this value can be greater than lastOutGoingId, which should be
51
         * treated as 'bad luck', resetting this to Integer.MIN_VALUE.
52
         */
53
        public int maxConfirmedId = Integer.MIN_VALUE;
54
    }
55
56
    // TODO: Consider passing a reentrant lock in the constructor (e.g. one lock per NetData).
57
    private final Lock lock = new ReentrantLock();
58
59
    /** Validated outgoing teleport locations, expected to be confirmed by the client. */
60
    private final LinkedList<CountableLocation> expectIncoming = new LinkedList<CountableLocation>();
61
    /** Location from a Bukkit event, which we expect an outgoing teleport for. */
62
    private DataLocation expectOutgoing = null;
63
64
    private long maxAge = 4000; // TODO: configurable
65
    private int maxQueueSize = 60; // TODO: configurable
66
67
    /**
68
     * Queried from the primary thread (read only), reset with outgoing
69
     * teleport.
70
     */
71
    private CountableLocation lastAck = null;
72
73
    private AckReference lastAckReference = new AckReference();
74
75
    /**
76
     * Maximum age in milliseconds, older entries expire.
77
     * @return
78
     */
79
    public long getMaxAge() {
80
        return maxAge;
81
    }
82
83
    /**
84
     * The last confirmed teleport location (read-only by primary thread),
85
     * resets with outgoing teleport.
86
     * 
87
     * @return
88
     */
89
    public CountableLocation getLastAck() {
90
        return lastAck;
91
    }
92
93
    /**
94
     * Get the reference of the last ack, not resetting, but updating with
95
     * incoming acks. This always is the same object, it might only by updated
96
     * on a successful ACK, depending on what's needed (current use is to cancel
97
     * packets on processAck returning WAITING).
98
     * 
99
     * @return
100
     */
101
    public AckReference getLastAckReference() {
102
        return lastAckReference;
103
    }
104
105
    /**
106
     * Compact diagnostic snapshot for NET_MOVING false-positive analysis.
107
     */
108
    public String getDebugState(final long now) {
109
        final StringBuilder builder = new StringBuilder(300);
110
        lock.lock();
111
        builder.append("expectOutgoing=").append(expectOutgoing == null ? "none" : expectOutgoing.toString());
112
        builder.append(",expectIncomingSize=").append(expectIncoming.size());
113
        if (!expectIncoming.isEmpty()) {
114
            builder.append(",incomingFirst=").append(formatCountable(expectIncoming.getFirst(), now));
115
            builder.append(",incomingLast=").append(formatCountable(expectIncoming.getLast(), now));
116
        }
117
        builder.append(",lastAck=").append(lastAck == null ? "none" : formatCountable(lastAck, now));
118
        builder.append(",ackRef=lastOutgoing:").append(lastAckReference.lastOutgoingId)
119
                .append("/maxConfirmed:").append(lastAckReference.maxConfirmedId);
120
        builder.append(",maxAge=").append(maxAge);
121
        lock.unlock();
122
        return builder.toString();
123
    }
124
125
    private String formatCountable(final CountableLocation ref, final long now) {
126
        final StringBuilder builder = new StringBuilder(160);
127
        builder.append(ref.toString());
128
        builder.append(",age=");
129
        builder.append(now >= ref.time ? now - ref.time : -(ref.time - now));
130
        return builder.toString();
131
    }
132
133
    /**
134
     * Call for Bukkit events (expect this packet to be sent).<br>
135
     * TODO: The method name is misleading, as this also should be called with
136
     * expected outgoing packet.
137
     * 
138
     * @param packetData
139
     */
140
    public void onTeleportEvent(final double x, final double y, final double z, final float yaw, final float pitch) {
141
        lock.lock();
142
        lastAck = null;
143
        expectOutgoing = new DataLocation(x, y, z, yaw, pitch);
144
        lock.unlock();
145
    }
146
147
    /**
148
     * Call for outgoing teleport packets. Lazily checks for expiration and max
149
     * queue size. Update teleportId (Integer.MIN_VALUE means that it isn't
150
     * provided).
151
     * 
152
     * @param x
153
     * @param y
154
     * @param z
155
     * @param yaw
156
     * @param pitch
157
     * @param teleportId
158
     * @return
159
     */
160
    public CountableLocation onOutgoingTeleport(final double x, final double y, final double z, 
161
            final float yaw, final float pitch, final int teleportId) {
162
        CountableLocation res = null;
163
        final long time = System.currentTimeMillis();
164
        lock.lock();
165
        lastAckReference.lastOutgoingId = teleportId;
166
        if (lastAckReference.maxConfirmedId > lastAckReference.lastOutgoingId) {
167
            lastAckReference.maxConfirmedId = Integer.MIN_VALUE; // Some data loss accepted here.
168
        }
169
        // Only register this location, if it matches the location from a Bukkit event.
170
        if (expectOutgoing != null) {
171
            if (expectOutgoing.isSamePosAndLook(x, y, z, yaw, pitch)) {
172
                // Add to queue.
173
                if (!expectIncoming.isEmpty()) {
174
                    // Lazy expiration check.
175
                    final Iterator<CountableLocation> it = expectIncoming.iterator();
176
                    while (it.hasNext()) {
177
                        final CountableLocation ref = it.next();
178
                        if (time < ref.time) {
179
                            // Time ran backwards. Force keep entries.
180
                            ref.time = time;
181
                        }
182
                        else if (time - maxAge > ref.time) {
183
                            it.remove();
184
                        } else {
185
                            break;
186
                        }
187
                    }
188
                    if (!expectIncoming.isEmpty()) {
189
                        final CountableLocation last = expectIncoming.getLast();
190
                        if (last.isSamePosAndLook(x, y, z, yaw, pitch)) {
191
                            last.time = time;
192
                            last.count ++;
193
                            last.teleportId = teleportId;
194
                            res = last;
195
                        }
196
                    }
197
                }
198
                // Add a new entry, if not merged with last.
199
                if (res == null) {
200
                    res = new CountableLocation(x, y, z, yaw, pitch, 1, time, teleportId);
201
                    expectIncoming.addLast(res);
202
                    // Don't exceed maxQueueSize.
203
                    if (expectIncoming.size() > maxQueueSize) {
204
                        expectIncoming.removeFirst();
205
                    }
206
                }
207
            }
208
            // Reset in any case.
209
            expectOutgoing = null;
210
        }
211
        lock.unlock();
212
        return res;
213
    }
214
215
    /**
216
     * Process ack on receiving a 'confirm teleport' packet.
217
     * 
218
     * @param teleportId
219
     * @return YES, if this teleport id is explicitly matched (not necessarily
220
     *         the latest one), MAYBE if it's a unique id smaller than than
221
     *         maxConfirmedId. NO, if it's not a valid ack - it could be some
222
     *         other special condition, like Integer overflow, or timeout.
223
     */
224
    public AlmostBoolean processAck(final int teleportId) {
225
        /*
226
         * Return values are subject to change, e.g.: (ACK_LATEST_POS),
227
         * ACK_LATEST_ID, ACK_OUTDATED_POS, ACK_OUTDATED_ID, UNKNOWN
228
         */
229
        if (teleportId == Integer.MIN_VALUE) {
230
            // Could consider to return MAYBE for not knowing, needs elaborating on context and use cases.
231
            return AlmostBoolean.NO;
232
        }
233
        lock.lock();
234
        if (teleportId == lastAckReference.lastOutgoingId) {
235
            lastAckReference.maxConfirmedId = teleportId;
236
            // Abort here for efficiency.
237
            expectIncoming.clear();
238
            lock.unlock();
239
            return AlmostBoolean.YES;
240
        }
241
        AlmostBoolean ackState = AlmostBoolean.NO;
242
        final Iterator<CountableLocation> it = expectIncoming.iterator();
243
        while (it.hasNext()) {
244
            final CountableLocation ref = it.next();
245
            // No expiration checks here.
246
            if (ref.teleportId == teleportId) {
247
                // Match an outdated id.
248
                // Remove all preceding older entries and this one.
249
                while (ref != expectIncoming.getFirst()) {
250
                    expectIncoming.removeFirst();
251
                }
252
                expectIncoming.removeFirst();
253
                // The count doesn't count anymore.
254
                ref.count = 0;
255
                ackState = AlmostBoolean.YES;
256
                break;
257
            }
258
        }
259
        // Update lastAckReference only if within the safe area.
260
        if (teleportId < lastAckReference.lastOutgoingId 
261
                && teleportId > lastAckReference.maxConfirmedId) {
262
            // Allow update.
263
            lastAckReference.maxConfirmedId = teleportId;
264
            if (ackState == AlmostBoolean.NO) {
265
                // Adjust to maybe, as long as the id is increasing within unique range.
266
                ackState = AlmostBoolean.MAYBE;
267
            }
268
        }
269
        else {
270
            lastAckReference.maxConfirmedId = Integer.MIN_VALUE;
271
        }
272
        lock.unlock();
273
        return ackState;
274
    }
275
276
    /**
277
     * Accept a movement packet that matches the teleport location from a Bukkit
278
     * event before ProtocolLib has observed the matching outgoing position.
279
     */
280
    public boolean consumeExpectedOutgoingPosition(final DataPacketFlying packetData) {
281
        if (packetData == null || !packetData.hasPos) {
282
            return false;
283
        }
284
        lock.lock();
285
        final boolean match = expectOutgoing != null && expectOutgoing.isSamePos(packetData);
286
        if (match) {
287
            expectOutgoing = null;
288
        }
289
        lock.unlock();
290
        return match;
291
    }
292
293
    /**
294
     * Test if the move is an ACK move (or no ACK is expected), adjust internals
295
     * if necessary.
296
     * 
297
     * @param packetData
298
     * @return ACK, if the packet matches an expected ACK position. IDLE, if no
299
     *         ACK is expected or on timeout. CANCEL, if still waiting for an
300
     *         ACK.
301
     */
302
    public AckResolution processAck(final DataPacketFlying packetData) {
303
        // Check packet.
304
        if (!packetData.hasPos || !packetData.hasLook) {
305
            // Applies, if we don't have a teleport-confirm event.
306
            return AckResolution.IDLE;
307
        }
308
        // Check queue.
309
        final AckResolution res;
310
311
        lock.lock();
312
        if (expectIncoming.isEmpty()) {
313
            res = AckResolution.IDLE;
314
        } else {
315
            res = getAckResolution(packetData);
316
        }
317
        lock.unlock();
318
319
        return res;
320
    }
321
322
    /**
323
     * Check queue (lock is handled outside of this method). Does check for
324
     * expiration of entries. Must only be called under lock.
325
     * 
326
     * @param packetData
327
     * @return
328
     */
329
    private AckResolution getAckResolution(final DataPacketFlying packetData) {
330
        // Iterate from oldest to newest.
331
        final Iterator<CountableLocation> it = expectIncoming.iterator();
332
        while (it.hasNext()) {
333
            final CountableLocation ref = it.next();
334
            if (packetData.time - maxAge >= ref.time) {
335
                it.remove();
336
            }
337
            else if (packetData.isSamePosAndLook(ref)) {
338
                // Match.
339
                // Remove all preceding older entries.
340
                while (ref != expectIncoming.getFirst()) {
341
                    expectIncoming.removeFirst();
342
                }
343
                // Decrease count and remove the matching entry if count is down to 0.
344
                if (--ref.count <= 0) { // (Lots of safety margin.)
345
                    expectIncoming.removeFirst(); // Do not use the iterator here.
346
                }
347
                lastAck = ref;
348
                return AckResolution.ACK;
349
            }
350
            else {
351
                // Skip until match or none found.
352
                // TODO: Consider settings like maxSkipCount or strictly return WAITING.
353
                if (packetData.time < ref.time) {
354
                    // Time ran backwards, update to now.
355
                    ref.time = packetData.time;
356
                }
357
            }
358
        }
359
        // No match.
360
        return expectIncoming.isEmpty() ? AckResolution.IDLE : AckResolution.WAITING;
361
    }
362
363
    public void clear() {
364
        lock.lock();
365
        expectIncoming.clear();
366
        expectOutgoing = null;
367
        lock.unlock();
368
    }
369
370
}

How it counteracts this module

TeleportQueue implements NoCheatPlus's teleport acknowledgment contract: outgoing S08 teleport locations are queued, and further movement is cancelled until the client acknowledges the previous teleport, which is why the movement checks can trust post-teleport positions. The queue is the net-side state every S08-consuming check reads.

NoRotate cancels only the yaw and pitch application of the server teleport, and the position half still lands client-side, so the player's reported position remains synchronized with the server's expectation and the acknowledgment flow is unaffected. A NoRotate user who moves normally confirms teleports in order and the ledger is satisfied; the module's cancel is invisible to the queue because rotation is not part of the acknowledgment. The queue matters to a NoRotate setup only through the movement modules that typically accompany it: speed and phase desyncs generate lag-back S08s, and the client must confirm each one before further moves are processed, so unacknowledged teleports still snap the player back.

The boundary: the check never sees the rotation cancel, and no position-based check can, because the rotation data of S08 is not re-sent by the client in any comparable form. NoRotate is a display-side convenience that defeats only the cosmetic snap; every positional enforcement on the server continues to apply in full.

anticheat Speed (horizontal envelope)

Speed.java280 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.check.movement.position;
20
21
import me.islandscout.hawk.Hawk;
22
import me.islandscout.hawk.HawkPlayer;
23
import me.islandscout.hawk.check.MovementCheck;
24
import me.islandscout.hawk.event.Event;
25
import me.islandscout.hawk.event.HawkEventListener;
26
import me.islandscout.hawk.event.ItemSwitchEvent;
27
import me.islandscout.hawk.event.MoveEvent;
28
import me.islandscout.hawk.util.*;
29
import me.islandscout.hawk.wrap.entity.WrappedEntity;
30
import org.bukkit.ChatColor;
31
import org.bukkit.Material;
32
import org.bukkit.enchantments.Enchantment;
33
import org.bukkit.entity.Player;
34
import org.bukkit.event.Listener;
35
import org.bukkit.util.Vector;
36
37
import java.util.*;
38
39
public class Speed extends MovementCheck implements Listener {
40
41
    //I legit hate this game's movement.
42
    //Do you realize how much easier it would be if
43
    //the server handled movement?
44
45
    //TODO False flag with pistons
46
47
    //Basically, this check is doing, "if your previous speed was X then your current speed must not exceed f(X)"
48
49
    private static final double EPSILON = 0.000001;
50
    //Now what we can do is predict how far a player could have travelled
51
    //if the move doesn't have a deltaPos due to insignificance.
52
    private static final double MAX_NO_MOVE_DISTANCE = 0.03;
53
    private final double DISCREPANCY_THRESHOLD;
54
    private final double VL_FAIL_DISCREPANCY_FACTOR;
55
    private final boolean RESET_DISCREPANCY_ON_FAIL;
56
    private final int RELEASE_ITEM_OVER_VL;
57
    private final boolean CHECK_FLYING;
58
    private final boolean DEBUG;
59
60
    private final Map<UUID, Double> prevSpeed;
61
    private final Map<UUID, Double> discrepancies;
62
    private final Map<UUID, Integer> noMovesMap;
63
    private final Map<UUID, Double> lastNegativeDiscrepancies;
64
    private final Map<UUID, Double> negativeDiscrepanciesCumulative;
65
    private final Map<UUID, Integer> slotSwitchQuirkTicksMap; //I hate this game.
66
    private final Map<UUID, Long> lastSlotSwitchTickMap;
67
68
    public Speed() {
69
        super("speed", true, 0, 5, 0.99, 5000, "%player% failed movement speed, VL: %vl%", null);
70
        prevSpeed = new HashMap<>();
71
        discrepancies = new HashMap<>();
72
        noMovesMap = new HashMap<>();
73
        lastNegativeDiscrepancies = new HashMap<>();
74
        negativeDiscrepanciesCumulative = new HashMap<>();
75
        slotSwitchQuirkTicksMap = new HashMap<>();
76
        lastSlotSwitchTickMap = new HashMap<>();
77
        DISCREPANCY_THRESHOLD = (double) customSetting("discrepancyThreshold", "", 0.1D);
78
        VL_FAIL_DISCREPANCY_FACTOR = (double) customSetting("vlFailDiscrepancyFactor", "", 10D);
79
        RESET_DISCREPANCY_ON_FAIL = (boolean) customSetting("resetDiscrepancyOnFail", "", true);
80
        RELEASE_ITEM_OVER_VL = (int) customSetting("releaseItemOverVl", "", 4);
81
        CHECK_FLYING = (boolean) customSetting("checkFlying", "", true);
82
        DEBUG = (boolean) customSetting("debug", "", false);
83
    }
84
85
    @Override
86
    protected void check(MoveEvent event) {
87
        Player p = event.getPlayer();
88
        HawkPlayer pp = event.getHawkPlayer();
89
90
        int noMoves = noMovesMap.getOrDefault(p.getUniqueId(), 0);
91
        double lastSpeed;
92
        double speed;
93
        if(event.isUpdatePos()) {
94
            lastSpeed = prevSpeed.getOrDefault(p.getUniqueId(), 0D);
95
            if(noMoves > 0) {
96
                //Players don't update position unless they've moved at least 0.03 blocks (or if 20 ticks passed)
97
                lastSpeed = Math.min(lastSpeed, MAX_NO_MOVE_DISTANCE);
98
            }
99
            speed = MathPlus.distance2d(event.getTo().getX() - event.getFrom().getX(), event.getTo().getZ() - event.getFrom().getZ());
100
        }
101
        else {
102
            speed = prevSpeed.getOrDefault(p.getUniqueId(), 0D) - (lastNegativeDiscrepancies.getOrDefault(p.getUniqueId(), 0D) + EPSILON);
103
            lastSpeed = speed;
104
        }
105
106
        if(event.isUpdatePos())
107
            noMoves = 0;
108
        else
109
            noMoves++;
110
111
        boolean flying = pp.isFlying();
112
        boolean swimming = pp.isInWater(); //this needs improvement
113
        //it is possible that the player has pressed the jump key even if this move is "stepped" (only while sprinting)
114
        boolean jump = event.isJump() || (event.isStep() && pp.isOnGround() && pp.isSprinting());
115
116
        float friction = event.getFriction();
117
        float maxForce = event.getMaxExpectedInputForce();
118
        float maxForceNoItemUse = event.getMaxExpectedInputForceNoItemUse();
119
120
        //It represents the previous location. Block collision is done after moving the entity.
121
        Set<Material> touchedBlocks = WrappedEntity.getWrappedEntity(p).getCollisionBox(event.getFrom().toVector()).getMaterials(pp.getWorld());
122
123
        //handle any pending knockbacks
124
        if(event.hasAcceptedKnockback() || (flying && !CHECK_FLYING)) {
125
            prepareNextMove(pp, noMoves, speed, touchedBlocks);
126
            return;
127
        }
128
129
        double lastSpeedCompare = lastSpeed;
130
        //Handle other things in the game that multiply velocity.
131
        //These affect velocity first (coincidentally, these are all multiplication operations)
132
        double handleMultipliers = 1;
133
        if(event.hasHitSlowdown())
134
            handleMultipliers *= 0.6;
135
        if(touchedBlocks.contains(Material.SOUL_SAND) && !flying)
136
            handleMultipliers *= 0.4;
137
        if(touchedBlocks.contains(Material.WEB) && !flying)
138
            handleMultipliers *= 0.25;
139
        if(Hawk.getServerVersion() > 7 && touchedBlocks.contains(Material.SLIME_BLOCK)) {
140
            //TODO I believe webs affect this mot Y too.
141
            if (Math.abs(pp.getVelocity().getY()) < 0.1 && !pp.isSneaking()) {
142
                handleMultipliers *= 0.4 + Math.abs(pp.getVelocity().getY()) * 0.2;
143
            }
144
        }
145
        //Handle other things in the game that add to velocity.
146
        //These affect velocity later (coincidentally, these are all addition operations)
147
        double handleAdders = 0;
148
        if(pp.isSprinting() && jump) {
149
            handleAdders += 0.2;
150
        }
151
        if(swimming && !flying) { //This is actually a terrible way of handling horizontal water flow.
152
            Vector move = new Vector(event.getTo().getX() - event.getFrom().getX(), 0, event.getTo().getZ() - event.getFrom().getZ());
153
            Vector waterForce = event.getWaterFlowForce().clone().setY(0);
154
            double waterForceLength = waterForce.length() + 0.003; //add epsilon to allow room for error
155
            double moveLength = move.length();
156
            double computedForce = moveLength == 0 ? waterForceLength : (move.dot(waterForce) / moveLength);
157
158
            handleAdders += computedForce;
159
        }
160
161
        //Finally, the expected speed calculation. There's another "expected" because of a dumb quirk when switching slots while using an item.
162
        //Optimize later.
163
        double expected = friction * lastSpeedCompare * handleMultipliers + (maxForce + handleAdders + EPSILON);
164
        double expectedNoItemUse = friction * lastSpeedCompare * handleMultipliers + (maxForceNoItemUse + handleAdders + EPSILON);
165
166
        //I hate this game. Handle slot switching quirk. The slot switch packet is delayed by a tick.
167
        //This sort of "event listening" must be done because Hawk's MoveEvents can be skipped under certain conditions.
168
        long slotSwitchTick = pp.getLastSlotSwitchTick();
169
        boolean switchedSlot = slotSwitchTick != lastSlotSwitchTickMap.getOrDefault(p.getUniqueId(), slotSwitchTick);
170
        int slotSwitchQuirkTicks = slotSwitchQuirkTicksMap.getOrDefault(p.getUniqueId(), 0);
171
        if(switchedSlot) {
172
            slotSwitchQuirkTicks = 0;
173
        }
174
        lastSlotSwitchTickMap.put(p.getUniqueId(), slotSwitchTick);
175
176
        //Calculate discrepancy.
177
        Discrepancy discrepancy; //This is the one that will be used for final comparison. It is the value of either discrepancyBase or discrepancyNoItemUse.
178
        Discrepancy discrepancyBase; //Used for pretty much 99.99% of moves.
179
        Discrepancy discrepancyNoItemUse; //Similar to discrepancyBase, but doesn't consider item-use slowdown.
180
181
        discrepancyBase = new Discrepancy(expected, speed);
182
        discrepancyNoItemUse = new Discrepancy(expectedNoItemUse, speed);
183
        if((pp.isBlocking() || pp.isConsumingItem() || pp.isPullingBow()) && Math.abs(discrepancyNoItemUse.value) < Math.abs(discrepancyBase.value)) {
184
            //This means that they're using an item, but they're moving at normal speed. This COULD be due to that
185
            //dumb item switch quirk, so we'll grant them only one extra tick. It resets when they switch their slot.
186
            if(slotSwitchQuirkTicks < 1) {
187
                //Allow them to move at normal speed for 1 tick.
188
                discrepancy = discrepancyNoItemUse;
189
                slotSwitchQuirkTicks++;
190
            } else {
191
                discrepancy = discrepancyBase;
192
            }
193
        } else {
194
            discrepancy = discrepancyBase;
195
        }
196
197
        //Client told server that it updated its position. Checking time.
198
        if (event.isUpdatePos()) {
199
            double haltDistanceExpected = negativeDiscrepanciesCumulative.getOrDefault(p.getUniqueId(), 0D);
200
            lastNegativeDiscrepancies.put(p.getUniqueId(), 0D);
201
            if(discrepancy.value < 0 || speed > haltDistanceExpected)
202
                discrepancies.put(p.getUniqueId(), Math.max(discrepancies.getOrDefault(p.getUniqueId(), 0D) + discrepancy.value, 0));
203
            double totalDiscrepancy = discrepancies.getOrDefault(p.getUniqueId(), 0D);
204
205
            if(DEBUG) {
206
                p.sendMessage((totalDiscrepancy > DISCREPANCY_THRESHOLD ? ChatColor.RED : ChatColor.GREEN) + "" + totalDiscrepancy);
207
            }
208
209
            if(discrepancy.value > 0 && totalDiscrepancy > DISCREPANCY_THRESHOLD && !event.isPossiblePistonPush()) {
210
                punishAndTryRubberband(pp, discrepancy.value * VL_FAIL_DISCREPANCY_FACTOR, event);
211
                if(RESET_DISCREPANCY_ON_FAIL)
212
                    discrepancies.put(p.getUniqueId(), 0D);
213
                if(RELEASE_ITEM_OVER_VL > -1 && (pp.isPullingBow() || pp.isConsumingItem() || pp.isBlocking()) && pp.getVL(this) > RELEASE_ITEM_OVER_VL)
214
                    pp.releaseItem();
215
            }
216
            else {
217
                reward(pp);
218
            }
219
220
            lastNegativeDiscrepancies.put(p.getUniqueId(), 0D);
221
            negativeDiscrepanciesCumulative.put(p.getUniqueId(), 0D);
222
        }
223
        //Client sent a flying packet, but didn't update position.
224
        //The move might have not been significant enough, so we need
225
        //to prepare for when the client decides it's time to update
226
        //position.
227
        else {
228
            lastNegativeDiscrepancies.put(p.getUniqueId(), discrepancy.value);
229
230
            //TODO improve these two lines...
231
            double val = negativeDiscrepanciesCumulative.getOrDefault(p.getUniqueId(), 0D);
232
            negativeDiscrepanciesCumulative.put(p.getUniqueId(), Math.min(val + speed, MAX_NO_MOVE_DISTANCE + speed));
233
            //negativeDiscrepanciesCumulative.put(p.getUniqueId(), negativeDiscrepanciesCumulative.getOrDefault(p.getUniqueId(), 0D) + speed);
234
        }
235
236
        slotSwitchQuirkTicksMap.put(p.getUniqueId(), slotSwitchQuirkTicks);
237
        prepareNextMove(pp, noMoves, speed, touchedBlocks);
238
    }
239
240
    private void prepareNextMove(HawkPlayer pp, int noMoves, double currentSpeed, Set<Material> touchedBlocks) {
241
        if(touchedBlocks.contains(Material.WEB) && !pp.isFlying()) {
242
            currentSpeed = 0;
243
        }
244
        UUID uuid = pp.getUuid();
245
        prevSpeed.put(uuid, currentSpeed);
246
        noMovesMap.put(uuid, noMoves);
247
    }
248
249
    public void removeData(Player p) {
250
        UUID uuid = p.getUniqueId();
251
        prevSpeed.remove(uuid);
252
        discrepancies.remove(uuid);
253
        noMovesMap.remove(uuid);
254
        lastNegativeDiscrepancies.remove(uuid);
255
        negativeDiscrepanciesCumulative.remove(uuid);
256
        slotSwitchQuirkTicksMap.remove(uuid);
257
        lastSlotSwitchTickMap.remove(uuid);
258
    }
259
260
    //speed potions do not affect swimming
261
    private Discrepancy waterMapping(double lastSpeed, double currentSpeed, double waterFlowForce) {
262
        double expected = 0.800001 * lastSpeed + 0.020001 + waterFlowForce;
263
        return new Discrepancy(expected, currentSpeed);
264
    }
265
266
    private Discrepancy lavaMapping(double lastSpeed, double currentSpeed) {
267
        double expected = 0.500001 * lastSpeed + 0.020001;
268
        return new Discrepancy(expected, currentSpeed);
269
    }
270
271
    private class Discrepancy {
272
273
        double value;
274
275
        Discrepancy(double expectedSpeed, double currentSpeed) {
276
            value = currentSpeed - expectedSpeed;
277
        }
278
279
    }
280
}

How it counteracts this module

Hawk's Speed check rebuilds the allowed horizontal motion per MoveEvent and punishes deltas that exceed the envelope for the player's movement mode, through the standard punish-and-rubberband path with reward decay. It is the horizontal speed bound for Hawk's movement package.

NoRotate changes no position data: it cancels the EventServerSetYawAndPitch handler, so the client keeps its own yaw and pitch after a server teleport, but the player's coordinates and velocity are exactly what the vanilla client would report. The horizontal deltas stay inside the envelope and the check passes regardless of the module's state. It remains in the countering set because rotation-cancel is commonly paired with movement cheats whose horizontal deltas do breach the envelope, and Hawk's rubberband then re-teleports the player through the very S08 stream NoRotate is trimming.

The boundary is the module's design: NoRotate defeats only the teleport rotation, never the teleport position, so a speed module running alongside still gets rubberbanded to the server's position on every violation. This check has no rotation-consistency component, so it cannot see the cancel either way.

anticheat EntityActionAdapter (C0B state feed)

EntityActionAdapter.java101 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.net.protocollib;
16
17
import java.util.Arrays;
18
import java.util.LinkedList;
19
import java.util.List;
20
21
import org.bukkit.entity.Player;
22
import org.bukkit.plugin.Plugin;
23
24
import com.comphenix.protocol.PacketType;
25
import com.comphenix.protocol.events.ListenerPriority;
26
import com.comphenix.protocol.events.PacketEvent;
27
import com.comphenix.protocol.reflect.StructureModifier;
28
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerAction;
29
30
import fr.neatmonster.nocheatplus.checks.CheckType;
31
import fr.neatmonster.nocheatplus.checks.net.NetConfig;
32
import fr.neatmonster.nocheatplus.checks.net.NetData;
33
import fr.neatmonster.nocheatplus.checks.net.ToggleFrequency;
34
import fr.neatmonster.nocheatplus.logging.StaticLog;
35
import fr.neatmonster.nocheatplus.players.DataManager;
36
import fr.neatmonster.nocheatplus.players.IPlayerData;
37
38
/**
39
 * Adapter for the EntityAction NMS packet.
40
 */
41
public class EntityActionAdapter extends BaseAdapter {
42
    
43
    private final ToggleFrequency toggleFrequency = new ToggleFrequency();
44
    
45
    private static PacketType[] initPacketTypes() {
46
        final List<PacketType> types = new LinkedList<PacketType>(Arrays.asList(PacketType.Play.Client.ENTITY_ACTION));
47
        return types.toArray(new PacketType[types.size()]);
48
    }
49
50
    public EntityActionAdapter(Plugin plugin) {
51
        super(plugin, ListenerPriority.LOW, initPacketTypes());
52
    }
53
    
54
    @Override
55
    public void onPacketReceiving(final PacketEvent event) {
56
        // Do some early return tests first.
57
        try {
58
            if (event.isPlayerTemporary()) return;
59
        } 
60
        catch (NoSuchMethodError e) {}
61
        
62
        // Not interested in any other packet.
63
        if (event.getPacketType() != PacketType.Play.Client.ENTITY_ACTION) {
64
            return;
65
        }
66
        final Player player = event.getPlayer();
67
        if (player == null) {
68
            counters.add(ProtocolLibComponent.idNullPlayer, 1);
69
            return;
70
        }
71
        
72
        final IPlayerData pData = DataManager.getPlayerDataSafe(player);
73
        if (pData == null) {
74
            StaticLog.logWarning("Failed to fetch player data with " + event.getPacketType() + " for: " + player.toString());
75
            return;
76
        }
77
        final StructureModifier<PlayerAction> actions = event.getPacket().getPlayerActions();
78
        // if (actions.size() != 1) {
79
        //     StaticLog.logWarning("Unexpected packet size for EntityActionAdapter: " + actions.size());
80
        //     return;
81
        // }
82
       
83
        final NetData data = pData.getGenericInstance(NetData.class);
84
        // (This check might invalidate the current BedLeave implementation...)
85
        // Currently, we don't discern action types from one another.
86
        data.playerActionFreq.add(System.currentTimeMillis(), 1f);
87
        // Always set last received time.
88
        data.lastKeepAliveTime = System.currentTimeMillis();
89
        boolean cancel = false;
90
        if (!cancel && pData.isCheckActive(CheckType.NET_TOGGLEFREQUENCY, player)
91
            && toggleFrequency.check(player, data, pData.getGenericInstance(NetConfig.class), pData)
92
            && !pData.hasBypass(CheckType.NET_TOGGLEFREQUENCY, player)) {
93
            cancel = true;
94
        }
95
        
96
        // Request a setback
97
        if (cancel) {
98
        	data.requestSetBack(player, this, plugin, checkType);
99
        }
100
    }
101
}

How it counteracts this module

EntityActionAdapter is the ProtocolLib bridge in NCPCompatProtocolLib that converts serverbound C0BPacketEntityAction packets into the entity-action state the net checks consume: sprint and sneak toggles are validated and translated into player state before the movement pipeline reads them. It is part of the net package's packet handling rather than a standalone flagging check.

NoRotate never emits a C0B packet: the module's single event branch cancels EventServerSetYawAndPitch and touches nothing else, so the adapter's input stream is identical whether the module is on or off. The sneak and sprint state it maintains is therefore as trustworthy for a NoRotate user as for any other player, and the movement checks that read that state keep working.

The boundary: the adapter has no view of S08 rotation at all, because rotation is delivered through the position-look teleport, not through entity actions. It is included here as the net-side state feed that remains fully effective for the companion modules; the rotation cancel itself is outside every check in this entry list.

← Back to Analysis Hub