Sigma 4.11 AutoTool module 2 files, 188 lines

Sigma 4.11 AutoTool: Full Source Analysis

Sigma's AutoTool switches to the fastest digging tool while the attack key is held.

info/sigmaclient/module/impl/player/AutoTool.java · GitHub source ↗

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

Analysis

Overview

Sigma's AutoTool switches to the fastest digging tool while the attack key is held. The EventTick handler returns immediately unless keyBindAttack is pressed and the mouse-over carries a block position, then delegates to BlockUtils.updateTool, which scans the nine hotbar slots for the item with the greatest getStrVsBlock against the targeted block and writes inventory.currentItem directly. The module never constructs packets: the C09 held-slot change is emitted by the fork's PlayerControllerMP.syncCurrentPlayItem whenever the tracked slot diverges at the next interaction, and the C07 dig pairs are the vanilla clickBlock stream.

Tool selection

updateTool iterates the hotbar with a strength accumulator that starts at 1.0F and a strictly greater-than comparison, so a bare hand (1.0 strength) never wins and the first slot that beats the current best is kept; ties favor the lowest index. The selection is purely getStrVsBlock against the targeted block state: there is no durability weighting, no enchantment-aware ranking and no silk-touch or fortune logic, so the module picks the raw fastest dig and will happily choose a nearly broken tool over a fresh one.

Wire shape

The write goes through the public currentItem field, and the C09 comes from PlayerControllerMP.syncCurrentPlayItem, which is called at the top of the interaction entry points (clickBlock, onPlayerDamageBlock, onPlayerRightClick and the rest) and emits C09PacketHeldItemChange only when the tracked slot diverges from the field. Because the switch happens while the attack key is held, the C09 lands immediately before the vanilla C07 START and STOP dig pair of the next break, producing the C09(tool), C07 pair, C09(restore) fingerprint around each dig when the player switches back.

Scope and gating

The module is inert while the attack key is released, and it bails when objectMouseOver is null or carries no block position, so it only fires at an actually targeted block. It never touches the inventory window, never ranks armor or offhand state, and has no settings at all: the constructor is empty, which makes the module a pure convenience layer over the vanilla dig path.

source AutoTool.java

AutoTool.java36 lines · JavaOriginal ↗
1
/**
2
 * Time: 1:14:15 AM
3
 * Date: Jan 2, 2017
4
 * Creator: cool1
5
 */
6
package info.sigmaclient.module.impl.player;
7
8
import info.sigmaclient.event.Event;
9
import info.sigmaclient.event.impl.EventTick;
10
import info.sigmaclient.module.data.ModuleData;
11
import info.sigmaclient.util.misc.BlockUtils;
12
import info.sigmaclient.event.RegisterEvent;
13
import info.sigmaclient.module.Module;
14
import net.minecraft.util.BlockPos;
15
16
public class AutoTool extends Module {
17
    public AutoTool(ModuleData data) {
18
        super(data);
19
    }
20
21
    @Override
22
    @RegisterEvent(events = {EventTick.class})
23
    public void onEvent(Event event) {
24
        if (!mc.gameSettings.keyBindAttack.getIsKeyPressed()) {
25
            return;
26
        }
27
        if (mc.objectMouseOver == null) {
28
            return;
29
        }
30
        BlockPos pos = mc.objectMouseOver.getBlockPos();
31
        if (pos == null) {
32
            return;
33
        }
34
        BlockUtils.updateTool(pos);
35
    }
36
}

What this file does

The module file is a thin gate: it returns unless keyBindAttack is pressed, objectMouseOver is non-null and carries a block position, then calls BlockUtils.updateTool(pos) once per tick. There are no settings and no packet construction; the entire mechanism lives in the util it delegates to. The EventTick registration places the handler on the per-tick event fired from EntityPlayer.onUpdate, so the switch is re-evaluated every tick the attack key is held.

The empty constructor and the absence of state make the module's surface easy to bound: it only writes inventory.currentItem, and everything observable on the wire comes from the vanilla interaction path reacting to that write.

source BlockUtils.java (updateTool)

BlockUtils.java152 lines · JavaOriginal ↗
1
package info.sigmaclient.util.misc;
2
3
import info.sigmaclient.management.MoveUtils;
4
import info.sigmaclient.util.MinecraftUtil;
5
import info.sigmaclient.util.NetUtil;
6
import net.minecraft.block.Block;
7
import net.minecraft.block.BlockAir;
8
import net.minecraft.block.BlockLiquid;
9
import net.minecraft.block.material.Material;
10
import net.minecraft.client.Minecraft;
11
import net.minecraft.init.Blocks;
12
import net.minecraft.item.ItemStack;
13
import net.minecraft.network.play.client.C03PacketPlayer;
14
import net.minecraft.util.BlockPos;
15
import net.minecraft.util.MathHelper;
16
17
import java.util.Arrays;
18
import java.util.List;
19
20
public class BlockUtils implements MinecraftUtil {
21
    private static Minecraft mc = Minecraft.getMinecraft();
22
    private static List<Block> blacklistedBlocks;
23
24
    static {
25
        blacklistedBlocks = Arrays.asList(
26
                Blocks.air, Blocks.water, Blocks.flowing_water, Blocks.lava, Blocks.flowing_lava,
27
                Blocks.enchanting_table, Blocks.carpet, Blocks.glass_pane, Blocks.stained_glass_pane, Blocks.iron_bars,
28
                Blocks.snow_layer, Blocks.ice, Blocks.packed_ice, Blocks.coal_ore, Blocks.diamond_ore, Blocks.emerald_ore,
29
                Blocks.chest, Blocks.torch, Blocks.anvil, Blocks.trapped_chest, Blocks.noteblock, Blocks.jukebox, Blocks.tnt,
30
                Blocks.gold_ore, Blocks.iron_ore, Blocks.lapis_ore, Blocks.lit_redstone_ore, Blocks.quartz_ore, Blocks.redstone_ore,
31
                Blocks.wooden_pressure_plate, Blocks.stone_pressure_plate, Blocks.light_weighted_pressure_plate, Blocks.heavy_weighted_pressure_plate,
32
                Blocks.stone_button, Blocks.wooden_button, Blocks.lever);
33
    }
34
35
    /**
36
     * Gets the yaw and pitch required to look at a given block
37
     *
38
     * @param pos
39
     * @return
40
     */
41
    public static float[] getRotationsNeeded(BlockPos pos) {
42
        double diffX = pos.getX() + 0.5 - mc.thePlayer.posX;
43
        double diffY = (pos.getY() + 0.5) - (mc.thePlayer.posY + mc.thePlayer.height);
44
        double diffZ = pos.getZ() + 0.5 - mc.thePlayer.posZ;
45
        double dist = MathHelper.sqrt_double((diffX * diffX) + (diffZ * diffZ));
46
        float yaw = (float) ((Math.atan2(diffZ, diffX) * 180.0D) / 3.141592653589793D) - 90.0F;
47
        float pitch = (float) -((Math.atan2(diffY, dist) * 180.0D) / 3.141592653589793D);
48
        return new float[]{mc.thePlayer.rotationYaw + MathHelper.wrapAngleTo180_float(yaw - mc.thePlayer.rotationYaw), mc.thePlayer.rotationPitch + MathHelper.wrapAngleTo180_float(pitch - mc.thePlayer.rotationPitch)};
49
    }
50
51
    /**
52
     * Updates the player's directions.
53
     */
54
    public static float[] updateDirections(BlockPos pos) {
55
        float[] looks = BlockUtils.getRotationsNeeded(pos);
56
        if (mc.thePlayer.isCollidedVertically) {
57
            NetUtil.sendPacketNoEvents(new C03PacketPlayer.C05PacketPlayerLook(looks[0], looks[1], mc.thePlayer.onGround));
58
        }
59
        return looks;
60
    }
61
62
    /**
63
     * Ensures that the best tool is used for breaking the block.
64
     */
65
    public static void updateTool(BlockPos pos) {
66
        Block block = mc.theWorld.getBlockState(pos).getBlock();
67
        float strength = 1.0F;
68
        int bestItemIndex = -1;
69
        for (int i = 0; i < 9; i++) {
70
            ItemStack itemStack = mc.thePlayer.inventory.mainInventory[i];
71
            if (itemStack == null) {
72
                continue;
73
            }
74
            if ((itemStack.getStrVsBlock(block) > strength)) {
75
                strength = itemStack.getStrVsBlock(block);
76
                bestItemIndex = i;
77
            }
78
        }
79
        if (bestItemIndex != -1) {
80
            mc.thePlayer.inventory.currentItem = bestItemIndex;
81
        }
82
    }
83
84
    // this is darkmagician's. credits to him.
85
    public static boolean isInLiquid() {
86
        if (mc.thePlayer.isInWater()) {
87
            return true;
88
        }
89
        boolean inLiquid = false;
90
        final int y = (int) mc.thePlayer.getEntityBoundingBox().minY;
91
        for (int x = MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().minX); x < MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().maxX) + 1; x++) {
92
            for (int z = MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().minZ); z < MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().maxZ) + 1; z++) {
93
                final Block block = mc.theWorld.getBlockState(new BlockPos(x, y, z)).getBlock();
94
                if (block != null && block.getMaterial() != Material.air) {
95
                    if (!(block instanceof BlockLiquid)) return false;
96
                    inLiquid = true;
97
                }
98
            }
99
        }
100
        return inLiquid;
101
    }
102
103
    // this method is N3xuz_DK's I believe. credits to him.
104
    public static boolean isOnLiquid() {
105
        if (mc.thePlayer == null) return false;
106
        boolean onLiquid = false;
107
        final int y = (int) mc.thePlayer.getEntityBoundingBox().offset(0.0D, -0.01D, 0.0D).minY;
108
        for (int x = MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().minX); x < MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().maxX) + 1; x++) {
109
            for (int z = MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().minZ); z < MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().maxZ) + 1; z++) {
110
                final Block block = mc.theWorld.getBlockState(new BlockPos(x, y, z)).getBlock();
111
                if (block != null && block.getMaterial() != Material.air) {
112
                    if (!(block instanceof BlockLiquid)) return false;
113
                    onLiquid = true;
114
                }
115
            }
116
        }
117
        return onLiquid;
118
    }
119
    public static boolean isOnLiquid(double profondeur)
120
	  {
121
	    boolean onLiquid = false;
122
	    
123
	    if(mc.theWorld.getBlockState(new BlockPos(mc.thePlayer.posX, mc.thePlayer.posY - profondeur, mc.thePlayer.posZ)).getBlock().getMaterial().isLiquid()) {
124
	      onLiquid = true;
125
	    }
126
	    return onLiquid;
127
	  }
128
    public static boolean isTotalOnLiquid(double profondeur)
129
	  {	    
130
	    for(double x = mc.thePlayer.boundingBox.minX; x < mc.thePlayer.boundingBox.maxX; x +=0.01f){
131
	    	
132
			for(double z = mc.thePlayer.boundingBox.minZ; z < mc.thePlayer.boundingBox.maxZ; z +=0.01f){
133
				Block block = mc.theWorld.getBlockState(new BlockPos(x, mc.thePlayer.posY - profondeur,z)).getBlock();
134
    			if(!(block instanceof BlockLiquid) && !(block instanceof BlockAir)){
135
    				return false;
136
    			}
137
    		}
138
		}
139
	    return true;
140
	  }
141
    public static boolean isOnGround(double height) {
142
        if (!mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, mc.thePlayer.getEntityBoundingBox().offset(0.0D, -height, 0.0D)).isEmpty()) {
143
            return true;
144
        } else {
145
            return false;
146
        }
147
    }
148
149
    public static List<Block> getBlacklistedBlocks() {
150
        return blacklistedBlocks;
151
    }
152
}

What this file does

updateTool (lines 65-82) is the selection engine: it reads the targeted block state, walks hotbar slots 0-8 with a strength accumulator starting at 1.0F, keeps the first item whose getStrVsBlock strictly exceeds the current best, and writes inventory.currentItem. The strict greater-than comparison against a 1.0F floor means an empty hand never wins and the first best slot wins ties, a lowest-index bias that is worth knowing because it is what the module actually does, not a weighted ranking.

The same file shows the family's other helpers the module does not use: updateDirections sends a C05 look packet when collided vertically, and the liquid and ground probes are unrelated to tool selection. For AutoTool the file's relevance is exactly updateTool and its write-through to currentItem, which is the hook that makes the fork's syncCurrentPlayItem emit the C09.

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 FastBreak (tool-calibrated break duration)

FastBreak.java135 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.blockbreak;
16
17
import org.bukkit.Material;
18
import org.bukkit.block.Block;
19
import org.bukkit.entity.Player;
20
import org.bukkit.inventory.ItemStack;
21
22
import fr.neatmonster.nocheatplus.actions.ParameterName;
23
import fr.neatmonster.nocheatplus.checks.Check;
24
import fr.neatmonster.nocheatplus.checks.CheckType;
25
import fr.neatmonster.nocheatplus.checks.ViolationData;
26
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
27
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
28
import fr.neatmonster.nocheatplus.compat.bukkit.BridgePotionEffect;
29
import fr.neatmonster.nocheatplus.permissions.Permissions;
30
import fr.neatmonster.nocheatplus.players.IPlayerData;
31
import fr.neatmonster.nocheatplus.utilities.TickTask;
32
import fr.neatmonster.nocheatplus.utilities.entity.PotionUtil;
33
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
34
35
/**
36
 * A check used to verify if the player is breaking blocks faster than possible.
37
 */
38
public class FastBreak extends Check {
39
40
    /**
41
     * Instantiates a new fast break check.
42
     */
43
    public FastBreak() {
44
        super(CheckType.BLOCKBREAK_FASTBREAK);
45
    }
46
47
    /**
48
     * Checks a player for fastbreak. This is NOT for creative mode.
49
     * @return true, if successful
50
     */
51
    public boolean check(final Player player, final Block block, final AlmostBoolean isInstaBreak, final BlockBreakConfig cc, final BlockBreakData data, final IPlayerData pData) {
52
        final long now = System.currentTimeMillis();
53
        boolean cancel = false;
54
        // Determine expected breaking time by block type.
55
        final Material blockType = block.getType();
56
        final long expectedBreakingTime = Math.max(0, Math.round((double) BlockProperties.getBreakingDuration(blockType, player) * (double) cc.fastBreakModSurvival / 100D));
57
        final long elapsedTime;
58
        // Counting interact...break.
59
        // TODO: Concept for unbreakable blocks? Context: extreme VL.
60
        // TODO: Should it be breakingTime instead of 0 for inconsistencies?
61
        elapsedTime = cc.fastBreakStrict ? (data.fastBreakBreakTime > data.fastBreakfirstDamage) ? 0 : now - data.fastBreakfirstDamage
62
                                         // Counting break...break.
63
                                         : (data.fastBreakBreakTime > now) ? 0 : now - data.fastBreakBreakTime;
64
65
        // Check if the time spent is lower than expected.
66
        if (isInstaBreak.decideOptimistically()) {
67
            // Ignore these for now.
68
            // TODO: Find out why this was commented out long ago a) did not fix mcMMO b) exploits.
69
            // TODO: Maybe adjust time to min(time, SOMETHING) for MAYBE/YES.
70
        }
71
        else if (elapsedTime < 0) {
72
            // Ignore it. TODO: ?
73
        }
74
        else if (elapsedTime + cc.fastBreakDelay < expectedBreakingTime) {
75
            // Lag or cheat or Minecraft.
76
            // Count in server side lag, if desired.
77
            final float serverLagFactor = pData.getCurrentWorldDataSafe().shouldAdjustToLag(type) ? TickTask.getLag(expectedBreakingTime, true) : 1f;
78
            final long missingTime = expectedBreakingTime - (long)(serverLagFactor * elapsedTime);
79
            if (missingTime > 0) {
80
                // Add as penalty
81
                data.fastBreakPenalties.add(now, (float) missingTime);
82
                // Only raise a violation, if the total penalty score exceeds the contention duration (for lag, delay).
83
                if (data.fastBreakPenalties.score(cc.fastBreakBucketFactor) > cc.fastBreakGrace) {
84
                    // TODO: maybe add one absolute penalty time for big amounts to stop breaking until then
85
                    final double violation = (double) missingTime / 1000.0;
86
                    data.fastBreakVL += violation;
87
                    final ViolationData vd = new ViolationData(this, player, data.fastBreakVL, violation, cc.fastBreakActions);
88
                    if (vd.needsParameters()) {
89
                        vd.setParameter(ParameterName.BLOCK_TYPE, blockType.toString());
90
                    }
91
                    cancel = executeActions(vd).willCancel();
92
                }
93
                // else: still within contention limits.
94
            }
95
        }
96
        else if (expectedBreakingTime > cc.fastBreakDelay) {
97
            // Fast breaking does not decrease violation level.
98
            data.fastBreakVL *= 0.9D;
99
        }
100
101
        // TODO: Rework to use (then hopefully completed) BlockBreakKey.
102
        if (pData.isDebugActive(type)) {
103
            detailDebugStats(player, isInstaBreak, blockType, elapsedTime, expectedBreakingTime, data, pData);
104
        }
105
        else {
106
            data.stats = null;
107
        }
108
        // (The break time is set in the listener).
109
        return cancel;
110
    }
111
112
    private void detailDebugStats(final Player player, final AlmostBoolean isInstaBreak,
113
                                  final Material blockType, final long elapsedTime, final long expectedBreakingTime,
114
                                  final BlockBreakData data, final IPlayerData pData) {
115
        if (pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
116
            // General stats:
117
            // TODO: Replace stats by new system (BlockBreakKey once complete), commands to inspect / auto-config.
118
            data.setStats();
119
            data.stats.addStats(data.stats.getId(blockType+ "/u", true), elapsedTime);
120
            data.stats.addStats(data.stats.getId(blockType + "/r", true), expectedBreakingTime);
121
            player.sendMessage(data.stats.getStatsStr(true));
122
            // Send info about current break:
123
            final ItemStack stack = Bridge1_9.getItemInMainHand(player);
124
            final boolean isValidTool = BlockProperties.isValidTool(blockType, stack);
125
            final double haste = PotionUtil.getPotionEffectAmplifier(player, BridgePotionEffect.HASTE);
126
            String msg = (isInstaBreak.decideOptimistically() ? ("[Insta=" + isInstaBreak + "]") : "[Normal]") + "[" + blockType + "] "+ elapsedTime + "u / " + expectedBreakingTime +"r (" + (isValidTool?"tool":"no-tool") + ")" + (Double.isInfinite(haste) ? "" : " haste=" + ((int) haste + 1));
127
            player.sendMessage(msg);
128
            //          net.minecraft.server.Item mcItem = net.minecraft.server.Item.byId[stack.getTypeId()];
129
            //          if (mcItem != null) {
130
            //              double x = mcItem.getDestroySpeed(((CraftItemStack) stack).getHandle(), net.minecraft.server.Block.byId[blockId]);
131
            //              player.sendMessage("mc speed: " + x);
132
            //          }
133
        }
134
    }
135
}

How it counteracts this module

FastBreak is NCP's dig-duration check and it is invisible to this module by construction. The expected breaking time comes from BlockProperties.getBreakingDuration, which reads the item in the main hand and walks the full tool table (type, efficiency level, haste and aqua affinity effects, on-ground and in-water penalties), so the check already assumes the player is using the optimal tool for the block. AutoTool's switch makes the client behave exactly like that assumption: the dig completes in the per-tool expected time, elapsed plus the 10ms delay is never below expected, and the fastBreakPenalties bucket never accumulates.

The honest boundary runs the other way: a true fastbreak hack that shortens the dig below the tool-calibrated expectation trips FastBreak immediately, which is why the check is the family's anchor. Against a best-tool switcher it scores nothing, because the module's entire effect is bringing the client's behavior up to the level the check already models as legitimate.

anticheat Frequency (blocks per time frame)

Frequency.java95 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.blockbreak;
16
17
import org.bukkit.GameMode;
18
import org.bukkit.entity.Player;
19
20
import fr.neatmonster.nocheatplus.checks.Check;
21
import fr.neatmonster.nocheatplus.checks.CheckType;
22
import fr.neatmonster.nocheatplus.players.IPlayerData;
23
import fr.neatmonster.nocheatplus.utilities.TickTask;
24
25
/**
26
 * This checks just limits the number of blocks broken per time frame.
27
 * @author asofold
28
 *
29
 */
30
public class Frequency extends Check {
31
32
    public Frequency() {
33
        super(CheckType.BLOCKBREAK_FREQUENCY);
34
    }
35
    
36
    /**
37
     * Checks a player
38
     * @param player
39
     * @param tick
40
     * @param cc
41
     * @param data
42
     * @param pData
43
     * @return true if cancelled.
44
     * 
45
     */
46
    public boolean check(final Player player, final int tick, final BlockBreakConfig cc, final BlockBreakData data, final IPlayerData pData) {
47
        final float interval = player.getGameMode() == GameMode.CREATIVE ? cc.frequencyIntervalCreative : cc.frequencyIntervalSurvival;
48
        data.frequencyBuckets.add(System.currentTimeMillis(), (float)interval);
49
        // Full period frequency.
50
        final float fullScore = data.frequencyBuckets.score(cc.frequencyBucketFactor);
51
        final long fullTime = cc.frequencyBucketDur * cc.frequencyBuckets;
52
        final boolean lag = pData.getCurrentWorldData().shouldAdjustToLag(type);
53
54
        // Short term limit.
55
        if (tick < data.frequencyShortTermTick) {
56
            // Tick task got reset.
57
            data.frequencyShortTermTick = tick;
58
            data.frequencyShortTermCount = 1;
59
        }
60
        else if (tick - data.frequencyShortTermTick < cc.frequencyShortTermTicks) {
61
            // Account for server side lag.
62
            if (!lag || TickTask.getLag(50L * (tick - data.frequencyShortTermTick), true) < 1.5f) {
63
                // Within range, add.
64
                data.frequencyShortTermCount ++;
65
            }
66
            else {
67
                // Too much lag, reset.
68
                data.frequencyShortTermTick = tick;
69
                data.frequencyShortTermCount = 1;
70
            }
71
        }
72
        else {
73
            data.frequencyShortTermTick = tick;
74
            data.frequencyShortTermCount = 1;
75
        }
76
77
        // Account for server side lag for the medium term check
78
        final float fullLag = lag ? TickTask.getLag(fullTime, true) : 1f;
79
        // Find if one or both are violations:
80
        final float fullViolation = (fullScore > fullTime * fullLag) ? (fullScore - fullTime * fullLag) : 0;
81
        final float shortTermWeight = 50f * cc.frequencyShortTermTicks / (float) cc.frequencyShortTermLimit; 
82
        final float shortTermViolation = data.frequencyShortTermCount > cc.frequencyShortTermLimit ? (data.frequencyShortTermCount - cc.frequencyShortTermLimit) * shortTermWeight : 0; 
83
        final float violation = Math.max(fullViolation, shortTermViolation);
84
        boolean cancel = false;
85
        if (violation > 0.0) {
86
            final double change = violation / 1000;
87
            data.frequencyVL += change;
88
            cancel = executeActions(player, data.frequencyVL, change, cc.frequencyActions).willCancel();
89
        }
90
        else if (data.frequencyVL > 0d && fullScore < fullTime * .75) {
91
            data.frequencyVL *= 0.95;
92
        }
93
        return cancel;
94
    }
95
}

How it counteracts this module

Frequency counts break events against time windows rather than dig durations: 2x1000ms ActionFrequency buckets with an interval weight of 45 in survival by default, plus a short-term counter that allows 7 break events inside 5 ticks before flagging. It counts completed breaks, not slot changes, so the module's only contribution to the ledger is the dig cadence itself, which is vanilla: the tool switch adds no break events of its own.

The check would catch a module that multiplied dig rate, but AutoTool leaves the C07 stream at the player's natural click pace. The slot-switch traffic between digs is invisible to Frequency, which is exactly why the family pairing of FastBreak (duration) and Frequency (rate) still leaves the C09 fingerprint to the slot-side checks and the honest gap entry.

anticheat Reach (blockbreak distance)

Reach.java83 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.blockbreak;
16
17
import org.bukkit.GameMode;
18
import org.bukkit.Location;
19
import org.bukkit.block.Block;
20
import org.bukkit.entity.Player;
21
22
import fr.neatmonster.nocheatplus.actions.ParameterName;
23
import fr.neatmonster.nocheatplus.checks.Check;
24
import fr.neatmonster.nocheatplus.checks.CheckType;
25
import fr.neatmonster.nocheatplus.checks.ViolationData;
26
import fr.neatmonster.nocheatplus.utilities.StringUtil;
27
import fr.neatmonster.nocheatplus.utilities.math.TrigUtil;
28
29
/**
30
 * The Reach check will find out if a player breaks a block that's too far away.
31
 */
32
public class Reach extends Check {
33
34
    /** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */
35
    private final Location useLoc = new Location(null, 0, 0, 0);
36
37
    /** The maximum distance allowed to interact with a block in creative mode. */
38
    public static final double CREATIVE_DISTANCE = 5.6D;
39
40
    /** The maximum distance allowed to interact with a block in survival mode. */
41
    public static final double SURVIVAL_DISTANCE = 5.2D;
42
43
    /**
44
     * Instantiates a new reach check.
45
     */
46
    public Reach() {
47
        super(CheckType.BLOCKBREAK_REACH);
48
    }
49
50
    /**
51
     * Checks a player.
52
     * 
53
     * @param player
54
     * @param eyeHeight 
55
     * @param block
56
     * @param data
57
     * @param cc
58
     * @return true, if successful
59
     */
60
    public boolean check(final Player player, final double eyeHeight, final Block block, final BlockBreakData data, final BlockBreakConfig cc) {
61
    	// TODO: Ray tracing-based?
62
        boolean cancel = false;
63
        final double distanceLimit = player.getGameMode() == GameMode.CREATIVE ? CREATIVE_DISTANCE : SURVIVAL_DISTANCE; 
64
        final Location loc = player.getLocation(useLoc);
65
        loc.setY(loc.getY() + eyeHeight);
66
         // Distance is calculated from eye location to center of targeted block.
67
        final double distance = TrigUtil.distance(loc, block) - distanceLimit;
68
        useLoc.setWorld(null);
69
70
        if (distance > distanceLimit) {
71
            // They failed, increment violation level.
72
            data.reachVL += distance - distanceLimit;
73
            // Execute whatever actions are associated with this check and the violation level and find out if we should
74
            // cancel the event.
75
            final ViolationData vd = new ViolationData(this, player, data.reachVL, distance, cc.reachActions);
76
            vd.setParameter(ParameterName.REACH_DISTANCE, StringUtil.fdec3.format(distance));
77
            cancel = executeActions(vd).willCancel();
78
        } 
79
        // Player passed the check, reward them.
80
        else data.reachVL *= 0.9D;
81
        return cancel;
82
    }
83
}

How it counteracts this module

Reach is NCP's blockbreak distance check: it measures the eye-to-block-center distance against 5.2 blocks in survival (5.6 creative) and accumulates excess into the violation value. AutoTool's tool switch grants no reach whatsoever; the player digs from the same position with the same ray that the vanilla path already validated, so the measured distance is identical to a manual dig.

The check matters to the family because some dig helpers move the player or extend the interaction range to reach distant blocks; this module does neither. Reach therefore contributes an honest pass, and its presence in the set documents that the module's surface is the slot switch, not geometry.

anticheat UseItemAdapter (held-slot handler)

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

UseItemAdapter's onChangeSlot handles PlayerItemHeldEvent: on a real slot change it calls requestItemUseResync, which forcibly releases an item in use so a held-slot switch cannot mask an ongoing eat or block. For AutoTool the handler is inert: the switches happen between digs, outside any item use, so there is no in-use state to release, and the resync path never fires.

The entry is the documented gap of the family: no NCP check scores the C09-to-C07 pairing that is AutoTool's actual fingerprint. The slot change is only observable at the protocol level (the C09 before the dig), and NCP's only held-slot hook is the item-use resync, which by design ignores switches that occur while nothing is in use. Servers that want the pairing need a protocol-level switch-and-dig check, which this tree does not ship.

← Back to Analysis Hub