Spicy ChestStealer module 2 files, 186 lines

Spicy ChestStealer: Full Source Analysis

Spicy's ChestStealer drains chests from a background thread.

info/spicyclient/modules/world/ChestStealer.java · GitHub source ↗

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

Analysis

Overview

Spicy's ChestStealer drains chests from a background thread. The client's custom GuiChest fires EventOpenChest PRE in initGui and POST in onGuiClosed; on PRE the module stops whatever previous thread is still alive and starts a fresh one that walks the chest's inventoryRows times 9 slots, sleeps the configured delay plus 0-40ms of random jitter before every non-null slot, and shift-clicks it through spicyHandleMouseInput, which is a one-line pass-through to GuiContainer.handleMouseClick and the source of every C0E mode-1 click. The thread is only ever stopped by the next chest opening, never by the GUI closing, so a drain can keep clicking a stale GuiChest after the window is gone; a C16 re-open trick sits in the source fully commented out.

Thread-per-chest steal loop

chestStealerThread is a static field, so exactly one drain can exist process-wide. EventOpenChest PRE calls thread.stop() on the previous worker (the deprecated API, which terminates the thread mid-sleep) and starts the replacement. The worker iterates the chest's own slots only (inventoryRows times 9, never the player's bottom rows), and for each non-null stack sleeps delay plus a fresh Random().nextInt(40) before clicking. The delay setting spans 0-2000ms with a 250ms default, so the cadence is one shift-click per delay-plus-jitter interval; the jitter is the module's only attempt at humanization and it is a fixed 40ms band on top of a constant delay, which leaves the near-uniform inter-click spacing intact.

The click path

The click is chest.spicyHandleMouseInput(slot, slotNumber, 0, 1): the Spicy GuiChest wrapper exposes GuiContainer.handleMouseClick, and click type 1 is the shift-click that moves the stack to the player inventory, emitted as C0EPacketClickWindow mode 1 against the chest's window id. The module never inspects item values or filters stacks; every non-null slot is drained. A commented-out C16PacketClientStatus(OPEN_INVENTORY_ACHIEVEMENT) inside the loop shows a re-open trick that was removed from the active code, leaving the drain dependent on the chest GUI staying open.

Lifecycle races

The thread starts only on the PRE event. When the player closes the chest, the vanilla GUI path sends C0D close-window and the custom GuiChest fires EventOpenChest POST, which the module ignores: the worker keeps running, sleeping and clicking the stale GuiChest object until its slot loop completes or the next chest opens and thread.stop() kills it. Every click in that window is an interaction against a window the server has already closed, which is the race the Hawk InventoryActions check below punishes.

source ChestStealer.java

ChestStealer.java101 lines · JavaOriginal ↗
1
package info.spicyclient.modules.world;
2
3
import java.util.Random;
4
5
import org.lwjgl.input.Keyboard;
6
7
import info.spicyclient.events.Event;
8
import info.spicyclient.events.listeners.EventMotion;
9
import info.spicyclient.events.listeners.EventOnLadder;
10
import info.spicyclient.events.listeners.EventOpenChest;
11
import info.spicyclient.events.listeners.EventUpdate;
12
import info.spicyclient.modules.Module;
13
import info.spicyclient.settings.ModeSetting;
14
import info.spicyclient.settings.NumberSetting;
15
import net.minecraft.client.gui.inventory.GuiInventory;
16
import net.minecraft.inventory.Slot;
17
import net.minecraft.network.play.client.C16PacketClientStatus;
18
import net.minecraft.network.play.client.C16PacketClientStatus.EnumState;
19
import net.minecraft.util.EnumFacing;
20
import net.minecraft.util.MathHelper;
21
22
public class ChestStealer extends Module {
23
	
24
	public static Thread chestStealerThread = null;
25
	
26
	NumberSetting delay = new NumberSetting("Delay", 250, 0, 2000, 10);
27
	
28
	public ChestStealer() {
29
		super("Chest Stealer", Keyboard.KEY_NONE, Category.WORLD);
30
		resetSettings();
31
	}
32
	
33
	@Override
34
	public void resetSettings() {
35
		settings.clear();
36
		addSettings(delay);
37
	}
38
	
39
	public void onEnable() {
40
		
41
	}
42
	
43
	public void onDisable() {
44
		
45
	}
46
	
47
	public void onEvent(Event e) {
48
		
49
		if (e instanceof EventOpenChest) {
50
			
51
			EventOpenChest chestEvent = (EventOpenChest) e;
52
			
53
			
54
			if (chestStealerThread == null) {
55
				
56
			}else {
57
				chestStealerThread.stop();
58
			}
59
			
60
			chestStealerThread = new Thread(new Runnable() {
61
				
62
				@Override
63
				public void run() {
64
					
65
					try {
66
						
67
						for (int i = 0; i < (chestEvent.chest.inventoryRows * 9); i++) {
68
							Slot slot = (Slot) chestEvent.chest.inventorySlots.inventorySlots.get(i);
69
							if (slot.getStack() != null) {
70
								
71
								try {
72
									Thread.sleep((long) delay.getValue() + new Random().nextInt(40));
73
								}catch (ThreadDeath e) {
74
									e.printStackTrace();
75
								}
76
								
77
				                if (!(mc.currentScreen instanceof GuiInventory)) {
78
				                    //mc.getNetHandler().addToSendQueue(new C16PacketClientStatus(EnumState.OPEN_INVENTORY_ACHIEVEMENT));
79
				                }
80
								
81
								chestEvent.chest.spicyHandleMouseInput(slot, slot.slotNumber, 0, 1);
82
								
83
							}
84
						}
85
						
86
					} catch (Exception e2) {
87
						// TODO: handle exception
88
					}
89
					
90
				}
91
			});
92
			
93
			if (e.isPre()) {
94
				chestStealerThread.start();
95
			}
96
			
97
		}
98
		
99
	}
100
	
101
}

What this file does

The whole module is the EventOpenChest handler and the anonymous worker. onEvent receives the chest event from the custom GuiChest, tears down any previous thread with Thread.stop(), and builds a Runnable that walks chest.inventoryRows times 9 slots, sleeping delay plus a random 0-40ms before each non-null slot and shift-clicking through spicyHandleMouseInput. The static thread field means the drain survives module toggles until the next chest opening replaces it, and the try/catch around the loop swallows ThreadDeath, the exception Thread.stop() throws, which is why a stopped worker leaves no trace.

The disabled C16 re-open inside the loop (commented out) is the only other packet logic: were it active it would re-send OPEN_INVENTORY_ACHIEVEMENT to keep the server-side window alive mid-drain. The onEnable and onDisable overrides are empty, and the Delay NumberSetting is the only setting the module carries.

source GuiChest.java (event hooks and click pass-through)

GuiChest.java85 lines · JavaOriginal ↗
1
package net.minecraft.client.gui.inventory;
2
3
import org.lwjgl.input.Keyboard;
4
5
import info.spicyclient.SpicyClient;
6
import info.spicyclient.events.EventType;
7
import info.spicyclient.events.listeners.EventOpenChest;
8
import net.minecraft.client.Minecraft;
9
import net.minecraft.client.renderer.GlStateManager;
10
import net.minecraft.inventory.ContainerChest;
11
import net.minecraft.inventory.IInventory;
12
import net.minecraft.inventory.Slot;
13
import net.minecraft.util.ResourceLocation;
14
15
public class GuiChest extends GuiContainer
16
{
17
    /** The ResourceLocation containing the chest GUI texture. */
18
    private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("textures/gui/container/generic_54.png");
19
    private IInventory upperChestInventory;
20
    private IInventory lowerChestInventory;
21
22
    /**
23
     * window height is calculated with these values; the more rows, the heigher
24
     */
25
    public int inventoryRows;
26
27
    public GuiChest(IInventory upperInv, IInventory lowerInv)
28
    {
29
        super(new ContainerChest(upperInv, lowerInv, Minecraft.getMinecraft().thePlayer));
30
        this.upperChestInventory = upperInv;
31
        this.lowerChestInventory = lowerInv;
32
        this.allowUserInput = false;
33
        int i = 222;
34
        int j = i - 108;
35
        this.inventoryRows = lowerInv.getSizeInventory() / 9;
36
        this.ySize = j + this.inventoryRows * 18;
37
    }
38
39
    /**
40
     * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
41
     */
42
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
43
    {
44
        this.fontRendererObj.drawString(this.lowerChestInventory.getDisplayName().getUnformattedText(), 8, 6, 4210752);
45
        this.fontRendererObj.drawString(this.upperChestInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
46
    }
47
48
    /**
49
     * Args : renderPartialTicks, mouseX, mouseY
50
     */
51
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
52
    {
53
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
54
        this.mc.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
55
        int i = (this.width - this.xSize) / 2;
56
        int j = (this.height - this.ySize) / 2;
57
        this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.inventoryRows * 18 + 17);
58
        this.drawTexturedModalRect(i, j + this.inventoryRows * 18 + 17, 0, 126, this.xSize, 96);
59
    }
60
    
61
    @Override
62
    public void initGui() {
63
    	super.initGui();
64
    	
65
    	EventOpenChest event = new EventOpenChest(this);
66
    	event.setType(EventType.PRE);
67
    	SpicyClient.onEvent(event);
68
    	
69
    }
70
    
71
    @Override
72
    public void onGuiClosed() {
73
    	super.onGuiClosed();
74
    	
75
    	EventOpenChest event = new EventOpenChest(this);
76
    	event.setType(EventType.POST);
77
    	SpicyClient.onEvent(event);
78
    	
79
    }
80
    
81
    public void spicyHandleMouseInput(Slot slotIn, int slotId, int clickedButton, int clickType) {
82
    	this.handleMouseClick(slotIn, slotId, clickedButton, clickType);
83
    }
84
    
85
}

What this file does

This Spicy-patched GuiChest is the module's trigger and click conduit. initGui fires EventOpenChest with type PRE after the vanilla chest layout is built, and onGuiClosed fires POST after the GUI tears down, so the module sees both ends of the window lifecycle. spicyHandleMouseInput is a direct pass-through to GuiContainer.handleMouseClick, which is the method that validates the click against the client-side container and emits C0EPacketClickWindow; the module calls it from the worker thread with clickType 1, the shift-click mode.

The file is small because it only adds the two event hooks and the alias; everything else is inherited vanilla container logic. The asymmetry that matters is in the event flow: the PRE event starts the drain, and the POST event is where the module could stop it but does not, which is what leaves the worker clicking a dead window.

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 FastClick (window click rate)

FastClick.java243 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.inventory;
16
17
import java.util.ArrayList;
18
import java.util.List;
19
20
import org.bukkit.Material;
21
import org.bukkit.entity.Player;
22
import org.bukkit.event.inventory.InventoryClickEvent;
23
import org.bukkit.event.inventory.InventoryType;
24
import org.bukkit.inventory.InventoryView;
25
import org.bukkit.inventory.ItemStack;
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.checks.combined.Improbable;
32
import fr.neatmonster.nocheatplus.permissions.Permissions;
33
import fr.neatmonster.nocheatplus.players.IPlayerData;
34
import fr.neatmonster.nocheatplus.utilities.entity.InventoryUtil;
35
import fr.neatmonster.nocheatplus.utilities.StringUtil;
36
import fr.neatmonster.nocheatplus.utilities.TickTask;
37
38
39
/**
40
 * FastClick checks for players clicking in inventories too quickly (nerfs autosteal cheats and the like).
41
 */
42
public class FastClick extends Check {
43
44
45
    final List<String> tags = new ArrayList<String>();
46
47
48
    /**
49
     * Instantiates a new fast click check.
50
     */
51
    public FastClick() {
52
        super(CheckType.INVENTORY_FASTCLICK);
53
    }
54
55
56
   /**
57
    * Checks a player.
58
    * 
59
    * @param player
60
    * @param now Millisec
61
    * @param view
62
    * @param slot
63
    * @param cursor
64
    * @param clicked
65
    * @param isShiftClick
66
    * @param inventoryAction
67
    * @param data
68
    * @param cc 
69
    * @param pData
70
    * @return true, if successful
71
    */
72
    public boolean check(final Player player, final long now, 
73
                         final InventoryClickEvent event, final int slot, final ItemStack cursor, 
74
                         final ItemStack clicked, final boolean isShiftClick, 
75
                         final String inventoryAction, final InventoryData data, final InventoryConfig cc, 
76
                         final IPlayerData pData) {
77
78
        final float amount;
79
        final Material clickedMat = clicked == null ? Material.AIR : clicked.getType();
80
        final Material cursorMat;
81
        final int cursorAmount;
82
        boolean cancel = false;
83
        tags.clear();
84
85
        if (cursor != null) {
86
            cursorMat = cursor.getType();
87
            cursorAmount = Math.max(1, cursor.getAmount());
88
        }
89
        else {
90
            cursorMat = null;
91
            cursorAmount = 0;
92
        }
93
94
        if (inventoryAction != null) {
95
            amount = getAmountWithAction(event, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, inventoryAction, data, cc);
96
        }
97
        else if (cursor != null) {
98
            // Detect shift-click features indirectly.
99
            amount = detectTweaks1_5(event, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, data, cc);
100
        }
101
        else amount = 1f;
102
103
        if (isShiftClick && inventoryAction.equals("MOVE_TO_OTHER_INVENTORY") 
104
            && (cursorMat != null && cursorMat != Material.AIR) 
105
            && clickedMat != Material.AIR) {
106
            return false;
107
        }
108
        
109
        // Count clicks
110
        data.fastClickFreq.add(now, amount);
111
        
112
        // Shor-term VL
113
        float shortTerm = data.fastClickFreq.bucketScore(0);
114
        if (shortTerm > cc.fastClickShortTermLimit) {
115
            // Check for lag.
116
            shortTerm /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration(), true);
117
        }
118
        shortTerm -= cc.fastClickShortTermLimit;
119
        
120
        // Normal VL
121
        float normal = data.fastClickFreq.score(1f);
122
        if (normal > cc.fastClickNormalLimit) {
123
            // Check for lag.
124
            normal /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration() * data.fastClickFreq.numberOfBuckets(), true);
125
        }
126
        normal -= cc.fastClickNormalLimit;
127
        
128
        // Process Violations.
129
        final double violation = Math.max(shortTerm, normal);
130
        if (violation > 0.0) {
131
            tags.add("clickspeed");
132
            data.fastClickVL += violation;
133
            final ViolationData vd = new ViolationData(this, player, data.fastClickVL, violation, cc.fastClickActions);
134
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
135
            cancel = executeActions(vd).willCancel();
136
        }
137
        else data.fastClickVL *= 0.99;
138
139
        if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
140
            player.sendMessage("FastClick: " + data.fastClickFreq.bucketScore(0) + " | " + data.fastClickFreq.score(1f) + " | cursor=" + cursor 
141
                                + " | clicked=" + clicked + " | action=" + inventoryAction);
142
        }
143
        
144
        // Adjust data
145
        data.fastClickLastClicked = clickedMat;
146
        data.fastClickLastSlot = slot;
147
        data.fastClickLastCursor = cursorMat;
148
        data.fastClickLastCursorAmount = cursorAmount;
149
150
        // Lastly, always feed the improbable.
151
        if (cc.fastClickImprobableWeight > 0.0f) {
152
            Improbable.feed(player, cc.fastClickImprobableWeight * amount, now);
153
        }
154
        return cancel;
155
    }
156
    
157
158
   /**
159
    * Enforce sane timings for interacting with the container and clicking in it.
160
    * 
161
    * @param player
162
    * @param data
163
    * @param cc
164
    */
165
    public boolean checkContainerInteraction(final Player player, final InventoryData data, final InventoryConfig cc) {
166
        boolean cancel = false;
167
        tags.clear();
168
        if (InventoryUtil.isContainerInteractionRecent(player, cc.chestOpenLimit)) {
169
            // Interaction was too quick, violation.
170
            tags.add("interact_time");
171
            long duration = Math.max(data.lastClickTime - data.containerInteractTime, 20);
172
            double violation = (cc.chestOpenLimit / duration) * 100D; // Normalize.
173
            data.fastClickVL += violation;
174
            final ViolationData vd = new ViolationData(this, player, data.fastClickVL, violation, cc.fastClickActions);
175
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
176
            cancel = executeActions(vd).willCancel();  
177
        }
178
       return cancel;
179
    }
180
    
181
182
   /**
183
    * Detect the inventory tweaks that were introduced in MC 1.5
184
    * 
185
    * @param view
186
    * @param slot
187
    * @param clicked
188
    * @param clickedMat
189
    * @param cursorAmount
190
    * @param isShiftClick
191
    * @param data
192
    * @param cc
193
    */
194
    private float detectTweaks1_5(final InventoryClickEvent event, final int slot, final ItemStack clicked, 
195
                                  final Material clickedMat, final Material cursorMat, 
196
                                  final int cursorAmount, final boolean isShiftClick, 
197
                                  final InventoryData data, final InventoryConfig cc) {
198
199
        if (cursorMat != data.fastClickLastCursor 
200
            && (!isShiftClick || clickedMat == Material.AIR || clickedMat != data.fastClickLastClicked) 
201
            || cursorMat == Material.AIR || cursorAmount != data.fastClickLastCursorAmount) {
202
            return 1f;
203
        }
204
        else if (clickedMat == Material.AIR || clickedMat == cursorMat 
205
                || isShiftClick && clickedMat == data.fastClickLastClicked ) {
206
            return Math.min(cc.fastClickNormalLimit , cc.fastClickShortTermLimit) 
207
                    / (float) (isShiftClick && clickedMat != Material.AIR ? (1.0 + Math.max(cursorAmount, InventoryUtil.getStackCount(event, clicked))) : cursorAmount)  * 0.75f;
208
        }
209
        return 1f;
210
    }
211
212
213
    private float getAmountWithAction(final InventoryClickEvent event, final int slot, final ItemStack clicked, 
214
                                      final Material clickedMat, final Material cursorMat, 
215
                                      final int cursorAmount, final boolean isShiftClick, 
216
                                      final String inventoryAction, 
217
                                      final InventoryData data, final InventoryConfig cc) {
218
219
        // Continuous drop feature with open inventories.
220
        if (inventoryAction.equals("DROP_ONE_SLOT")
221
            && slot == data.fastClickLastSlot 
222
            && clickedMat == data.fastClickLastClicked
223
            && event.getInventory().getType() == InventoryType.CRAFTING
224
            // && InventoryUtil.couldHaveInventoryOpen(player)
225
            // TODO: Distinguish if the inventory is really open.
226
            ) {
227
            return 0.6f;
228
        }
229
230
        // Collect to cursor.
231
        if (inventoryAction.equals("COLLECT_TO_CURSOR")) {
232
            final int stackCount = InventoryUtil.getStackCount(event, clicked);
233
            return stackCount <= 0 ? 1f : Math.min(cc.fastClickNormalLimit , cc.fastClickShortTermLimit) / stackCount * 0.75f;
234
        }
235
236
        // Shift click features.
237
        if ((inventoryAction.equals("MOVE_TO_OTHER_INVENTORY")) && cursorMat != Material.AIR) {
238
            // Let the legacy method do the side condition checks and counting for now.
239
            return detectTweaks1_5(event, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, data, cc);
240
        }
241
        return 1f;
242
    }
243
}

How it counteracts this module

NoCheatPlus FastClick counts inventory clicks into data.fastClickFreq, an ActionFrequency with five 200ms buckets (InventoryData line 58), against a short-term limit of 4 for the newest bucket and a one-second window limit of 15 (DefaultConfig lines 389-390). Each shift-click with an empty cursor scores 1.0; the stack-size weighting in detectTweaks1_5 only applies when the cursor already holds an item, which never happens here because every click is a shift-click with an empty cursor. checkContainerInteraction adds a second path: when the first click lands within chestOpenLimit (155ms) of the container open, it scores (chestOpenLimit / duration) * 100 (lines 165-179).

At the stock 250ms delay plus 0-40ms jitter the module lands roughly one click per 200ms bucket (score 1-2 against the short-term limit of 4) and about 3.4-4 clicks per second against the window limit of 15, and the first click arrives at 250-290ms, after the 155ms interact-time window, so the default configuration passes. Dropping the delay flips it: at 0ms the clicks land every 0-40ms, the newest bucket carries 5-10 clicks against the limit of 4 and the window score clears 15 within a second, and the first click lands inside the interact-time window for an immediate (155 / duration) * 100 violation, so a low-delay drain trips the cancel action within the first chest.

anticheat Open (inventory close on movement)

Open.java171 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.inventory;
16
17
import java.util.UUID;
18
19
import org.bukkit.GameMode;
20
import org.bukkit.Input;
21
import org.bukkit.entity.Player;
22
import org.bukkit.event.inventory.InventoryType;
23
import org.bukkit.event.inventory.InventoryType.SlotType;
24
25
import fr.neatmonster.nocheatplus.NCPAPIProvider;
26
import fr.neatmonster.nocheatplus.checks.Check;
27
import fr.neatmonster.nocheatplus.checks.CheckType;
28
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
29
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
30
import fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData;
31
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
32
import fr.neatmonster.nocheatplus.compat.registry.BukkitAPIAccessFactory;
33
import fr.neatmonster.nocheatplus.compat.versions.ClientVersion;
34
import fr.neatmonster.nocheatplus.components.registry.event.IHandle;
35
import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
36
import fr.neatmonster.nocheatplus.hooks.ExemptionSettings;
37
import fr.neatmonster.nocheatplus.players.DataManager;
38
import fr.neatmonster.nocheatplus.players.IPlayerData;
39
import fr.neatmonster.nocheatplus.utilities.collision.CollisionUtil;
40
import fr.neatmonster.nocheatplus.utilities.entity.InventoryUtil;
41
42
/**
43
 * Watch over open inventories - check with "combined" static access, put here because it has too much to do with inventories.
44
 * @author asofold
45
 */
46
public class Open extends Check implements IDisableListener {
47
48
    private static Open instance = null;
49
50
    private UUID nestedPlayer = null;
51
52
    private final IHandle<ExemptionSettings> exeSet = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstanceHandle(ExemptionSettings.class);
53
    
54
    // TODO: Add specific contexts (allow different settings for fight / blockbreak etc.).
55
56
    /**
57
     * Static access check, if there is a cancel-action flag the caller should have stored that locally already and use the result to know if to cancel or not.
58
     * 
59
     * @param player
60
     * @return If cancelling some event is opportune (open inventory and cancel flag set).
61
     */
62
    public static boolean checkClose(Player player) {
63
        return instance.check(player);
64
    }
65
66
    public Open() {
67
        super(CheckType.INVENTORY_OPEN);
68
        instance = this;
69
    }
70
71
    @Override
72
    public void onDisable() {
73
        instance = null;
74
        nestedPlayer = null;
75
    }
76
77
    /**
78
     * Enforce a closed inventory on this generic event/action (without checking for any specific side condition) <br>
79
     * This check contains the isEnabled checking (!). Inventory is closed if set in the config. <br>
80
     * Also resets inventory opening time and interaction time.
81
     * 
82
     * @param player
83
     * @return True, if the inventory has been successfully closed. This will also reset the inventory open time and interaction time.
84
     */
85
    public boolean check(final Player player) {
86
        final boolean isShulkerBox = BukkitAPIAccessFactory.getBukkitAccess().getTopInventory(player).getType().toString().equals("SHULKER_BOX");
87
        if (
88
            // TODO: POC: Item duplication with teleporting NPCS, having their inventory open.
89
            exeSet.getHandle().isRegardedAsNpc(player)
90
            || !isEnabled(player) 
91
            || !InventoryUtil.hasInventoryOpen(player)
92
            // Workaround, Open would disallow players from opening the container if standing on top
93
            // of the shulker. Reason for this is unknown
94
            || isShulkerBox) {
95
            return false;
96
        }
97
        final IPlayerData pData = DataManager.getPlayerData(player);
98
        final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
99
        if (cc.openClose) {
100
            // NOTE about UUID stuff: https://github.com/NoCheatPlus/NoCheatPlus/commit/a41ff38c997bcca780da32681e92216880e9e1b0
101
            final UUID id = player.getUniqueId();
102
            if ((this.nestedPlayer == null || !id.equals(this.nestedPlayer))) {
103
                // (The second condition represents an error, but we don't handle alternating things just yet.)
104
                this.nestedPlayer = id;
105
                player.closeInventory();
106
                pData.getGenericInstance(InventoryData.class).inventoryOpenTime = 0;
107
                pData.getGenericInstance(InventoryData.class).containerInteractTime = 0;
108
                this.nestedPlayer = null;
109
                return true;
110
            }
111
        }
112
        return false;
113
    }
114
115
    /**
116
     * To be called on {@link org.bukkit.event.player.PlayerMoveEvent}; pre-requisite is {@link InventoryUtil#hasInventoryOpen(Player)} having returned true. <br>
117
     * (Against InventoryMove cheats and similar)<br>
118
     * 
119
     * @param player
120
     * @param pData
121
     * @return True, if the open inventory needs to be closed during this movement.
122
     */
123
    public boolean checkOnMove(final Player player, final IPlayerData pData) {
124
        if (BridgeMisc.isWASDImpulseKnown(player)) {
125
            // Use WASD input directly if available (1.21.1+).
126
            Input input = player.getCurrentInput();
127
            boolean moving = input.isLeft() || input.isRight() || input.isForward() || input.isBackward() || input.isJump();
128
            if (moving) {
129
                final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
130
                if (cc.openImprobableWeight > 0.0) {
131
                    Improbable.feed(player, cc.openImprobableWeight, System.currentTimeMillis());
132
                }
133
                return true;
134
            }
135
            return false;
136
        }
137
        
138
        final MovingData mData = pData.getGenericInstance(MovingData.class);
139
        final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
140
        final InventoryData data = pData.getGenericInstance(InventoryData.class);
141
        final boolean creative = player.getGameMode() == GameMode.CREATIVE && ((data.clickedSlotType == SlotType.QUICKBAR) || cc.openDisableCreative);
142
        final boolean isMerchant = BukkitAPIAccessFactory.getBukkitAccess().getTopInventory(player).getType() == InventoryType.MERCHANT;
143
        final PlayerMoveData thisMove = mData.playerMoves.getCurrentMove();
144
        // Skipping conditions first.
145
        if (
146
            // Ignore duplicate packets
147
            mData.lastMoveNoMove
148
            // Can't check vehicles
149
            || player.isInsideVehicle()
150
            // In creative or middle click
151
            || creative 
152
            // Ignore merchant inventories.
153
            || isMerchant 
154
            // Velocity is ignored altogether. TODO: Should be horizontal too. Maybe this still work fine, most the time appear together
155
            || !mData.getOrUseVerticalVelocity(thisMove.yDistance).isEmpty()
156
            //|| mData.useHorizontalVelocity(thisMove.hDistance - mData.getHorizontalFreedom()) >= thisMove.hDistance - mData.getHorizontalFreedom()
157
            // Ignore entity pushing.
158
            || pData.getClientVersion().isAtLeast(ClientVersion.V_1_9) && CollisionUtil.isCollidingWithEntities(player, 0.5, 0.1, 0.5, true)) {
159
            return false;
160
        }
161
            
162
        // Actual detection: do assume player to be actively moving even if we don't actually know the direction (MAYBE, needs testing)
163
        if (thisMove.hasImpulse.decide()) {
164
            if (cc.openImprobableWeight > 0.0) {
165
                Improbable.feed(player, cc.openImprobableWeight, System.currentTimeMillis());
166
            }
167
            return true;
168
        }
169
        return false;
170
    }
171
}

How it counteracts this module

NCP's Open check closes the inventory when the player moves while a window is open. checkOnMove skips duplicate packets, vehicles, creative quickbar cases, merchants and vertical-velocity moves, then decides on impulse via direct WASD input where available or the movement model's hasImpulse.decide(); an impulse while InventoryUtil.hasInventoryOpen(player) is true feeds Improbable and the caller force-closes the window, resetting inventoryOpenTime and containerInteractTime (Open.java lines 123-170).

ChestStealer never touches the player's motion: the worker only clicks the container, so any WASD input or step while the chest is open is visible to the check, and a single impulse move aborts the drain by closing the window. The module offers no protection for this: it has no movement-cancelling logic and no anti-close guard beyond the disabled C16 re-open, so on NCP the steal is only safe while the player stands perfectly still. The check also resets the open-time baseline that FastClick's interact_time path compares against, so a player caught moving mid-steal loses the click-timing advantage on the next attempt.

anticheat InventoryActions (window state mismatch)

InventoryActions.java60 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.interaction.inventory;
20
21
/*
22
 * InventoryActions check originally written by Havesta; modified, split apart, and implemented into Hawk by Islandscout
23
 *
24
 * InventoryActions checks if a player is
25
 * - interacting with entities/blocks while inventory is opened
26
 */
27
28
import me.islandscout.hawk.HawkPlayer;
29
import me.islandscout.hawk.check.CustomCheck;
30
import me.islandscout.hawk.event.*;
31
32
public class InventoryActions extends CustomCheck {
33
34
    public InventoryActions() {
35
        super("inventoryactions", true, 3, 5, 0.999, 5000, "%player% failed inventory-actions, VL: %vl%", null);
36
    }
37
38
    @Override
39
    protected void check(Event e) {
40
        HawkPlayer pp = e.getHawkPlayer();
41
42
        //player tried to interact with entities/world while an inventory window is open
43
        if(pp.hasInventoryOpen() != 0 && (e instanceof InteractEntityEvent || e instanceof BlockDigEvent ||
44
                e instanceof ArmSwingEvent || e instanceof InteractWorldEvent)) {
45
            punish(pp, true, e);
46
            e.resync();
47
            //TODO After failing several times, there's a chance that they could be legit, but the inventory state is glitched. Close the player's inventory.
48
        }
49
50
        //player tried to interact with inventory while it is closed
51
        else if(pp.hasInventoryOpen() == 0 && e instanceof ClickInventoryEvent) {
52
            //TODO also check that window ID makes sense with the window type (eg. ID 0 must mean hasInventoryOpen() == 0)
53
            punish(pp, true, e);
54
            e.resync();
55
        }
56
        else {
57
            reward(pp);
58
        }
59
    }
60
}

How it counteracts this module

Hawk's InventoryActions punishes ClickInventoryEvent packets when HawkPlayer.hasInventoryOpen() is zero, and world interaction (InteractEntity, BlockDig, ArmSwing, InteractWorld) when it is non-zero, with a resync on every punish (InventoryActions.java lines 43-55). Hawk tracks the window lifecycle from the S2D open, C16 inventory-command and close packets, so its open state mirrors the server's window bookkeeping rather than the client's screen.

The module's lifecycle race is the exposure here. The worker thread is only stopped by the next chest opening, never by the GUI close, so after the player closes the chest (C0D goes out and Hawk's open state returns to zero) the thread keeps sleeping and shift-clicking the stale GuiChest. Every C0E that lands after the close is a ClickInventoryEvent against a window Hawk considers closed, punished and resynced, which forces a container-state refresh and interrupts whatever slots remain. The world-interaction branch stays quiet, since the drain never swings, digs or interacts with the world while the chest is up, but the click-after-close race is inherent to the thread lifecycle.

anticheat InventoryMove (rotation and state while open)

InventoryMove.java52 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;
20
21
import me.islandscout.hawk.HawkPlayer;
22
import me.islandscout.hawk.check.MovementCheck;
23
import me.islandscout.hawk.event.MoveEvent;
24
25
/*
26
 * InventoryActions check originally written by Havesta; modified, split apart, and implemented into Hawk by Islandscout
27
 *
28
 * InventoryMove checks if a player is
29
 * - rotating, sprinting, or sneaking while inventory is opened
30
 */
31
32
public class InventoryMove extends MovementCheck {
33
34
    public InventoryMove() {
35
        super("inventorymove", true, 3, 5, 0.999, 5000, "%player% failed inventory-move, VL: %vl%", null);
36
    }
37
38
    @Override
39
    protected void check(MoveEvent e) {
40
        HawkPlayer pp = e.getHawkPlayer();
41
42
        //TODO: false flag: rotation is still possible at least 1 tick after opening inventory
43
        //TODO: false flag: you gotta do that TP grace period thing for this too
44
        //TODO: false flag: ESCing out of F6 twitch options while inv is open will cause a desync. Forcibly close inventory on flag to fix desyncs like this?
45
        if((e.isUpdateRot() || pp.isSprinting() || pp.isSneaking()) && pp.hasInventoryOpen() != 0 && !e.isTeleportAccept()) {
46
            punishAndTryRubberband(pp, e);
47
        }
48
        else {
49
            reward(pp);
50
        }
51
    }
52
}

How it counteracts this module

Hawk's InventoryMove punishes rotation updates, sprinting and sneaking while an inventory window is open, excluding only teleport-accept moves, and rubberbands the player on violation (InventoryMove.java line 45). The check keys on the client's movement state as reported in the move stream, so it catches players who open a chest mid-motion or look around while the window flag is set.

ChestStealer does nothing to hide these states: it never cancels movement packets and never suppresses rotation, so a player who opens the chest while holding W or sneaking, or who turns to check surroundings mid-drain, trips the check immediately. The vanilla chest GUI normally grabs the mouse and blocks look, which is the main reason rotation-while-open is rare in legit play, but the module offers no protection for the sprint and sneak flags, which persist from the moment of opening. The randomized steal delays are irrelevant to this check, which scores movement state, not click cadence.

← Back to Analysis Hub