LiquidSense Dev AutoBow module 2 files, 108 lines

LiquidSense Dev AutoBow: Full Source Analysis

LiquidSense's AutoBow fires the bow the instant the draw reaches full charge.

net/ccbluex/liquidbounce/features/module/modules/combat/AutoBow.kt · GitHub source ↗

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

Packets This Module Uses

Analysis

Overview

LiquidSense's AutoBow fires the bow the instant the draw reaches full charge. The single UpdateEvent handler checks that the player is using an item, that the held item is a bow, and that itemInUseDuration has crossed the 20-tick full-charge mark; when all three hold it calls stopUsingItem() and sends C07PacketPlayerDigging RELEASE_USE_ITEM at BlockPos.ORIGIN facing DOWN, which makes the server release the charge and launch the arrow along the player's current look. One BoolValue, WaitForBowAimbot (default on), couples the module to the BowAimbot sibling: while that module is enabled the release is additionally gated on bowAimbot.hasTarget(), so shots only leave while the aimbot reports a visible locked target. The module has no timing jitter and emits no C02PacketUseEntity of its own; its entire wire footprint is one C07 release per draw.

Release logic

onUpdate is the whole module. The guard is mc.thePlayer.isUsingItem, the held item being Items.bow, and itemInUseDuration > 20. itemInUseDuration counts the ticks the draw has been running, and 20 ticks is exactly where the vanilla charge factor (j = duration, folded through (f*f + 2f) / 3 capped at 1.0) reaches full power, so the release always fires a maximum-charge arrow. stopUsingItem() runs the client-side onPlayerStoppedUsing, and the wire trigger is the C07PacketPlayerDigging with Action.RELEASE_USE_ITEM at BlockPos.ORIGIN with EnumFacing.DOWN; the server clears the use state on that packet and launches the arrow along the look it last received, which is why the module only needs the one packet. Nothing randomizes the release: every draw that satisfies the guard ends on the exact tick the charge completes.

WaitForBowAimbot coupling

The gate is (!waitForBowAimbot || !bowAimbot.state || bowAimbot.hasTarget()). With the default settings (WaitForBowAimbot true, BowAimbot enabled) the release is deferred until bowAimbot.hasTarget() is true, which is the aimbot's own last-aimed-entity check: target != null plus a fresh canEntityBeSeen ray trace against the client's world. The module therefore inherits the aimbot's target selection and sight filter: it only fires while a visible, client-side-valid enemy is locked. With BowAimbot disabled or the wait switch off it fires on the plain 20-tick condition. Either way, every shot that leaves under the default configuration coincides with an actively aimed draw.

Wire footprint

Per draw the module sends exactly one packet, the C07 release; the arrow damage arrives later as server-side projectile hits, not as C02PacketUseEntity. The only other traffic it participates in is the C03 family: while BowAimbot is active the movement packets carry the faceBow rotations computed each tick, and when FastBow is active the same release path is fed by FastBow's per-tick re-arm cycle. On its own the module adds nothing to the movement stream, which is what makes it the least visible of the bow modules: a server sees a release at minimum charge, which is a fast but legal draw.

source AutoBow.kt (module logic)

AutoBow.kt35 lines · JavaOriginal ↗
1
/*
2
 * LiquidBounce Hacked Client
3
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
4
 * https://github.com/CCBlueX/LiquidBounce/
5
 */
6
package net.ccbluex.liquidbounce.features.module.modules.combat
7
8
import net.ccbluex.liquidbounce.LiquidBounce
9
import net.ccbluex.liquidbounce.event.EventTarget
10
import net.ccbluex.liquidbounce.event.UpdateEvent
11
import net.ccbluex.liquidbounce.features.module.Module
12
import net.ccbluex.liquidbounce.features.module.ModuleCategory
13
import net.ccbluex.liquidbounce.features.module.ModuleInfo
14
import net.ccbluex.liquidbounce.value.BoolValue
15
import net.minecraft.init.Items
16
import net.minecraft.network.play.client.C07PacketPlayerDigging
17
import net.minecraft.network.play.client.C07PacketPlayerDigging.Action
18
import net.minecraft.util.BlockPos
19
import net.minecraft.util.EnumFacing
20
21
@ModuleInfo(name = "AutoBow", description = "Automatically shoots an arrow whenever your bow is fully loaded.", category = ModuleCategory.COMBAT)
22
class AutoBow : Module() {
23
    private val waitForBowAimbot = BoolValue("WaitForBowAimbot", true)
24
25
    @EventTarget
26
    fun onUpdate(event: UpdateEvent) {
27
        val bowAimbot = LiquidBounce.moduleManager[BowAimbot::class.java] as BowAimbot
28
29
        if (mc.thePlayer.isUsingItem && mc.thePlayer.heldItem?.item == Items.bow &&
30
                mc.thePlayer.itemInUseDuration > 20 && (!waitForBowAimbot.get() || !bowAimbot.state || bowAimbot.hasTarget())) {
31
            mc.thePlayer.stopUsingItem()
32
            mc.netHandler.addToSendQueue(C07PacketPlayerDigging(Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN))
33
        }
34
    }
35
}

What this file does

The file is a single @EventTarget onUpdate handler plus the WaitForBowAimbot BoolValue. Reading it from the value declaration down shows the full surface: one switch that decides whether the release waits for the aimbot, and one guard expression that combines the using-item state, the bow check, the 20-tick charge check and the aimbot gate. The module reaches into the module manager once per update to fetch the BowAimbot instance, which is the only cross-module dependency; everything else is vanilla player state (isUsingItem, heldItem, itemInUseDuration) and one packet send. There is no enable/disable logic, no timer, and no configuration beyond the single value, so the entire module is the guard plus the C07 send.

source BowAimbot.kt (WaitForBowAimbot gate)

BowAimbot.kt73 lines · JavaOriginal ↗
1
/*
2
 * LiquidBounce Hacked Client
3
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
4
 * https://github.com/CCBlueX/LiquidBounce/
5
 */
6
package net.ccbluex.liquidbounce.features.module.modules.combat
7
8
import net.ccbluex.liquidbounce.event.EventTarget
9
import net.ccbluex.liquidbounce.event.Render3DEvent
10
import net.ccbluex.liquidbounce.event.UpdateEvent
11
import net.ccbluex.liquidbounce.features.module.Module
12
import net.ccbluex.liquidbounce.features.module.ModuleCategory
13
import net.ccbluex.liquidbounce.features.module.ModuleInfo
14
import net.ccbluex.liquidbounce.utils.EntityUtils
15
import net.ccbluex.liquidbounce.utils.RotationUtils
16
import net.ccbluex.liquidbounce.utils.render.RenderUtils
17
import net.ccbluex.liquidbounce.value.BoolValue
18
import net.ccbluex.liquidbounce.value.FloatValue
19
import net.ccbluex.liquidbounce.value.ListValue
20
import net.minecraft.entity.Entity
21
import net.minecraft.entity.EntityLivingBase
22
import net.minecraft.item.ItemBow
23
import java.awt.Color
24
25
@ModuleInfo(name = "BowAimbot", description = "Automatically aims at players when using a bow.", category = ModuleCategory.COMBAT)
26
class BowAimbot : Module() {
27
    private val silentValue = BoolValue("Silent", true)
28
    private val predictValue = BoolValue("Predict", true)
29
    private val throughWallsValue = BoolValue("ThroughWalls", false)
30
    private val predictSizeValue = FloatValue("PredictSize", 2F, 0.1F, 5F)
31
    private val priorityValue = ListValue("Priority", arrayOf("Health", "Distance", "Direction"), "Direction")
32
    private val markValue = BoolValue("Mark", true)
33
34
    private var target: Entity? = null
35
36
    override fun onDisable() {
37
        target = null
38
    }
39
40
    @EventTarget
41
    fun onUpdate(event: UpdateEvent) {
42
        target = null
43
44
        if (mc.thePlayer.itemInUse?.item is ItemBow) {
45
            val entity = getTarget(throughWallsValue.get(), priorityValue.get()) ?: return
46
47
            target = entity
48
            RotationUtils.faceBow(target, silentValue.get(), predictValue.get(), predictSizeValue.get())
49
        }
50
    }
51
52
    @EventTarget
53
    fun onRender3D(event: Render3DEvent) {
54
        if (target != null && !priorityValue.get().equals("Multi", ignoreCase = true) && markValue.get())
55
            RenderUtils.drawPlatform(target, Color(37, 126, 255, 70))
56
    }
57
58
    private fun getTarget(throughWalls: Boolean, priorityMode: String): Entity? {
59
        val targets = mc.theWorld.loadedEntityList.filter {
60
            it is EntityLivingBase && EntityUtils.isSelected(it, true) &&
61
                    (throughWalls || mc.thePlayer.canEntityBeSeen(it))
62
        }
63
64
        return when (priorityMode.toUpperCase()) {
65
            "DISTANCE" -> targets.minBy { mc.thePlayer.getDistanceToEntity(it) }
66
            "DIRECTION" -> targets.minBy { RotationUtils.getRotationDifference(it) }
67
            "HEALTH" -> targets.minBy { (it as EntityLivingBase).health }
68
            else -> null
69
        }
70
    }
71
72
    fun hasTarget() = target != null && mc.thePlayer.canEntityBeSeen(target)
73
}

What this file does

The coupling target of AutoBow's default configuration. hasTarget() is the method AutoBow polls before releasing: it returns true only while the aimbot holds a target reference from its last UpdateEvent pass and that entity is still visible through a fresh client-side ray trace. The file also shows where the target comes from: getTarget filters the loaded entity list through EntityUtils.isSelected(entity, true), which composes the client's AntiBot, NoHurt, NoFriends, spectator and Teams filters, and then picks the priority winner (Health, Distance or Direction). AutoBow's release therefore fires only when this module has a client-side-valid enemy locked, and the rotations that accompany the shot are the faceBow angles this module computed.

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 AimbotConvergence (fixed convergence point)

AimbotConvergence.java84 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.look;
20
21
import me.islandscout.hawk.HawkPlayer;
22
import me.islandscout.hawk.check.CustomCheck;
23
import me.islandscout.hawk.event.Event;
24
import me.islandscout.hawk.event.MoveEvent;
25
import me.islandscout.hawk.util.*;
26
import org.bukkit.entity.Player;
27
import org.bukkit.util.Vector;
28
29
import java.util.*;
30
31
public class AimbotConvergence extends CustomCheck {
32
33
    //You better turn off your aimbot when your opponent is standing still!
34
    //Flags basic aimbots that update rotation before motion updates
35
36
    private Map<UUID, Vector> lastConvergencePointMap;
37
38
    public AimbotConvergence() {
39
        super("aimbotconvergence", true, -1, 5, 0.999, 5000, "%player% failed aimbot (convergence), VL: %vl%", null);
40
        this.lastConvergencePointMap = new HashMap<>();
41
    }
42
43
    @Override
44
    protected void check(Event event) {
45
        if(event instanceof MoveEvent) {
46
            MoveEvent e = (MoveEvent) event;
47
            HawkPlayer pp = e.getHawkPlayer();
48
            if(!e.hasDeltaPos())
49
                return;
50
            UUID uuid = pp.getUuid();
51
            Vector prePos = e.getFrom().toVector().clone().subtract(pp.getVelocity()).add(new Vector(0, 1.62, 0));
52
            Vector postPos = e.getFrom().toVector().add(new Vector(0, 1.62, 0));
53
            Vector preDir = e.getFrom().getDirection();
54
            Vector postDir = e.getTo().getDirection();
55
            Pair<Vector, Vector> points = new Ray(prePos, preDir).closestPointsBetweenLines(new Ray(postPos, postDir));
56
57
            Vector lastConvergence = lastConvergencePointMap.get(uuid);
58
            Vector convergence = points.getKey().add(points.getValue()).multiply(0.5);
59
60
            if(lastConvergence != null &&
61
                    //make sure TPs don't false this check
62
                    pp.getCurrentTick() - pp.getLastTeleportAcceptTick() > ServerUtils.getPing(e.getPlayer()) / 50 + 10 &&
63
                    pp.getCurrentTick() > 100) {
64
65
                double distance = lastConvergence.distanceSquared(convergence);
66
                if(!Double.isNaN(distance)) {
67
68
                    if(distance < 0.00000001) //TODO convergence point should be some distance away from head position to filter some falses
69
                        punish(pp, false, e);
70
                    else
71
                        reward(pp);
72
73
                }
74
            }
75
76
            lastConvergencePointMap.put(uuid, convergence);
77
        }
78
    }
79
80
    @Override
81
    public void removeData(Player p) {
82
        lastConvergencePointMap.remove(p.getUniqueId());
83
    }
84
}

How it counteracts this module

AimbotConvergence intersects the look rays of consecutive movement updates and punishes a convergence point that does not move. On every MoveEvent with a position delta it builds the pre-move ray (from position minus velocity, plus eye height) and the post-move ray, finds the closest points between the two lines, and compares the midpoint against the previous midpoint; when the squared distance is under 1e-8 the aim is treated as locked on a fixed world point and the player is punished. Teleports are excluded and the check only arms after tick 100.\n\nThis is a direct hit on the default AutoBow configuration, where every release is gated on BowAimbot. faceBow re-aims the target every tick while the draw runs, so while the shooter strafes during the draw the rays from successive positions all converge on the same target point and the convergence distance stays at zero. The check's own comment warns exactly about this class: 'You better turn off your aimbot when your opponent is standing still'. Standing-still draws emit no position deltas, so the check never arms against a stationary shooter, and a moving target shifts the convergence point with it and passes; the deterministic minimum-charge release itself is not what this check sees.

anticheat AimbotPrecision (pitch-delta GCD)

AimbotPrecision.java132 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.look;
20
21
import me.islandscout.hawk.HawkPlayer;
22
import me.islandscout.hawk.check.Cancelless;
23
import me.islandscout.hawk.check.MovementCheck;
24
import me.islandscout.hawk.event.MoveEvent;
25
import me.islandscout.hawk.util.Debug;
26
import me.islandscout.hawk.util.MathPlus;
27
import org.bukkit.ChatColor;
28
import org.bukkit.entity.Player;
29
30
import java.util.*;
31
32
/**
33
 * The AimbotPrecision check detects aim-bots by
34
 * checking for variation in head pitch precision.
35
 * It does this by solving the greatest common divisor
36
 * of the samples. All pitch changes should be divisible
37
 * by a constant, which is determined by the in-game
38
 * mouse sensitivity. Not compatible with cinematic
39
 * camera mode.
40
 *
41
 * The main issue with this approach to detecting aimbots
42
 * (besides cinematic camera mode) is its unreliability
43
 * at high client framerates. Because rotation is updated
44
 * per frame, there can be multiple rotation updates per
45
 * tick. Every time a new delta yaw/pitch is added to the
46
 * current rotation, there is precision loss due to the
47
 * arithmetic involved. These errors can add up very quickly,
48
 * ultimately causing the GCD algorithm to fail and
49
 * produce false-positives.
50
 */
51
public class AimbotPrecision extends MovementCheck implements Cancelless {
52
53
    //This concept could be used to determine someone's in-game sensitivity.
54
    //That's pretty spoopy if you ask me.
55
56
    //Inspired by https://www.spigotmc.org/threads/killaura-detection.143226/page-17#post-2821779
57
58
    private final Map<UUID, List<Float>> deltaPitches;
59
    private final Map<UUID, Float> lastDeltaPitchGCDs;
60
61
    private final int SAMPLES;
62
    private final float PITCHRATE_LIMIT;
63
64
    public AimbotPrecision() {
65
        super("aimbotprecision", false, -1, 5, 0.9, 5000, "%player% failed aimbot (precision), VL: %vl%", null);
66
        SAMPLES = (int)customSetting("samples", "", 10);
67
        PITCHRATE_LIMIT = (float)((double)customSetting("ignorePitchrateHigherThan", "", 0.96D));
68
        this.deltaPitches = new HashMap<>();
69
        this.lastDeltaPitchGCDs = new HashMap<>();
70
    }
71
72
    @Override
73
    protected void check(MoveEvent e) {
74
        HawkPlayer pp = e.getHawkPlayer();
75
        UUID uuid = pp.getUuid();
76
        float deltaPitch = e.getTo().getPitch() - e.getFrom().getPitch();
77
        List<Float> lastDeltaPitches = deltaPitches.getOrDefault(uuid, new ArrayList<>());
78
79
        //ignore if deltaPitch is 0 or >= 10 or if pitch is +/-90.
80
        if(deltaPitch != 0 && Math.abs(deltaPitch) <= PITCHRATE_LIMIT && Math.abs(e.getTo().getPitch()) != 90) {
81
            lastDeltaPitches.add(Math.abs(deltaPitch));
82
        }
83
84
        //Only check for pitch
85
        //For some reason when you spin your head around too much,
86
        //yaw checking becomes unreliable. Precision errors?
87
        //Still, this check is pretty impressive.
88
        if(lastDeltaPitches.size() >= SAMPLES) {
89
90
            float deltaPitchGCD = MathPlus.gcdRational(lastDeltaPitches);
91
            float gcdDiff = Math.abs(deltaPitchGCD - lastDeltaPitchGCDs.getOrDefault(uuid, deltaPitchGCD));
92
93
            if(gcdDiff > 0.001) {
94
95
                //Assuming sens didn't change, add last GCD in our delta pitches
96
                //just in case we didn't collect enough samples to compute the same GCD.
97
                //Try again. Mathematically, the GCD should remain the same.
98
                if(lastDeltaPitchGCDs.containsKey(uuid)) {
99
                    float lastDeltaPitchGCD = lastDeltaPitchGCDs.get(uuid);
100
                    if(lastDeltaPitchGCD > 0.001) {
101
                        lastDeltaPitches.add(lastDeltaPitchGCD);
102
                        deltaPitchGCD = MathPlus.gcdRational(lastDeltaPitches);
103
                        gcdDiff = Math.abs(deltaPitchGCD - lastDeltaPitchGCDs.getOrDefault(uuid, deltaPitchGCD));
104
                    }
105
                }
106
            }
107
108
            //if GCD is practically unsolvable
109
            if(deltaPitchGCD < 0.00001) {
110
                fail(pp, e);
111
            }
112
            else
113
                reward(pp);
114
115
            lastDeltaPitches.clear();
116
            lastDeltaPitchGCDs.put(uuid, deltaPitchGCD);
117
        }
118
119
        deltaPitches.put(uuid, lastDeltaPitches);
120
    }
121
122
    private void fail(HawkPlayer pp, MoveEvent e) {
123
        punish(pp, false, e);
124
    }
125
126
    @Override
127
    public void removeData(Player p) {
128
        UUID uuid = p.getUniqueId();
129
        deltaPitches.remove(uuid);
130
        lastDeltaPitchGCDs.remove(uuid);
131
    }
132
}

How it counteracts this module

AimbotPrecision collects the pitch deltas of consecutive moves and solves their greatest common divisor. A human's pitch changes are quantized by the in-game mouse sensitivity, so all deltas share a GCD; a computed aim produces continuous arbitrary deltas whose GCD is unsolvable, and the check fails the player when the GCD drops below 1e-5. It ignores zero deltas, deltas above the 0.96 pitch-rate limit, and pitches at exactly +/-90.\n\nfaceBow's pitch comes from the closed-form arrow-trajectory solution (atan of the ballistic equation with the charge-velocity factor), so while a target moves or the shooter strafes, the per-tick pitch deltas are floating-point derivatives of that formula - exactly the unsolvable-GCD profile. The same caveats apply as with the convergence check: a perfectly still target produces a zero pitch delta that the check skips, and the module's own 20-tick release timing contributes nothing to the look stream. The check is what catches the aim the release depends on, not the release itself.

anticheat Angle (attack-stream rotation deltas)

Angle.java255 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.fight;
16
17
import java.util.Iterator;
18
import java.util.LinkedList;
19
import java.util.List;
20
import java.util.UUID;
21
22
import org.bukkit.ChatColor;
23
import org.bukkit.Location;
24
import org.bukkit.entity.Entity;
25
import org.bukkit.entity.Player;
26
27
import fr.neatmonster.nocheatplus.actions.ParameterName;
28
import fr.neatmonster.nocheatplus.checks.Check;
29
import fr.neatmonster.nocheatplus.checks.CheckType;
30
import fr.neatmonster.nocheatplus.checks.ViolationData;
31
import fr.neatmonster.nocheatplus.permissions.Permissions;
32
import fr.neatmonster.nocheatplus.players.IPlayerData;
33
import fr.neatmonster.nocheatplus.utilities.StringUtil;
34
import fr.neatmonster.nocheatplus.utilities.TickTask;
35
import fr.neatmonster.nocheatplus.utilities.math.TrigUtil;
36
37
/**
38
 * A check used to verify if the player isn't using a forcefield in order to attack multiple entities at the same time.
39
 * 
40
 * Thanks @asofold for the original idea!
41
 */
42
public class Angle extends Check {
43
  
44
45
  private final List<String> tags = new LinkedList<String>();
46
47
48
    public static class AttackLocation {
49
        public final double x, y, z;
50
        /** Yaw of the attacker. */
51
        public final float yaw;
52
        public long time;
53
        public final UUID damagedId;
54
        /** Squared distance to the last location (0 if none given). */
55
        public final double distSqLast;
56
        /** Difference in yaw to the last location (0 if none given). */
57
        public final double yawDiffLast;
58
        /** Time difference to the last location (0 if none given). */
59
        public final long timeDiff;
60
        /** If the id differs from the last damaged entity (true if no lastLoc is given). */
61
        public final boolean idDiffLast;
62
        public AttackLocation(final Location loc, final UUID damagedId, final long time, final AttackLocation lastLoc) {
63
            x = loc.getX();
64
            y = loc.getY();
65
            z = loc.getZ();
66
            yaw = loc.getYaw();
67
            this.time = time;
68
            this.damagedId = damagedId;
69
70
            if (lastLoc != null) {
71
                distSqLast = TrigUtil.distanceSquared(x, y, z, lastLoc.x, lastLoc.y, lastLoc.z);
72
                yawDiffLast = TrigUtil.yawDiff(yaw, lastLoc.yaw);
73
                timeDiff = Math.max(0L, time - lastLoc.time);
74
                idDiffLast = !damagedId.equals(lastLoc.damagedId);
75
            } 
76
            else {
77
                distSqLast = 0.0;
78
                yawDiffLast = 0f;
79
                timeDiff = 0L;
80
                idDiffLast = true;
81
            }
82
        }
83
    }
84
    
85
    /** Used to also monitor lag-time */
86
    public static long maxTimeDiff = 1000L;
87
88
89
    /**
90
     * Instantiates a new angle check.
91
     */
92
    public Angle() {
93
        super(CheckType.FIGHT_ANGLE);
94
    }
95
96
97
    /**
98
     * The Angle check.
99
     * @param player
100
     * @param loc Location of the player.
101
     * @param worldChanged
102
     * @param data
103
     * @param cc
104
     * @return
105
     */
106
    public boolean check(final Player player, final Location loc, 
107
                         final Entity damagedEntity, final boolean worldChanged, 
108
                         final FightData data, final FightConfig cc, final IPlayerData pData) {
109
110
        if (worldChanged) {
111
            data.angleHits.clear();
112
        }
113
114
        boolean cancel = false;
115
        tags.clear();
116
117
        // Quick check for expiration of all entries.
118
        final long time = System.currentTimeMillis();
119
        AttackLocation lastLoc = data.angleHits.isEmpty() ? null : data.angleHits.getLast();
120
        if (lastLoc != null && time - lastLoc.time > maxTimeDiff) {
121
            data.angleHits.clear();
122
            lastLoc = null;
123
        }
124
125
        // Add the new location.
126
        data.angleHits.add(new AttackLocation(loc, damagedEntity.getUniqueId(), System.currentTimeMillis(), lastLoc));
127
128
        // Calculate the sums of differences.
129
        double deltaMove = 0D;
130
        long deltaTime = 0L;
131
        float deltaYaw = 0f;
132
        int deltaSwitchTarget = 0;
133
        final Iterator<AttackLocation> it = data.angleHits.iterator();
134
        while (it.hasNext()) {
135
            final AttackLocation refLoc = it.next();
136
            if (time - refLoc.time > maxTimeDiff) {
137
                it.remove();
138
                continue;
139
            }
140
            deltaMove += refLoc.distSqLast;
141
            final double yawDiff = Math.abs(refLoc.yawDiffLast);
142
            deltaYaw += yawDiff;
143
            deltaTime += refLoc.timeDiff;
144
            if (refLoc.idDiffLast && yawDiff > 30.0) {
145
                // TODO: Configurable sensitivity ? Scale with yawDiff?
146
                deltaSwitchTarget += 1;
147
            }
148
        }
149
150
        // Check if there is enough data present.
151
        if (data.angleHits.size() < 2) {
152
            return false;
153
        }
154
155
        final double n = (double) (data.angleHits.size() - 1);
156
157
        // Let's calculate the average move.
158
        double averageMove = deltaMove / n;
159
        // Adjust to server-sided lag
160
        averageMove *= TickTask.getLag(maxTimeDiff, true);
161
162
        // And the average time elapsed.
163
        double averageTime = (double) deltaTime / n;
164
        // Adjust to server-sided lag
165
        averageTime *= TickTask.getLag(maxTimeDiff, true);
166
167
        // And the average yaw delta.
168
        double averageYaw = (double) deltaYaw / n;
169
        // Adjust to server-sided lag
170
        averageYaw /= TickTask.getLag(maxTimeDiff, true);
171
172
        // Average target switching.
173
        double averageSwitching = (double) deltaSwitchTarget / n;
174
        // Adjust to server-sided lag
175
        averageSwitching /= TickTask.getLag(maxTimeDiff, true);
176
177
        // Declare the variables.
178
        double violation = 0.0;
179
        double violationMove = 0.0;
180
        double violationTime = 0.0;
181
        double violationYaw = 0.0;
182
        double violationSwitchSpeed = 0.0;
183
184
        // If the average move is between 0 and 0.2 block(s), add it to the violation.
185
        if (averageMove >= 0.0 && averageMove < 0.2D) {
186
            violationMove += 20.0 * (0.2 - averageMove) / 0.2;
187
            tags.add("avgmove");
188
            if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
189
                player.sendMessage(ChatColor.RED + "NC+ Debug: " + ChatColor.RESET + "avgMove: " + averageMove + " avgMove VL: " + violationMove + "/" + cc.angleMove);
190
            }
191
        }
192
193
        // If the average time elapsed is between 0 and 150 millisecond(s), add it to the violation.
194
        if (averageTime >= 0.0 && averageTime < 150.0) {
195
            violationTime += 30.0 * (150.0 - averageTime) / 150.0;
196
            tags.add("avgtime");
197
            if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
198
                player.sendMessage(ChatColor.RED + "NC+ Debug: " + ChatColor.RESET + "avgTime: " + averageTime + " avgTime VL: " + violationTime + "/" + cc.angleTime);
199
            }
200
        }
201
202
        // If the average difference of yaw is superior to 50 degrees, add it to the violation.
203
        if (averageYaw > 50.0) {
204
            violationYaw += 30.0 * averageYaw / 180.0;
205
            tags.add("avgyaw");
206
            if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
207
                player.sendMessage(ChatColor.RED + "NC+ Debug: " + ChatColor.RESET + "avgYaw: " + averageYaw + " avgYaw VL: " + violationYaw + "/" + cc.angleYaw);
208
            }
209
        }
210
        
211
        // Check for too quick target switch speed
212
        if (averageSwitching > 0.0) {
213
            violationSwitchSpeed += 20.0 * averageSwitching;
214
            tags.add("switchspeed");
215
            if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
216
                player.sendMessage(ChatColor.RED + "NC+ Debug: " + ChatColor.RESET + "avgSwitch: " + averageSwitching + " avgSwitch VL: " + violationSwitchSpeed + "/" + cc.angleSwitch);
217
            }
218
        }
219
220
221
        if (violationMove > cc.angleMove) {
222
            violation = violationMove;
223
            data.angleVL += violation;
224
            final ViolationData vd = new ViolationData(this, player, data.angleVL, violation, cc.angleActions);
225
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
226
            cancel = executeActions(vd).willCancel();
227
        }
228
        else if (violationTime > cc.angleTime) {
229
            violation = violationTime;
230
            data.angleVL += violation;
231
            final ViolationData vd = new ViolationData(this, player, data.angleVL, violation, cc.angleActions);
232
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
233
            cancel = executeActions(vd).willCancel();
234
        }
235
        else if (violationYaw > cc.angleYaw) {
236
            violation = violationYaw;
237
            data.angleVL += violation;
238
            final ViolationData vd = new ViolationData(this, player, data.angleVL, violation, cc.angleActions);
239
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
240
            cancel = executeActions(vd).willCancel();
241
        } 
242
        else if (violationSwitchSpeed > cc.angleSwitch) {
243
            violation = violationSwitchSpeed;
244
            data.angleVL += violation;
245
            final ViolationData vd = new ViolationData(this, player, data.angleVL, violation, cc.angleActions);
246
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
247
            cancel = executeActions(vd).willCancel();
248
        } 
249
        else {
250
            // Reward the player by lowering their violation level.
251
            data.angleVL *= 0.98D;  
252
        }
253
        return cancel;
254
    }
255
}

How it counteracts this module

NCP's fight.Angle keeps a rolling list of AttackLocation entries - position, yaw, timestamp, target id - for every C02 attack and scores four averages across the window: movement between attacks (avgmove, flagged below 0.2 blocks), time between attacks (avgtime, flagged under 150ms), yaw change (avgyaw, flagged above 50 degrees) and target-switch speed (switchspeed, any switch with a yaw jump over 30 degrees), each folded through the configured thresholds and accumulated into angleVL with cancel actions.\n\nAutoBow never emits a C02, so the check cannot fire on the shot itself; its relevance is the attack stream around the shots. The LiquidSense play pattern the module enables is a bow shot at minimum charge followed by a melee attack, and when the paired BowAimbot is active the same scripted rotation that aimed the arrow is still being applied when the follow-up C02 leaves - the low-movement, tightly-timed attack cadence scores avgmove and avgtime. The honest caveat is the stock configuration: the per-call scores stay far below the default move/time/yaw/switch thresholds (100, 150, 60, 50), so the check is dormant until an admin tunes it down - the same caveat that applies to every fight check against this module family.

anticheat UseItemAdapter (release-item rate gate)

UseItemAdapter.java438 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.GameMode;
22
import org.bukkit.Material;
23
import org.bukkit.entity.HumanEntity;
24
import org.bukkit.entity.Player;
25
import org.bukkit.event.Event;
26
import org.bukkit.event.EventHandler;
27
import org.bukkit.event.EventPriority;
28
import org.bukkit.event.block.Action;
29
import org.bukkit.event.entity.PlayerDeathEvent;
30
import org.bukkit.event.inventory.InventoryOpenEvent;
31
import org.bukkit.event.player.PlayerInteractEvent;
32
import org.bukkit.event.player.PlayerItemConsumeEvent;
33
import org.bukkit.event.player.PlayerItemHeldEvent;
34
import org.bukkit.event.player.PlayerRespawnEvent;
35
import org.bukkit.event.player.PlayerRiptideEvent;
36
import org.bukkit.inventory.EquipmentSlot;
37
import org.bukkit.inventory.ItemStack;
38
import org.bukkit.inventory.meta.CrossbowMeta;
39
import org.bukkit.plugin.Plugin;
40
41
import com.comphenix.protocol.PacketType;
42
import com.comphenix.protocol.events.ListenerPriority;
43
import com.comphenix.protocol.events.PacketContainer;
44
import com.comphenix.protocol.events.PacketEvent;
45
import com.comphenix.protocol.reflect.StructureModifier;
46
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType;
47
48
import fr.neatmonster.nocheatplus.NCPAPIProvider;
49
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
50
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
51
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
52
import fr.neatmonster.nocheatplus.compat.Bridge1_13;
53
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
54
import fr.neatmonster.nocheatplus.compat.bukkit.BridgeEnchant;
55
import fr.neatmonster.nocheatplus.compat.bukkit.BridgeMaterial;
56
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
57
import fr.neatmonster.nocheatplus.compat.versions.ClientVersion;
58
import fr.neatmonster.nocheatplus.compat.versions.ServerVersion;
59
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
60
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
61
import fr.neatmonster.nocheatplus.event.mini.MiniListener;
62
import fr.neatmonster.nocheatplus.logging.StaticLog;
63
import fr.neatmonster.nocheatplus.players.DataManager;
64
import fr.neatmonster.nocheatplus.players.IPlayerData;
65
import fr.neatmonster.nocheatplus.utilities.entity.InventoryUtil;
66
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
67
import fr.neatmonster.nocheatplus.utilities.map.MaterialUtil;
68
69
/**
70
 * <p>Adapter for listening to packets and Bukkit events relevant to item use.</p>
71
 *
72
 * On versions 1.17 and above, the adapter will only register events related to a specific item-use exploit, 
73
 * as Bukkit provides the {@link HumanEntity#getItemInUse()} method.<br>
74
 *
75
 * <p>On versions 1.12 and above, up to 1.17, all listeners will be registered because Bukkit does not offer a way to 
76
 * determine <em>which</em> item is in use; we can only detect if a player is using an item through {@link HumanEntity#isHandRaised()}.</p>
77
 *
78
 * The {@link PlayerRespawnEvent} is always listened to in order to fix a specific item desynchronization issue.
79
 */
80
public class UseItemAdapter extends BaseAdapter {
81
    
82
    private final static String dftag = "system.nocheatplus.useitemadapter";
83
        
84
    // All relevant Bukkit events for item-use.
85
    private final static MiniListener<?>[] miniListeners = new MiniListener<?>[] {
86
        new MiniListener<PlayerItemConsumeEvent>() {
87
            @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
88
            @RegisterMethodWithOrder(tag = dftag)
89
            @Override
90
            public void onEvent(final PlayerItemConsumeEvent event) {
91
                onItemConsume(event);
92
            }
93
        },
94
        new MiniListener<PlayerInteractEvent>() {
95
            @EventHandler(priority = EventPriority.MONITOR)
96
            @RegisterMethodWithOrder(tag = dftag)
97
            @Override
98
            public void onEvent(final PlayerInteractEvent event) {
99
                onItemInteract(event);
100
            }
101
        },
102
        new MiniListener<InventoryOpenEvent>() {
103
            @EventHandler(priority = EventPriority.LOWEST)
104
            @RegisterMethodWithOrder(tag = dftag)
105
            @Override
106
            public void onEvent(final InventoryOpenEvent event) {
107
                onInventoryOpen(event);
108
            }
109
        },
110
        new MiniListener<PlayerDeathEvent>() {
111
            @EventHandler(priority = EventPriority.MONITOR)
112
            @RegisterMethodWithOrder(tag = dftag)
113
            @Override
114
            public void onEvent(final PlayerDeathEvent event) {
115
                onDeath(event);
116
            }
117
        },
118
        new MiniListener<PlayerItemHeldEvent>() {
119
            @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
120
            @RegisterMethodWithOrder(tag = dftag)
121
            @Override
122
            public void onEvent(final PlayerItemHeldEvent event) {
123
                onChangeSlot(event);
124
            }
125
        },
126
    };
127
128
    private static int timeBetweenRL = 70;
129
130
    private static PacketType[] initPacketTypes() {
131
        // Only interested in these two packets.
132
        final List<PacketType> types = new LinkedList<PacketType>(Arrays.asList(PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.BLOCK_PLACE));
133
        return types.toArray(new PacketType[types.size()]);
134
    }
135
136
    public UseItemAdapter(Plugin plugin) {
137
        super(plugin, ListenerPriority.MONITOR, initPacketTypes());
138
        final NoCheatPlusAPI api = NCPAPIProvider.getNoCheatPlusAPI();
139
        if (!BridgeMisc.hasGetItemInUseMethod()) {
140
            // getItemInUse() isn't there, register all events
141
            if (Bridge1_13.hasPlayerRiptideEvent()) {
142
                // Only register this one if available.
143
                final MiniListener<?> riptideListener = new MiniListener<PlayerRiptideEvent>() {
144
                    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
145
                    @RegisterMethodWithOrder(tag = dftag)
146
                    @Override
147
                    public void onEvent(final PlayerRiptideEvent event) {
148
                        onTridentRelease(event);
149
                   }
150
                };
151
                api.addComponent(riptideListener, false);
152
            }
153
            // ...All the other listeners
154
            for (final MiniListener<?> listener : miniListeners) {
155
                api.addComponent(listener, false);
156
            }
157
        }
158
        // Always register this event, because it is used to fix an MC/Bukkit glitch, not for item-use setting.
159
        final MiniListener<?> respawningListener = new MiniListener<PlayerRespawnEvent>() {
160
            @EventHandler(priority = EventPriority.MONITOR)
161
            @RegisterMethodWithOrder(tag = dftag)
162
            @Override
163
            public void onEvent(final PlayerRespawnEvent event) {
164
                onRespawning(event);
165
            }
166
        };
167
        api.addComponent(respawningListener, false);
168
    }
169
170
    @Override
171
    public void onPacketReceiving(final PacketEvent event) {
172
        // Fast return tests first.
173
        try {
174
            if (event.isPlayerTemporary()) return;
175
        } 
176
        catch (NoSuchMethodError e) {
177
            if (event.getPlayer() == null) {
178
                counters.add(ProtocolLibComponent.idNullPlayer, 1);
179
                return;
180
            }
181
            if (DataManager.getPlayerDataSafe(event.getPlayer()) == null) {
182
                StaticLog.logWarning("Failed to fetch player data with " + event.getPacketType() + " for: " + event.getPlayer().toString());
183
                return;
184
            }
185
        }
186
        if (BridgeMisc.hasGetItemInUseMethod()) {
187
            // getItemInUse() is already there. Only check the digging packet for exploitation prevention purposes.
188
            if (event.getPacketType().equals(PacketType.Play.Client.BLOCK_DIG)) {
189
                handleDiggingPacket(event);
190
            }
191
            // Don't need to do anything else.
192
            return;
193
        }
194
        
195
        // getItemInUse() ins't there: do the ordinary stuff.
196
        if (event.getPacketType().equals(PacketType.Play.Client.BLOCK_DIG)) {
197
            handleDiggingPacket(event);
198
        }
199
        else handleBlockPlacePacket(event);
200
    }
201
    
202
    /** Attempt to fix server-side-only blocking after respawn. */
203
    private static void onRespawning(final PlayerRespawnEvent e) {
204
        final IPlayerData pData = DataManager.getPlayerData(e.getPlayer());
205
        // Patch up issues on Bukkit's (Minecraft's ?) side (item has been reset already on death).
206
        if (Bridge1_9.hasGetItemInOffHand() && e.getPlayer().isBlocking()) {
207
            pData.requestItemUseResync();
208
        }
209
    }
210
211
    private static void onTridentRelease(final PlayerRiptideEvent e) {
212
        final IPlayerData pData = DataManager.getPlayerData(e.getPlayer());
213
        // This event is called on releasing the trident (See ItemTrident.java), so the item is not in use anymore.
214
        pData.setItemInUse(null);
215
    }
216
217
    private static void onItemConsume(final PlayerItemConsumeEvent e) {
218
        final Player p = e.getPlayer();
219
        final IPlayerData pData = DataManager.getPlayerData(p);
220
        // Consume(d) (!!), so the player isn't using the item anymore
221
        pData.setItemInUse(null);   
222
    }
223
224
    private static void onInventoryOpen(final InventoryOpenEvent e) {
225
        if (e.isCancelled()) return;
226
        final Player p = (Player) e.getPlayer();
227
        final IPlayerData pData = DataManager.getPlayerData(p);
228
        // Can't use item with an inventory open.
229
        pData.setItemInUse(null);
230
    }
231
232
    private static void onDeath(final PlayerDeathEvent e) {
233
        final IPlayerData pData = DataManager.getPlayerData((Player) e.getEntity());
234
        // Can't use item if dead
235
        pData.setItemInUse(null);  
236
    }
237
238
    @SuppressWarnings("deprecation")
239
	private static void onItemInteract(final PlayerInteractEvent e) {
240
        if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) {
241
            return;
242
        }
243
        final Player p = e.getPlayer();
244
        final IPlayerData pData = DataManager.getPlayerData(p);
245
        final MovingConfig mCC = pData.getGenericInstance(MovingConfig.class);
246
        final CombinedData data = pData.getGenericInstance(CombinedData.class);
247
        data.offHandUse = false;
248
        if (!data.mightUseItem) {
249
            // Player did not send the block-placement packet, so they are for sure not using anything, return.
250
            return;
251
        }
252
        // Do reset the flag at the start (!)
253
        data.mightUseItem = false;
254
255
        if (e.useItemInHand().equals(Event.Result.DENY)) {
256
            // A plugin denied the item-use.
257
            return;
258
        }
259
260
        if (p.getGameMode() == GameMode.CREATIVE) {
261
            // TODO: If merging SurvivalFly and CreativeFly, creative mode needs to be taken into consideration as well.
262
            pData.setItemInUse(null);
263
            return;
264
        }
265
        
266
        // Proceed to check...
267
        if (e.hasItem()) {
268
            final ItemStack item = e.getItem();
269
            final Material m = item.getType();
270
            if (Bridge1_9.hasElytra() && p.hasCooldown(m)) {
271
                // Item is in cooldown so it cannot be used.
272
                return;
273
            }
274
            
275
            // Edible / consumable items...
276
            if (InventoryUtil.isConsumable(item)) {
277
                if (!Bridge1_9.hasElytra() && item.getDurability() > 16384) {
278
                    // pre1.9 splash potion edge case.
279
                    return;
280
                }
281
                if (m == Material.POTION || m == Material.MILK_BUCKET || m.toString().endsWith("_APPLE") || m.name().startsWith("HONEY_BOTTLE")) {
282
                    // Can be consumed regardless of hunger level
283
                    pData.setItemInUse(m);
284
                    data.offHandUse = Bridge1_9.hasGetItemInOffHand() && e.getHand() == EquipmentSlot.OFF_HAND;
285
                    return;
286
                }
287
                if (item.getType().isEdible() && p.getFoodLevel() < 20) {
288
                    // Hunger level dependant consumables.
289
                    pData.setItemInUse(m); 
290
                    data.offHandUse = Bridge1_9.hasGetItemInOffHand() && e.getHand() == EquipmentSlot.OFF_HAND;
291
                    return;
292
                }
293
            }
294
            // Bows...
295
            if (m == Material.BOW && InventoryUtil.hasArrow(p.getInventory(), false)) {
296
                pData.setItemInUse(m);
297
                data.offHandUse = Bridge1_9.hasGetItemInOffHand() && e.getHand() == EquipmentSlot.OFF_HAND;
298
                return;
299
            }
300
            // Shields and swords (legacy)... Bukkit takes care here, but set anyway.
301
            if (ServerVersion.isAtLeast("1.9") && pData.getClientVersion().isAtLeast(ClientVersion.V_1_9)) {
302
                // Both server and client are on a version that support shield (thus, sword-blocking is not possible)
303
            	if (m == Material.SHIELD) {
304
            	    pData.setItemInUse(m);
305
                    data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
306
                    return;
307
            	}
308
            }
309
            else if (MaterialUtil.isSword(m) && (ServerVersion.isLowerThan("1.9") || pData.getClientVersion().isAtMost(ClientVersion.V_1_8))) {
310
            	// Legacy server. Or legacy client on a modern server. Blocking is done with swords in both cases.
311
            	pData.setItemInUse(m);
312
            	// (Off hand doesn't exist)
313
            	return;
314
            }
315
            
316
            // Crosswbows...
317
            if (m.toString().equals("CROSSBOW")) {
318
                if (!((CrossbowMeta) item.getItemMeta()).hasChargedProjectiles() && InventoryUtil.hasArrow(p.getInventory(), true)) {
319
                    pData.setItemInUse(m);
320
                    data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
321
                }
322
            }
323
            // Tridents (1.13)... 
324
            if (m == BridgeMaterial.TRIDENT && item.getDurability() < m.getMaxDurability() - 1 && pData.getClientVersion().isAtLeast(ClientVersion.V_1_13)
325
            	&& (
326
                    // 1: If the trident has riptide enchant, it can only be used in rain or water 
327
            		BridgeEnchant.getRiptideLevel(p) > 0.0
328
                    && (
329
                        // 2: In water
330
                        BlockProperties.isInWater(p, p.getLocation(), mCC.yOnGround)
331
                        // 2: Always check raining first, since canSeeSky is a much more expensive call. Needs optimization.
332
                        || p.getLocation().getWorld().hasStorm() && BlockProperties.canSeeSky(p, p.getLocation(), mCC.yOnGround) 
333
                    ) 
334
                    // 1: Otherwise, the trident can be used and thrown anywhere
335
                    || BridgeEnchant.getRiptideLevel(p) <= 0.0
336
                )) {
337
                pData.setItemInUse(m);
338
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
339
                return;
340
            }
341
            // Spyglass (1.17)...
342
            if (BridgeMisc.hasIsFrozen() && m == Material.SPYGLASS) {
343
                pData.setItemInUse(m);
344
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
345
                return;
346
            }
347
            // Lastly, goat horns (1.19)...
348
            if (m.toString().equals("GOAT_HORN")) {
349
                pData.setItemInUse(m);
350
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
351
                return;
352
            }
353
            // 1.21.11: Spears...
354
            if (MaterialUtil.isSpear(m)) {
355
                pData.setItemInUse(m);
356
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
357
            }
358
        } 
359
        else {
360
            // No item in hands, no deal.
361
            pData.setItemInUse(null);  
362
        }
363
    }
364
    
365
    // NOTE: Bukkit takes care of invalid slot values (< 0 or > 8. PlayerConnection.java), so we don't need to check for this as well.
366
    private static void onChangeSlot(final PlayerItemHeldEvent e) {
367
        final Player p = e.getPlayer();
368
        final IPlayerData pData = DataManager.getPlayerData(p);
369
        // Switching a slot, so the item use status is reset.
370
        final MovingData mData = pData.getGenericInstance(MovingData.class);
371
        final CombinedData cData = pData.getGenericInstance(CombinedData.class);
372
        if (e.getPreviousSlot() != e.getNewSlot()) {
373
            /*if ((pData.getItemInUse() != null || p.isBlocking()) && mData.playerMoves.getCurrentMove() != null) {
374
                p.getInventory().setHeldItemSlot(e.getPreviousSlot());
375
                cData.invalidItemUse = true;
376
            }*/
377
            // To avoid any more potential bypasses, let Minecraft forcibly release the item.
378
            pData.requestItemUseResync();
379
        }
380
    }
381
382
    private void handleBlockPlacePacket(PacketEvent event) {
383
        final Player p = event.getPlayer();
384
        final IPlayerData pData = DataManager.getPlayerData(p);
385
        final CombinedData data = pData.getGenericInstance(CombinedData.class);
386
        final PacketContainer packet = event.getPacket();
387
        final StructureModifier<Integer> ints = packet.getIntegers();
388
        // Legacy: pre 1.9
389
        if (ints.size() > 0 && !ServerVersion.isAtLeast("1.9")) {
390
            final int faceIndex = ints.read(0); // arg 3 if 1.7.10 below
391
            if (faceIndex <= 5) {
392
                data.mightUseItem = false;
393
                return;
394
            }
395
        }
396
        // Player sends a block-placement item when right-clicking, so they might be actually using an item. Set the flag.
397
        if (!event.isCancelled()) data.mightUseItem = true;
398
    }
399
400
    private void handleDiggingPacket(PacketEvent event) {
401
        Player p = event.getPlayer();       
402
        final IPlayerData pData = DataManager.getPlayerDataSafe(p);
403
        final CombinedData data = pData.getGenericInstance(CombinedData.class);
404
        PlayerDigType digtype = event.getPacket().getPlayerDigTypes().read(0);
405
        if (!BridgeMisc.hasGetItemInUseMethod()) {
406
            // DROP_ALL_ITEMS when dead?
407
            if (digtype == PlayerDigType.DROP_ALL_ITEMS || digtype == PlayerDigType.DROP_ITEM) {
408
                pData.setItemInUse(null);
409
            }
410
        }
411
        
412
        if (digtype == PlayerDigType.RELEASE_USE_ITEM) {
413
            pData.setItemInUse(null);
414
            long now = System.currentTimeMillis();
415
            if (data.releaseItemTime != 0) {
416
                if (now < data.releaseItemTime) {
417
                    data.releaseItemTime = now;
418
                    return;
419
                }
420
                if (data.releaseItemTime + timeBetweenRL > now) {
421
                    data.isHackingRI = true;
422
                }
423
            }
424
            data.releaseItemTime = now;
425
        }
426
    }
427
428
    /**
429
     * Set Minimum time between RELEASE_USE_ITEM packet is sent.
430
     * If time lower this value, A check will flag
431
     * Should be set from 51-100. Larger number, more protection more false-positive
432
     * 
433
     * @param time milliseconds
434
     */ 
435
    public static void setuseRLThreshold(int time) {
436
        timeBetweenRL = time;
437
    }   
438
}

How it counteracts this module

The adapter is NCP's surface on the item-use packet stream. handleDiggingPacket stamps releaseItemTime on every C07 RELEASE_USE_ITEM and sets the isHackingRI flag when a second release arrives within timeBetweenRL of the first, with the threshold defaulting to 70ms; the javadoc states outright that this is a minimum-time-between-releases gate for the rapid-release exploit class. handleBlockPlacePacket tracks the C08 use-item sentinel so the use-state model stays consistent.\n\nAutoBow's own releases are one per full draw - roughly a second apart - so they sit far outside the 70ms window and the gate never trips on the module alone, and no anticheat in the pool carries a bow-charge timer that would see the deterministic 20-tick release. The check matters as the family boundary: the moment AutoBow's release path is combined with FastBow's per-tick re-arm cycle, the same C07 stream starts arriving every 50ms and isHackingRI is set from the second shot onward. That combination is exactly what the WaitForBowAimbot default encourages - an aimed minimum-charge shot every tick - so on an NCP-protected server the module family as configured runs into this gate.

← Back to Analysis Hub