Memeware 7.3 Auto Potion module 2 files, 134 lines

Memeware 7.3 Auto Potion: Full Source Analysis

Memeware's Auto Potion is a health-gated splash-heal thrower driven by a two-phase UpdateEvent handler and a static doThrow flag.

me/memewaredevs/client/module/combat/AutoPotion.java · GitHub source ↗

Published 2026-08-12 · Updated 2026-08-12

Analysis

Overview

Memeware's Auto Potion is a health-gated splash-heal thrower driven by a two-phase UpdateEvent handler and a static doThrow flag. Below 9.0 health the pre phase scans the hotbar for a splash potion whose effects contain Instant Health; if the hotbar is empty it window-clicks one from the main inventory (C0E, mode 2 hotbar swap), then arms doThrow and forces the local pitch to 90 so the throw appears straight up. The post phase of the next event fires the actual throw as a three-packet burst in one tick: C09 to the pot slot, C08 with the held stack (the single-stack constructor, so block position ORIGIN and face 255 - the use-item form), then C09 back to the previous slot. A 500ms Timer with reset() on arming sets the cooldown. The module has no open-container guard on its window click and never sends a look packet with the pitch change, so the splash is thrown at the server's last-synced rotation while the client renders a straight-up lob - the visual and the wire disagree.

Two-phase throw cycle

The handler splits work across update phases. The pre phase gates on health < 9.0 and non-creative, then (if the 500ms timer has elapsed) locates a potion: hotbar scan 0-8 for an ItemPotion that isSplash() and whose effects list contains Potion.heal, falling back to a container scan 9-35 whose first hit is swapped into hotbar slot 1 with mc.playerController.windowClick(windowId, j, 1, 2) - mode 2 SWAP, button 1. It then re-scans the hotbar, remembers the first pot slot in the instance field slot, calls timer.reset() and sets the static doThrow, and finally event.setPitch(90.0f) - a local-only rotation change. The post phase consumes the flag: if doThrow, it queues C09(slot), C08(getStackInSlot(slot)) and C09(inventory.currentItem) back-to-back through addToSendQueue and clears doThrow. The static flag doubles as a public isPotting() query other modules can poll. Because the throw packets fire on the post of the same tick that armed them, the C09-C08-C09 triple is one 50ms window of traffic.

C08 use-item form and rotation split

The C08 is built with the one-argument constructor, which serializes BlockPos.ORIGIN (0, 0, 0) with face index 255 (-1) and the current stack. That face value is the protocol's 'use item in hand' marker: the server's processPlayerBlockPlacement routes it to ItemPotion.onItemRightClick, which spawns the splash entity for a splash potion. The packet carries the potion stack itself, so the server validates the throw against the item the client claims to hold - and because the module switched the held slot with C09 immediately before, the carried stack matches the announced slot. The pitch is applied only to the local player (event.setPitch) with no C05/C06 look packet, so the server processes the throw with the last rotation it received; the client meanwhile renders the potion lobbing straight up from the forced 90 pitch. That split - throw direction diverging from the synced rotation - is a local/remote desync a rotation-checking anticheat can measure, though the module never claims the 90-degree pitch on the wire.

Cooldown and window-click edge cases

The Timer here behaves as a real period, unlike Auto Armor's: arming calls timer.reset(), so delay(500f) gates the next search to 500ms after the previous arm. Two edge cases follow from the ordering: the window-click refill path uses mc.thePlayer.openContainer.windowId with no windowId != 0 guard, so with a chest open the swap click targets the chest window's slot j instead of the inventory (the container scan 9-35 also walks chest slots in that state), and the throw still fires regardless. And isValidPotion is called twice per candidate with an overload that re-casts the stack's item, a redundancy that costs nothing but signals the copy-paste origin. The health gate is a hard 9.0 (4.5 hearts) with no setting; the module only ever throws heal splash, so it is a pure panic-heal bot rather than a buff module.

source AutoPotion.java (module)

AutoPotion.java103 lines · JavaOriginal ↗
1
2
package me.memewaredevs.client.module.combat;
3
4
import me.hippo.api.lwjeb.annotation.Handler;
5
import me.memewaredevs.client.util.misc.Timer;
6
import net.minecraft.item.ItemPotion;
7
import net.minecraft.item.ItemStack;
8
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
9
import net.minecraft.network.play.client.C09PacketHeldItemChange;
10
import net.minecraft.potion.Potion;
11
import net.minecraft.potion.PotionEffect;
12
import me.memewaredevs.client.event.events.UpdateEvent;
13
import me.memewaredevs.client.module.Module;
14
15
import java.util.function.Consumer;
16
17
public class AutoPotion extends Module {
18
    private static boolean doThrow;
19
    int slot;
20
    private final Timer timer = new Timer();
21
22
    public AutoPotion() {
23
        super("Auto Potion", 0, Module.Category.COMBAT);
24
    }
25
26
    @Handler
27
    public Consumer<UpdateEvent> update = event -> {
28
        int j;
29
        ItemStack stack;
30
        if (mc.thePlayer.getHealth() >= 9.0 || mc.thePlayer.capabilities.isCreativeMode) {
31
            return;
32
        }
33
        if (event.isPost() && doThrow) {
34
            mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(slot));
35
            mc.thePlayer.sendQueue.addToSendQueue(
36
                    new C08PacketPlayerBlockPlacement(mc.thePlayer.inventory.getStackInSlot(slot)));
37
            mc.thePlayer.sendQueue
38
                    .addToSendQueue(new C09PacketHeldItemChange(mc.thePlayer.inventory.currentItem));
39
            doThrow = false;
40
        }
41
        if (!timer.delay(500.0f)) {
42
            return;
43
        }
44
        slot = -1;
45
        boolean hasPots = false;
46
        for (j = 0; j < 9; ++j) {
47
            stack = mc.thePlayer.inventory.getStackInSlot(j);
48
            if (stack == null || stack.getItem() == null || !(stack.getItem() instanceof ItemPotion)
49
                    || !isValidPotion((ItemPotion) stack.getItem(), stack)) {
50
                continue;
51
            }
52
            hasPots = true;
53
        }
54
        if (!hasPots) {
55
            for (j = 9; j < 36; ++j) {
56
                stack = mc.thePlayer.inventoryContainer.getSlot(j).getStack();
57
                if (stack == null || stack.getItem() == null || !(stack.getItem() instanceof ItemPotion)
58
                        || !isValidPotion(stack)) {
59
                    continue;
60
                }
61
                mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, j, 1, 2,
62
                        mc.thePlayer);
63
                break;
64
            }
65
        }
66
        for (j = 0; j < 9; ++j) {
67
            stack = mc.thePlayer.inventory.getStackInSlot(j);
68
            if (stack == null || stack.getItem() == null || !(stack.getItem() instanceof ItemPotion)
69
                    || !isValidPotion((ItemPotion) stack.getItem(), stack)) {
70
                continue;
71
            }
72
            slot = j;
73
            break;
74
        }
75
        if (slot == -1) {
76
            return;
77
        }
78
        timer.reset();
79
        doThrow = true;
80
        event.setPitch(90.0f);
81
    };
82
83
    public boolean isValidPotion(final ItemPotion potion, final ItemStack stack) {
84
        if (ItemPotion.isSplash(stack.getItemDamage())) {
85
            for (final Object o : potion.getEffects(stack)) {
86
                if (!(o instanceof PotionEffect) || ((PotionEffect) o).getPotionID() != Potion.heal.id) {
87
                    continue;
88
                }
89
                return true;
90
            }
91
        }
92
        return false;
93
    }
94
95
    public boolean isValidPotion(final ItemStack stack) {
96
        return isValidPotion((ItemPotion) stack.getItem(), stack);
97
    }
98
99
    public static boolean isPotting() {
100
        return doThrow;
101
    }
102
103
}

What this file does

The whole module is the UpdateEvent handler (lines 27-81) plus the potion predicates. Lines 30-32 gate on health >= 9.0 and creative. The post-phase throw (lines 33-40) sends the C09-C08-C09 triple and clears the static doThrow. The pre-phase search (lines 41-65) applies the 500ms timer, scans the hotbar for a valid heal splash, and on failure window-clicks the first inventory hit into hotbar slot 1 (line 61, mode 2 SWAP). Lines 66-74 re-scan the hotbar to fix the actual slot, lines 75-80 bail if none, else reset the timer, set doThrow and force pitch 90. isValidPotion (lines 83-97) requires isSplash() and a Potion.heal effect; isPotting() (lines 99-101) exposes the static flag. Note the module never checks openContainer.windowId before the refill click and never sends a look packet with the pitch.

source Timer.java (cooldown gate)

Timer.java31 lines · JavaOriginal ↗
1
2
package me.memewaredevs.client.util.misc;
3
4
public class Timer {
5
    private long prevMS = 0L;
6
7
    public Timer() {
8
        this.reset();
9
    }
10
11
    public boolean delay(final float milliSec) {
12
        return this.getTime() - this.prevMS >= milliSec;
13
    }
14
15
    public void reset() {
16
        this.prevMS = this.getTime();
17
    }
18
19
    public long getTime() {
20
        return System.nanoTime() / 1000000L;
21
    }
22
23
    public boolean sleep(long time) {
24
	    if (getTime() >= time) {
25
	      reset();
26
	      return true;
27
	    } 
28
	    return false;
29
	  }
30
31
}

What this file does

The same Timer class Auto Armor uses, but here it behaves as a genuine period because the module calls reset() on every arm (line 78): delay(500f) only passes once 500ms has elapsed since the last reset, so potion searches cannot re-arm within half a second of a throw. The class itself is a comparison-only helper - constructor reset, delay() with no side effect - and its utility depends entirely on whether the caller resets. isPotting() consumers on the same client can therefore rely on a stable 500ms cadence between throws, which is the fingerprint the countering checks measure.

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 ItemSwitchSpeed (C09 after item use)

ItemSwitchSpeed.java80 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
package me.islandscout.hawk.check.interaction.item;
19
20
import me.islandscout.hawk.HawkPlayer;
21
import me.islandscout.hawk.check.Cancelless;
22
import me.islandscout.hawk.check.CustomCheck;
23
import me.islandscout.hawk.event.Event;
24
import me.islandscout.hawk.event.InteractItemEvent;
25
import me.islandscout.hawk.event.InteractWorldEvent;
26
import me.islandscout.hawk.event.ItemSwitchEvent;
27
import org.bukkit.entity.Player;
28
29
import java.util.*;
30
31
public class ItemSwitchSpeed extends CustomCheck implements Cancelless {
32
33
    private Map<UUID, Long> lastSwitchTicks;
34
    private Set<UUID> usedSomething;
35
    private int MIN_SWITCH_TICKS;
36
37
    //might rename this to "AutoUse"
38
    public ItemSwitchSpeed() {
39
        super("itemswitchspeed", true, -1, 1, 0.999, 5000, "%player% failed item switch speed, VL: %vl%", null);
40
        lastSwitchTicks = new HashMap<>();
41
        usedSomething = new HashSet<>();
42
        MIN_SWITCH_TICKS = (int)customSetting("minSwitchTicks", "", 1);
43
    }
44
45
    //For future reference, if you try to verify that the item-switch packet points to a different slot, beware of falses.
46
    //The client can send item-switch packets regardless if the slot switched or not.
47
48
    @Override
49
    protected void check(Event event) {
50
        if(event instanceof InteractItemEvent || event instanceof InteractWorldEvent) {
51
            usedSomething.add(event.getPlayer().getUniqueId());
52
        }
53
        else if(event instanceof ItemSwitchEvent) {
54
55
            HawkPlayer pp = event.getHawkPlayer();
56
            UUID uuid = pp.getUuid();
57
58
            if(usedSomething.contains(uuid)) {
59
                long lastSwitchTick = lastSwitchTicks.getOrDefault(uuid, 0L);
60
                if(pp.getCurrentTick() - lastSwitchTick < MIN_SWITCH_TICKS) {
61
                    punish(pp, 1, false, event);
62
                }
63
                else {
64
                    reward(pp);
65
                }
66
67
                usedSomething.remove(uuid);
68
            }
69
70
            lastSwitchTicks.put(pp.getUuid(), pp.getCurrentTick());
71
        }
72
    }
73
74
    @Override
75
    public void removeData(Player p) {
76
        UUID uuid = p.getUniqueId();
77
        lastSwitchTicks.remove(uuid);
78
        usedSomething.remove(uuid);
79
    }
80
}

How it counteracts this module

Hawk's ItemSwitchSpeed is the canonical check for the auto-pot slot dance - the source comment literally notes it 'might rename this to AutoUse'. The check maintains a per-player lastSwitchTick map and a usedSomething set: an InteractItemEvent or InteractWorldEvent adds the player to usedSomething, and the next ItemSwitchEvent then compares the tick delta against MIN_SWITCH_TICKS (default 1); a switch within that window of a use is a punish (1 VL, cancelless). Memeware's module produces the worst-case input: C09(pot slot), C08 (the use), C09(back) are all queued in the same post-update tick, so the switch-back ItemSwitchEvent arrives in the same or the immediately following tick as the InteractItemEvent generated by the C08 - well inside MIN_SWITCH_TICKS. Every throw is therefore a guaranteed violation, and because the module re-arms on a 500ms cooldown whenever health stays under 9, sustained low-health combat accumulates VL without human-like spacing. There is no randomization or delay setting to widen the gap; the only escape is throwing less often than the check's window, which defeats the module's purpose.

anticheat UseItemAdapter (C08 face-255 and C09 resync)

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

NCP's ProtocolLib adapter is the layer that classifies C08 traffic into block places and item uses, and it is the C09-sensitive half of NCP's item-use state machine. handleBlockPlacePacket (line 382) reads the pre-1.9 C08 face index: a face <= 5 means a genuine block place and clears data.mightUseItem, while any other face - including the 255 the module's one-argument constructor serializes - sets mightUseItem = true, marking the player as possibly using an item. The subsequent PlayerInteractEvent (RIGHT_CLICK_AIR for the potion throw) then drives onItemInteract, which for splash potions hits the pre-1.9 durability guard (line 277, durability > 16384) and skips setItemInUse entirely - an accurate gap: NCP deliberately does not track splash throws as item-use. What the adapter does catch is the slot churn: the module's C09 to the pot slot and C09 back fire onChangeSlot (line 366), and any real slot change while an item use is in flight calls pData.requestItemUseResync(), forcibly releasing the server-side item-use state. The same-tick C09-C08-C09 cycle is exactly the sequence the adapter's state machine exists to reconcile, and the resync it triggers is the server reasserting its inventory/use state against the client's rapid manipulation.

anticheat FastConsume (consume-time ledger)

FastConsume.java28 lines · Java
1
package me.vrekt.arc.check.inventory;
2
3
import me.vrekt.arc.Arc;
4
import me.vrekt.arc.check.Check;
5
import me.vrekt.arc.check.CheckType;
6
import me.vrekt.arc.data.inventory.InventoryData;
7
import org.bukkit.entity.Player;
8
9
public class FastConsume extends Check {
10
11
    private int consumeTime = 0;
12
13
    public FastConsume() {
14
        super(CheckType.FASTCONSUME);
15
16
        consumeTime = Arc.getCheckManager().getValueInt(CheckType.FASTCONSUME, "consume-time");
17
    }
18
19
    public boolean check(Player player, InventoryData data) {
20
21
        long now = System.currentTimeMillis();
22
        long last = data.getConsumeTime();
23
        long total = now - last;
24
25
        // check if the time it took to consume the item is less than allowed.
26
        return total < consumeTime && checkViolation(player, "consume time less than allowed.");
27
    }
28
}

How it counteracts this module

Arc v2's FastConsume measures the time between the first right-click on a consumable and its completion, flagging when the interval is shorter than the configured consume-time. The feed is InventoryListener.onInteract (Arc v2): a RIGHT_CLICK_AIR or RIGHT_CLICK_BLOCK with a POTION or edible in hand stamps InventoryData.consumeTime, and PlayerItemConsumeEvent is where FastConsume.check compares the elapsed time. For Memeware's module the ledger interaction is lopsided: the C08 throw fires a PlayerInteractEvent with the potion in hand, so consumeTime is stamped on every throw, but a splash potion never produces a PlayerItemConsumeEvent - the item is consumed instantly server-side - so the completion half of the ledger never arrives and the check's cancel path (which resets via getFirstConsumableItemInHand) is never exercised. The stamping still matters: the module's 500ms cooldown is the only thing separating consecutive consumeTime stamps, and Arc v2's AutoHeal path (PacketListener, gated on Material.MUSHROOM_SOUP) ignores potions entirely - so Arc v2 sees the module's throws only as a repeated consume-start signal with no completion, a pattern its inventory timing was built to scrutinize even though the soup-gated check does not flag it directly.

anticheat UseItemStatusHandle (use-item classifier)

UseItemStatusHandle.java100 lines · Java
1
package ai.idealistic.spartan.listeners.protocol;
2
3
import ai.idealistic.spartan.Register;
4
import ai.idealistic.spartan.abstraction.protocol.PlayerProtocol;
5
import ai.idealistic.spartan.compatibility.necessary.protocollib.BlockPositionPlib;
6
import ai.idealistic.spartan.compatibility.necessary.protocollib.HandsPlib;
7
import ai.idealistic.spartan.compatibility.necessary.protocollib.MovingBlockPositionsPlib;
8
import ai.idealistic.spartan.compatibility.necessary.protocollib.ProtocolLib;
9
import ai.idealistic.spartan.functionality.concurrent.CheckThread;
10
import ai.idealistic.spartan.functionality.server.Config;
11
import ai.idealistic.spartan.functionality.server.MultiVersion;
12
import ai.idealistic.spartan.functionality.server.PluginBase;
13
import com.comphenix.protocol.PacketType;
14
import com.comphenix.protocol.events.ListenerPriority;
15
import com.comphenix.protocol.events.PacketAdapter;
16
import com.comphenix.protocol.events.PacketContainer;
17
import com.comphenix.protocol.events.PacketEvent;
18
import com.comphenix.protocol.wrappers.BlockPosition;
19
import com.comphenix.protocol.wrappers.EnumWrappers;
20
import org.bukkit.GameMode;
21
import org.bukkit.entity.Player;
22
import org.bukkit.inventory.ItemStack;
23
24
public class UseItemStatusHandle extends PacketAdapter {
25
26
    public UseItemStatusHandle() {
27
        super(Register.plugin, ListenerPriority.NORMAL, resolvePacketTypes());
28
    }
29
30
    @Override
31
    public void onPacketReceiving(PacketEvent event) {
32
        Player player = event.getPlayer();
33
        PlayerProtocol protocol = PluginBase.getProtocol(player);
34
35
        if (!Config.settings.getBoolean("Important.bedrock_on_protocollib")
36
                && protocol.isBedrockPlayer()) {
37
            return;
38
        }
39
        PacketContainer packet = event.getPacket();
40
41
        CheckThread.run(protocol, () -> {
42
            if (packet.getType().equals(PacketType.Play.Client.BLOCK_DIG)) {
43
                protocol.useItemPacket = false;
44
            } else {
45
                BlockPosition blockPosition = new BlockPosition(0, 0, 0);
46
                if (packet.getHands().size() == 0) {
47
                    if (packet.getMovingBlockPositions().size() > 0) {
48
                        blockPosition = MovingBlockPositionsPlib.getSafeMovingBlockPositions(packet, 0).getBlockPosition();
49
                    }
50
                    if (packet.getBlockPositionModifier().size() > 0) {
51
                        blockPosition = BlockPositionPlib.getSafeBlockPosition(packet, 0);
52
                    }
53
                    if (blockPosition.getY() != -1) return;
54
                }
55
                boolean isMainHand = !MultiVersion.isOrGreater(MultiVersion.MCVersion.V1_9)
56
                        || HandsPlib.getSafeHand(event.getPacket(), 0) == EnumWrappers.Hand.MAIN_HAND;
57
                ItemStack itemStack = MultiVersion.isOrGreater(MultiVersion.MCVersion.V1_9)
58
                        ? (isMainHand ? protocol.getInventory().getItemInMainHand()
59
                        : protocol.getInventory().getItemInOffHand()) : player.getItemInHand();
60
                if (packet.getType().toString().contains("USE_ITEM_ON")) {
61
                    if (event.getPacket().getStructures().getValues().toString().contains("Serverbound"))
62
                        return;
63
                }
64
                if (itemStack.getType().toString().contains("SHIELD") ||
65
                        (itemStack.getType().isEdible() && (player.getFoodLevel() != 20
66
                                || itemStack.getType().toString().contains("GOLDEN_APPLE"))
67
                                && !protocol.getGameMode().equals(GameMode.CREATIVE))) {
68
                    protocol.useItemPacket = true;
69
                    protocol.useItemPacketReset =
70
                            !(itemStack.getType().toString().contains("SHIELD") ||
71
                                    itemStack.getType().toString().contains("GOLDEN_APPLE"));
72
                }
73
            }
74
        });
75
    }
76
77
    private static PacketType[] resolvePacketTypes() {
78
        if (MultiVersion.isOrGreater(MultiVersion.MCVersion.V1_17)) {
79
            return new PacketType[]{
80
                    PacketType.Play.Client.USE_ITEM,
81
                    PacketType.Play.Client.BLOCK_DIG
82
            };
83
        } else {
84
            if (ProtocolLib.isPacketSupported("USE_ITEM_ON")) {
85
                return new PacketType[]{
86
                        PacketType.Play.Client.USE_ITEM_ON,
87
                        PacketType.Play.Client.BLOCK_PLACE,
88
                        PacketType.Play.Client.BLOCK_DIG
89
                };
90
            } else {
91
                return new PacketType[]{
92
                        PacketType.Play.Client.BLOCK_PLACE,
93
                        PacketType.Play.Client.BLOCK_DIG
94
                };
95
            }
96
        }
97
    }
98
99
100
}

How it counteracts this module

Spartan's UseItemStatusHandle classifies every C08/use-item packet into Spartan's useItemPacket state. For pre-1.9 C08 traffic it reads the block position; a real block place (Y != -1) returns immediately without touching the flag. The module's throw - C08 with position ORIGIN - has Y == 0, so it falls through to the item inspection, which only sets useItemPacket = true for shields and edible items (with the food-level and golden-apple carve-outs). A splash potion is neither, so the throw leaves useItemPacket untouched. That is the honest summary of this check against the module: the potion use is not a shield block and not food, so Spartan's item-use status machine does not mark it, and the check is a gap rather than a counter for Memeware's Auto Potion. The value of the file is diagnostic - it shows the exact classification boundary the module exploits: the C08 use-item form passes through Spartan's status layer without being recorded as an item use, so downstream checks that key on useItemPacket never see the throw.

← Back to Analysis Hub