0x1D S1DPacketEntityEffect
Applies a status/potion effect to an entity.
Published 2026-06-18 · Updated 2026-10-14
Fields
| Field | Type | Description |
|---|---|---|
| entityId | VarInt | |
| effectId | byte | Potion effect ID |
| amplifier | byte | Effect amplifier (0 = level 1, 1 = level 2, etc.) |
| duration | VarInt | Duration in ticks (20 ticks = 1 second) |
| hideParticles | boolean | Whether to hide ambient particles |
Wire Encoding
| Field | Type | Notes |
|---|---|---|
| Entity ID | VarInt | |
| Effect ID | byte | |
| Amplifier | byte | |
| Duration | VarInt | |
| Hide Particles | bool |
MCP References
NetHandlerPlayClient.handleEntityEffect()Handler Interface
INetHandlerPlayClientNotes
Vanilla Source
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
Deobfuscated MCP 1.8.9 source of S1DPacketEntityEffect, fetched directly from Marcelektro/MavenMCP-1.8.9 (net/minecraft/network/play/server/S1DPacketEntityEffect.java) at build time and verified present.
Deep Dive
Role in the protocol
S1DPacketEntityEffect applies one potion effect to one entity. The server has three send sites: EntityTrackerEntry broadcasts an entity's new effect to every player watching it, EntityPlayerMP.addPotionEffect and refreshActivePotionEffect send it to the affected player directly, and ServerConfigurationManager replays effects (beacon, team) on respawn and on player join. Wire layout is entityId VarInt, effectId byte, amplifier byte, duration VarInt in ticks, hideParticles boolean. In 1.8.9 the effect is a full state push: the client stores it in the entity's active potion map and the server never asks for confirmation.
Vanilla handling
NetHandlerPlayClient.handleEntityEffect runs on the client thread via PacketThreadUtil, resolves the entity with getEntityByID, and for EntityLivingBase targets builds a PotionEffect(effectId, duration, amplifier, false, hideParticles), calls setPotionDurationMax(duration), then addPotionEffect. From that point every renderer (armor, HUD, particles, the player's own effect tab) reads the entity's activePotionMap. Effects on non-living entities are silently dropped, and an unknown entityId does nothing.
Why clients touch it
The 8 reference clients leave S1D to vanilla; the only non-vanilla hit among them is Rise 6.1.30 and 6.2.4 NetworkAPI.java, which registers S1DPacketEntityEffect in the clientbound class table (index 72) so scripts can build and inject it via receivePacket. Effect-aware features in those clients (effect HUD rows, potion ESP) poll the entity's active potion map after vanilla applies the packet, or render from EntityLivingBase state, so no packet interception is needed. November Recode 2.0 is the exception: AutoPotModule hooks S1D as the server's implicit confirmation that a thrown splash potion landed, resetting its potion sequence only when the effect packet for the local player arrives. The PotionHUD/AntiPotion entries in older packet docs come from Sigma 3.9, which is not part of the reference set; Sigma 4.11's corpus has no S1D hit.
Exploit surface
Cancelling S1D in a receive event is a client-side potion bypass: the server keeps applying the effect and its movement math, the client simply never renders or stores it. That grants nothing for movement because speed, jump and health attributes are server-authoritative. Anti-cheats never measure this packet; it is one-directional cosmetic state. The only bandwidth note is that EntityTrackerEntry sends one S1D per effect per tracked entity on the tracking loop, so rapid effect churn is amplification surface for griefing plugins, not for cheat modules.
Server-Side Handling
EntityTrackerEntry line 418 sends S1D to each playerNetServerHandler in the watching list when a tracked entity gains an effect; EntityPlayerMP lines 922/927 send it to the affected player for addPotionEffect and refreshActivePotionEffect; ServerConfigurationManager lines 193/509 replay active effects on respawn and join. The server does no validation on the receiving side: there is no processX handler because the packet is clientbound only.
Protocol Analysis
The amplifier byte is the level minus one (0 means level I). Duration is in ticks on the wire; the client stores it as the effect duration and also as durationMax, so the potion icon countdown and the expiry timestamp both come from this single value. hideParticles maps to the PotionEffect showParticles flag; an S1D with the same effectId overwrites the previous entry in the active potion map rather than stacking.
Anti-Cheat Landscape
No anti-cheat in the 1.8.9 ecosystem flags S1D handling. Movement-relevant effects (speed, jump boost, slowness) are validated from server-side attribute and motion math, so a client that drops the packet only sees wrong visuals. Servers that want to detect a modified client would have to query the client for its potion state, which vanilla 1.8.9 has no packet for.
implementation Implementation Cases
Effect application is a pure server-to-client state push. The 8 reference clients have no module interest in it and every effect-aware feature reads the entity's potion map after vanilla applies the packet; the sole non-vanilla hit among them is Rise 6.x NetworkAPI registering the class for script injection. November Recode 2.0's AutoPotModule is the only module that hooks S1D, using it as the ack that a splash potion actually applied.
Use the S1D effect packet for the local player as the server-side confirmation that a thrown splash potion landed, so the potion sequence only advances after the effect applies.
The potion sequence is staged: C09 held-item change, C08 block placement for the throw, then the module sets waitingClientUpdate and waits. The S1D listener checks the packet's entity id against the local player; while waitingClientUpdate is set it resets the pot stage, restarts the delay timer and re-syncs the inventory, scheduling the next pot.
// ===== FILE: November Recode 2.0, feature/module/impl/combat/AutoPotModule.java =====
/* November.lol © 2023 */
package lol.november.feature.module.impl.combat;
import static lol.november.listener.bus.DefaultEventPriority.HIGH;
import java.util.List;
import lol.november.November;
import lol.november.feature.module.Category;
import lol.november.feature.module.Module;
import lol.november.feature.module.Register;
import lol.november.feature.setting.Setting;
import lol.november.listener.bus.Listener;
import lol.november.listener.bus.Subscribe;
import lol.november.listener.event.net.EventPacket;
import lol.november.listener.event.player.EventUpdate;
import lol.november.utility.math.timer.Timer;
import lol.november.utility.player.InventoryUtils;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
import net.minecraft.network.play.client.C09PacketHeldItemChange;
import net.minecraft.network.play.server.S1DPacketEntityEffect;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
/**
* @author Gavin
* @since 2.0.0
*/
@Register(
name = "AutoPot",
description = "Automatically pots you",
category = Category.COMBAT
)
public class AutoPotModule extends Module {
private final Setting<Integer> delay = new Setting<>(
"Delay",
100,
1,
0,
2500
);
private final Setting<Float> health = new Setting<>(
"Health",
14.0f,
0.01f,
1.0f,
19.0f
);
private final Setting<Boolean> rotate = new Setting<>("Rotate", true);
private final Timer timer = new Timer();
private boolean waitingClientUpdate = false;
private int potStage = -1;
@Override
public void disable() {
super.disable();
if (mc.thePlayer != null) {
November.instance().inventory().sync();
}
waitingClientUpdate = false;
potStage = -1;
}
@Subscribe
private final Listener<EventUpdate> update = event -> {
if (waitingClientUpdate) {
return;
}
int slot = potSlot();
if (slot == -1) {
if (waitingClientUpdate || potStage != -1) November
.instance()
.inventory()
.sync();
potStage = -1;
waitingClientUpdate = false;
return;
}
if (rotate.getValue()) {
November
.instance()
.rotations()
.spoof(HIGH, 5, new float[] { mc.thePlayer.rotationYaw, 90.0f });
}
if (timer.passed(delay.getValue(), true)) {
if (potStage <= 0) {
potStage = 1;
if (November.instance().inventory().slot() != slot) {
mc.thePlayer.sendQueue.addToSendQueue(
new C09PacketHeldItemChange(slot)
);
}
} else if (potStage == 1) {
potStage = 2;
mc.thePlayer.sendQueue.addToSendQueue(
new C08PacketPlayerBlockPlacement(
November.instance().inventory().itemStack()
)
);
} else if (potStage == 2) {
if (!waitingClientUpdate) {
November.instance().inventory().sync();
potStage = 3;
waitingClientUpdate = true;
}
}
}
};
@Subscribe
private final Listener<EventPacket.In> packetIn = event -> {
if (mc.thePlayer == null) return;
if (event.get() instanceof S1DPacketEntityEffect packet) {
if (
packet.getEntityId() == mc.thePlayer.getEntityId() &&
waitingClientUpdate
) {
waitingClientUpdate = false;
potStage = -1;
timer.reset();
November.instance().inventory().sync();
}
}
};
public int potSlot() {
for (int i = 0; i < 9; ++i) {
ItemStack stack = mc.thePlayer.inventory.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ItemPotion itemPotion) {
if (!ItemPotion.isSplash(stack.getItemDamage())) continue;
List<PotionEffect> effectList = itemPotion.getEffects(stack);
for (PotionEffect effect : effectList) {
Potion potion = Potion.potionTypes[effect.getPotionID()];
if (
mc.thePlayer.getHealth() <= health.getValue() &&
potion.id == Potion.heal.id
) return i;
if (
InventoryUtils.validPotions.contains(potion) &&
!mc.thePlayer.isPotionActive(potion) &&
!potion.isInstant()
) return i;
}
}
}
return -1;
}
}
// NOTE (AI): AutoPotModule uses S1D as a client-side confirmation that a splash potion actually applied. The potion sequence is staged: C09 held-item change, C08 block placement for the throw, then the module waits with waitingClientUpdate set. The S1D listener resolves the effect packet for the local player and, while waitingClientUpdate is set, resets the pot stage, restarts the delay timer and re-syncs the inventory. The potion's effect application is the server's implicit ack that the throw landed, which is why the module keys on S1D rather than a fixed post-throw delay: the next pot is only scheduled after the effect arrives, so a missed throw does not stall the sequence. This is the only module in the reference corpus that hooks S1D.anticheat Anti-Cheat Checks
Server-side anticheats treat the entity-effect packet as state synchronization, not a cheat signal. The corpus splits into packet-driven potion trackers (Grim, Artemis, BetterAnticheat, Kauri, Intave) that decode S1D and mirror the effect onto their simulated player or entity, and Bukkit-polling checks (FlopAC, Hydro, Frequency) that read getActivePotionEffects and only see the effect after the server applies it. The trackers matter because movement checks must know the exact speed, jump and slowness multipliers the client has; a potion state mismatch causes false flags in speed and flight checks, so the apply packet is transaction-confirmed before the effect lands in the simulation.
Keep the compensated entity's potion state in sync with the server so movement predictions apply the same speed, jump and slowness multipliers the client sees.
PacketEntityReplication listens on the packet-send side. For ENTITY_EFFECT it decodes the potion type and amplifier, cancels the packet when ViaVersion would fake an effect the client version does not support, forces a transaction when the effect targets the player, and schedules entity.addPotionEffect on the compensated entity at the transaction's real-time position. The remove branch in the same listener mirrors this with entity.removePotionEffect.
// ===== FILE: GrimAnticheat-Grim, common/src/main/java/ac/grim/grimac/events/packets/PacketEntityReplication.java =====
package ac.grim.grimac.events.packets;
import ac.grim.grimac.GrimAPI;
import ac.grim.grimac.api.config.ConfigManager;
import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.type.PacketReceiveListener;
import ac.grim.grimac.checks.type.PacketSendListener;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.anticheat.LogUtil;
import ac.grim.grimac.utils.data.SprintingState;
import ac.grim.grimac.utils.data.TrackerData;
import ac.grim.grimac.utils.data.packetentity.DashableEntity;
import ac.grim.grimac.utils.data.packetentity.PacketEntity;
import ac.grim.grimac.utils.data.packetentity.PacketEntityHook;
import ac.grim.grimac.utils.data.packetentity.PacketEntityTrackXRot;
import ac.grim.grimac.utils.enums.Pose;
import ac.grim.grimac.utils.nmsutil.EntityMetadataPoseUtil;
import ac.grim.grimac.utils.viaversion.ViaVersionUtil;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.EntityPositionData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.InteractionHand;
import com.github.retrooper.packetevents.protocol.player.UserProfile;
import com.github.retrooper.packetevents.protocol.potion.PotionType;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerAttachEntity;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDestroyEntities;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEquipment;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityMetadata;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityPositionSync;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityRelativeMove;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityRelativeMoveAndRotation;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityRotation;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityStatus;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityTeleport;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfo;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoRemove;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoUpdate;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRemoveEntityEffect;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetPassengers;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetSlot;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnLivingEntity;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnPainting;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnPlayer;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAttributes;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerWindowItems;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
public class PacketEntityReplication extends Check implements PacketReceiveListener, PacketSendListener {
private final AtomicBoolean hasSentPreWavePacket = new AtomicBoolean(true);
// Let's imagine the player is on a boat.
// The player breaks this boat
// If we were to despawn the boat without an extra transaction, then the boat would disappear before
// it disappeared on the client side, creating a ghost boat to flag checks with
//
// If we were to despawn the tick after, spawning must occur the transaction before to stop the same exact
// problem with ghost boats in reverse.
//
// Therefore, we despawn the transaction after, and spawn the tick before.
//
// If we despawn then spawn an entity in the same transaction, then this solution would despawn the new entity
// instead of the old entity, so we wouldn't see the boat at all
//
// Therefore, if the server sends a despawn and then a spawn in the same transaction for the same entity,
// We should simply add a transaction (which will clear this list!)
//
// Another valid solution is to simply spam more transactions, but let's not waste bandwidth.
private final List<Integer> despawnedEntitiesThisTransaction = new ArrayList<>();
// Maximum ping when a firework boost is removed from the player.
private int maxFireworkBoostPing = 1000;
public PacketEntityReplication(GrimPlayer player) {
super(player);
}
@Override
public void onPacketReceive(PacketReceiveEvent event) {
// Teleports don't interpolate, duplicate 1.17 packets don't interpolate
if (!isTickPacket(event.getPacketType())) return;
player.compensatedEntities.entitiesRemovedThisTick.clear();
boolean isTickingReliably = player.isTickingReliablyFor(3);
PacketEntity playerVehicle = player.compensatedEntities.self.getRiding();
for (PacketEntity entity : player.compensatedEntities.entityMap.values()) {
if (entity == playerVehicle && !player.vehicleData.lastDummy) {
// The player has this as their vehicle, so they aren't interpolating it.
// And it isn't a dummy position
entity.setPositionRaw(player, entity.getPossibleLocationBoxes());
} else {
entity.onMovement(isTickingReliably);
}
}
if (player.vehicleData.camelSprintingState == SprintingState.STOPPING) {
player.vehicleData.camelSprintingState = SprintingState.STOPPED;
} else if (player.vehicleData.camelSprintingState == SprintingState.STOPPED && player.isSprinting) { // For sprint desyncs
player.vehicleData.camelSprintingState = SprintingState.STARTED;
}
}
@Override
public void onPacketSend(PacketSendEvent event) {
// ensure grim is the one that sent the transaction
if ((event.getPacketType() == PacketType.Play.Server.PING || event.getPacketType() == PacketType.Play.Server.WINDOW_CONFIRMATION) && player.packetStateData.lastServerTransWasValid) {
despawnedEntitiesThisTransaction.clear();
} else if (event.getPacketType() == PacketType.Play.Server.SPAWN_LIVING_ENTITY) {
WrapperPlayServerSpawnLivingEntity packetOutEntity = new WrapperPlayServerSpawnLivingEntity(event);
addEntity(packetOutEntity.getEntityId(), packetOutEntity.getEntityUUID(), packetOutEntity.getEntityType(), packetOutEntity.getPosition(), packetOutEntity.getYaw(), packetOutEntity.getPitch(), packetOutEntity.getEntityMetadata(), 0);
} else if (event.getPacketType() == PacketType.Play.Server.SPAWN_ENTITY) {
WrapperPlayServerSpawnEntity packetOutEntity = new WrapperPlayServerSpawnEntity(event);
addEntity(packetOutEntity.getEntityId(), packetOutEntity.getUUID().orElse(null), packetOutEntity.getEntityType(), packetOutEntity.getPosition(), packetOutEntity.getYaw(), packetOutEntity.getPitch(), null, packetOutEntity.getData());
} else if (event.getPacketType() == PacketType.Play.Server.SPAWN_PLAYER) {
WrapperPlayServerSpawnPlayer packetOutEntity = new WrapperPlayServerSpawnPlayer(event);
addEntity(packetOutEntity.getEntityId(), packetOutEntity.getUUID(), EntityTypes.PLAYER, packetOutEntity.getPosition(), packetOutEntity.getYaw(), packetOutEntity.getPitch(), packetOutEntity.getEntityMetadata(), 0);
} else if (event.getPacketType() == PacketType.Play.Server.SPAWN_PAINTING) {
WrapperPlayServerSpawnPainting packetOutEntity = new WrapperPlayServerSpawnPainting(event);
addEntity(packetOutEntity.getEntityId(), packetOutEntity.getUUID(), EntityTypes.PAINTING, packetOutEntity.getPosition().toVector3d(), 0, 0f, null, packetOutEntity.getDirection().getHorizontalIndex());
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_RELATIVE_MOVE) {
WrapperPlayServerEntityRelativeMove move = new WrapperPlayServerEntityRelativeMove(event);
handleMoveEntity(event, move.getEntityId(), move.getDeltaX(), move.getDeltaY(), move.getDeltaZ(), null, null, true, true);
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_RELATIVE_MOVE_AND_ROTATION) {
WrapperPlayServerEntityRelativeMoveAndRotation move = new WrapperPlayServerEntityRelativeMoveAndRotation(event);
handleMoveEntity(event, move.getEntityId(), move.getDeltaX(), move.getDeltaY(), move.getDeltaZ(), move.getYaw() * 0.7111111F, move.getPitch() * 0.7111111F, true, true);
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_TELEPORT) {
WrapperPlayServerEntityTeleport move = new WrapperPlayServerEntityTeleport(event);
Vector3d pos = move.getPosition();
handleMoveEntity(event, move.getEntityId(), pos.getX(), pos.getY(), pos.getZ(), move.getYaw(), move.getPitch(), false, true);
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_POSITION_SYNC) {
// ENTITY_TELEPORT but without relative flags
WrapperPlayServerEntityPositionSync move = new WrapperPlayServerEntityPositionSync(event);
final EntityPositionData values = move.getValues();
final Vector3d pos = values.getPosition();
// TODO this isn't technically correct
// If the position sync is to a pos > 4096 from the entity pos, client does some special stuff without interpolation
handleMoveEntity(event, move.getId(), pos.getX(), pos.getY(), pos.getZ(), values.getYaw(), values.getPitch(), false, true);
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_ROTATION) { // Affects interpolation
WrapperPlayServerEntityRotation move = new WrapperPlayServerEntityRotation(event);
handleMoveEntity(event, move.getEntityId(), 0, 0, 0, move.getYaw() * 0.7111111F, move.getPitch() * 0.7111111F, true, false);
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) {
WrapperPlayServerEntityMetadata entityMetadata = new WrapperPlayServerEntityMetadata(event);
schedulePoseTransition(entityMetadata, event);
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> player.compensatedEntities.updateEntityMetadata(entityMetadata.getEntityId(), entityMetadata.getEntityMetadata()));
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
WrapperPlayServerEntityEquipment equipment = new WrapperPlayServerEntityEquipment(event);
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> player.compensatedEntities.updateEntityEquipment(equipment.getEntityId(), equipment.getEquipment()));
}
// 1.19.3+
else if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO_UPDATE) {
WrapperPlayServerPlayerInfoUpdate info = new WrapperPlayServerPlayerInfoUpdate(event);
if (info.getActions().contains(WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER)) {
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
for (WrapperPlayServerPlayerInfoUpdate.PlayerInfo entry : info.getEntries()) {
final UserProfile gameProfile = entry.getGameProfile();
final UUID uuid = gameProfile.getUUID();
player.compensatedEntities.profiles.put(uuid, gameProfile);
}
});
}
} else if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO_REMOVE) {
WrapperPlayServerPlayerInfoRemove remove = new WrapperPlayServerPlayerInfoRemove(event);
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> remove.getProfileIds().forEach(player.compensatedEntities.profiles::remove));
} else if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo(event);
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
if (info.getAction() == WrapperPlayServerPlayerInfo.Action.ADD_PLAYER) {
for (WrapperPlayServerPlayerInfo.PlayerData entry : info.getPlayerDataList()) {
final UserProfile gameProfile = entry.getUserProfile();
final UUID uuid = gameProfile.getUUID();
player.compensatedEntities.profiles.put(uuid, gameProfile);
}
} else if (info.getAction() == WrapperPlayServerPlayerInfo.Action.REMOVE_PLAYER) {
info.getPlayerDataList().forEach(profile -> player.compensatedEntities.profiles.remove(profile.getUserProfile().getUUID()));
}
});
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_EFFECT) {
WrapperPlayServerEntityEffect effect = new WrapperPlayServerEntityEffect(event);
PotionType type = effect.getPotionType();
// ViaVersion tries faking levitation effects and fails badly lol, flagging the anticheat
// Block other effects just in case ViaVersion gets any ideas
//
// Set to 24 so ViaVersion blocks it
// 24 is the levitation effect
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_9) && ViaVersionUtil.isAvailable && type.getId(player.getClientVersion()) > 23) {
event.setCancelled(true);
return;
}
// ViaVersion dolphin's grace also messes us up, set it to a potion effect that doesn't exist on 1.12
// Effect 31 is bad omen
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_13) && ViaVersionUtil.isAvailable && type.getId(player.getClientVersion()) == 30) {
event.setCancelled(true);
return;
}
if (isDirectlyAffectingPlayer(player, effect.getEntityId())) player.sendTransaction();
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
PacketEntity entity = player.compensatedEntities.getEntity(effect.getEntityId());
if (entity == null) return;
entity.addPotionEffect(type, effect.getEffectAmplifier());
});
} else if (event.getPacketType() == PacketType.Play.Server.REMOVE_ENTITY_EFFECT) {
WrapperPlayServerRemoveEntityEffect effect = new WrapperPlayServerRemoveEntityEffect(event);
if (isDirectlyAffectingPlayer(player, effect.getEntityId())) player.sendTransaction();
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
PacketEntity entity = player.compensatedEntities.getEntity(effect.getEntityId());
if (entity == null) return;
entity.removePotionEffect(effect.getPotionType());
});
} else if (event.getPacketType() == PacketType.Play.Server.UPDATE_ATTRIBUTES) {
WrapperPlayServerUpdateAttributes attributes = new WrapperPlayServerUpdateAttributes(event);
int entityID = attributes.getEntityId();
// The attributes for this entity is active, currently
if (isDirectlyAffectingPlayer(player, entityID)) player.sendTransaction();
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(),
() -> player.compensatedEntities.updateAttributes(entityID, attributes.getProperties()));
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) {
WrapperPlayServerEntityStatus status = new WrapperPlayServerEntityStatus(event);
// This hasn't changed from 1.7.2 to 1.17
// Needed to exempt players on dead vehicles, as dead entities have strange physics.
if (status.getStatus() == 3) {
PacketEntity entity = player.compensatedEntities.getEntity(status.getEntityId());
if (entity == null) return;
entity.isDead = true;
}
if (status.getStatus() == 9) {
if (status.getEntityId() != player.entityID) return;
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> player.packetStateData.setSlowedByUsingItem(false));
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get() + 1, () -> player.packetStateData.setSlowedByUsingItem(false));
}
if (status.getStatus() == 31) {
PacketEntity hook = player.compensatedEntities.getEntity(status.getEntityId());
if (!(hook instanceof PacketEntityHook hookEntity)) return;
if (hookEntity.attached == player.entityID) {
player.sendTransaction();
// We don't transaction sandwich this, it's too rare to be a real problem.
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> player.uncertaintyHandler.fishingRodPulls.add(hookEntity.owner));
}
}
if (status.getStatus() >= 24 && status.getStatus() <= 28 && status.getEntityId() == player.entityID) {
player.compensatedEntities.self.opLevel = status.getStatus() - 24;
}
} else if (event.getPacketType() == PacketType.Play.Server.SET_SLOT) {
WrapperPlayServerSetSlot slot = new WrapperPlayServerSetSlot(event);
if (slot.getWindowId() == 0) {
Runnable task = () -> {
if (slot.getSlot() - 36 == player.packetStateData.lastSlotSelected && (
!player.inventory.getHeldItem().is(slot.getItem().getType()) || player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)
) || slot.getSlot() == 45 && !player.inventory.getOffHand().is(slot.getItem().getType())) {
InteractionHand hand = slot.getSlot() == 45 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
if (hand == player.packetStateData.itemInUseHand) {
player.packetStateData.setSlowedByUsingItem(false);
}
if (player.isResetItemUsageOnItemUpdate() && hand == GrimAPI.INSTANCE.getItemResetHandler().getItemUsageHand(player.platformPlayer)) {
GrimAPI.INSTANCE.getItemResetHandler().resetItemUsage(player.platformPlayer);
}
}
};
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), task);
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get() + 1, task);
}
} else if (event.getPacketType() == PacketType.Play.Server.WINDOW_ITEMS) {
WrapperPlayServerWindowItems items = new WrapperPlayServerWindowItems(event);
if (items.getWindowId() == 0) { // Player inventory
Runnable task = () -> {
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) {
player.packetStateData.setSlowedByUsingItem(false);
if (player.isResetItemUsageOnItemUpdate()) {
GrimAPI.INSTANCE.getItemResetHandler().resetItemUsage(player.platformPlayer);
}
} else {
if (items.getItems().size() > 45 && !player.inventory.getOffHand().is(items.getItems().get(45).getType())) {
if (player.packetStateData.itemInUseHand == InteractionHand.OFF_HAND) {
player.packetStateData.setSlowedByUsingItem(false);
}
if (player.isResetItemUsageOnItemUpdate() && GrimAPI.INSTANCE.getItemResetHandler().getItemUsageHand(player.platformPlayer) == InteractionHand.OFF_HAND) {
GrimAPI.INSTANCE.getItemResetHandler().resetItemUsage(player.platformPlayer);
}
}
if (!player.inventory.getHeldItem().is(items.getItems().get(player.packetStateData.lastSlotSelected + 36).getType())) {
if (player.packetStateData.itemInUseHand == InteractionHand.MAIN_HAND) {
player.packetStateData.setSlowedByUsingItem(false);
}
if (player.isResetItemUsageOnItemUpdate() && GrimAPI.INSTANCE.getItemResetHandler().getItemUsageHand(player.platformPlayer) == InteractionHand.MAIN_HAND) {
GrimAPI.INSTANCE.getItemResetHandler().resetItemUsage(player.platformPlayer);
}
}
}
};
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), task);
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get() + 1, task);
}
}
// 1.8 clients fail to send the RELEASE_USE_ITEM packet when a window is opened client sided while using an item
else if (event.getPacketType() == PacketType.Play.Server.OPEN_WINDOW) {
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> player.packetStateData.setSlowedByUsingItem(false));
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get() + 1, () -> player.packetStateData.setSlowedByUsingItem(false));
} else if (event.getPacketType() == PacketType.Play.Server.OPEN_HORSE_WINDOW) {
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> player.packetStateData.setSlowedByUsingItem(false));
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get() + 1, () -> player.packetStateData.setSlowedByUsingItem(false));
} else if (event.getPacketType() == PacketType.Play.Server.SET_PASSENGERS) {
WrapperPlayServerSetPassengers mount = new WrapperPlayServerSetPassengers(event);
int vehicleID = mount.getEntityId();
int[] passengers = mount.getPassengers();
handleMountVehicle(event, vehicleID, passengers);
} else if (event.getPacketType() == PacketType.Play.Server.ATTACH_ENTITY) {
WrapperPlayServerAttachEntity attach = new WrapperPlayServerAttachEntity(event);
// This packet was replaced by the mount packet on 1.9+ servers - to support multiple passengers on one vehicle
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9))
return;
// If this is mounting rather than leashing
if (!attach.isLeash()) {
// Alright, let's convert this to the 1.9+ format to make it easier for grim
int vehicleID = attach.getHoldingId();
int attachID = attach.getAttachedId();
TrackerData trackerData = player.compensatedEntities.getTrackedEntity(attachID);
if (trackerData != null) {
// 1.8 sends a vehicle ID of -1 to dismount the entity from its vehicle
// This is opposite of the 1.9+ format, which sends the vehicle ID and then an empty array.
if (vehicleID == -1) { // Dismounting
vehicleID = trackerData.getLegacyPointEightMountedUpon();
handleMountVehicle(event, vehicleID, new int[]{}); // The vehicle is empty
} else { // Mounting
trackerData.setLegacyPointEightMountedUpon(vehicleID);
handleMountVehicle(event, vehicleID, new int[]{attachID});
}
} else {
// I don't think we can recover from this... warn and move on as this shouldn't happen.
LogUtil.warn("Server sent an invalid attach entity packet for entity " + attach.getHoldingId() + " with passenger " + attach.getAttachedId() + "! The client ignores this.");
}
}
} else if (event.getPacketType() == PacketType.Play.Server.DESTROY_ENTITIES) {
WrapperPlayServerDestroyEntities destroy = new WrapperPlayServerDestroyEntities(event);
int[] destroyEntityIds = destroy.getEntityIds();
for (int entityID : destroyEntityIds) {
despawnedEntitiesThisTransaction.add(entityID);
player.compensatedEntities.serverPositionsMap.remove(entityID);
// Remove the tracked vehicle (handling tracking knockback) if despawned
if (player.compensatedEntities.serverPlayerVehicle != null && player.compensatedEntities.serverPlayerVehicle == entityID) {
player.compensatedEntities.serverPlayerVehicle = null;
}
}
final int destroyTransaction = player.lastTransactionSent.get() + 1;
player.latencyUtils.addRealTimeTask(destroyTransaction, () -> {
for (int entityId : destroyEntityIds) {
player.compensatedEntities.removeEntity(entityId);
player.dashableEntities.removeEntity(entityId);
player.fireworks.removeFirework(entityId);
player.compensatedEntities.entitiesRemovedThisTick.add(entityId);
}
});
// Don't let the player freeze transactions to keep the firework boost velocity + uncertainty
// Also generally prevents people with high ping gaining too high an advantage in firework use
if (maxFireworkBoostPing > 0) {
player.runNettyTaskInMs(() -> {
if (player.lastTransactionReceived.get() >= destroyTransaction) return;
for (int entityID : destroyEntityIds) {
// If the player has a firework boosting them, setback
if (player.fireworks.hasFirework(entityID)) {
player.getSetbackTeleportUtil().executeViolationSetback();
break;
}
}
}, maxFireworkBoostPing);
}
}
}
private void handleMountVehicle(PacketSendEvent event, int vehicleID, int[] passengers) {
boolean wasInVehicle = player.compensatedEntities.serverPlayerVehicle != null && player.compensatedEntities.serverPlayerVehicle == vehicleID;
boolean inThisVehicle = false;
for (int passenger : passengers) {
inThisVehicle = passenger == player.entityID;
if (inThisVehicle) break;
}
if (inThisVehicle && !wasInVehicle) {
player.handleMountVehicle(vehicleID);
}
if (!inThisVehicle && wasInVehicle) {
player.handleDismountVehicle(event);
}
// Better lag compensation if we were affected by this
if (wasInVehicle || inThisVehicle) {
player.sendTransaction();
}
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
PacketEntity vehicle = player.compensatedEntities.getEntity(vehicleID);
// Vanilla likes sending null vehicles, so we must ignore those like the client ignores them
if (vehicle == null) return;
// Eject existing passengers for this vehicle
for (PacketEntity passenger : new ArrayList<>(vehicle.passengers)) {
passenger.eject();
}
// Add the entities as vehicles
for (int entityID : passengers) {
PacketEntity passenger = player.compensatedEntities.getEntity(entityID);
if (passenger == null) continue;
passenger.mount(vehicle);
}
});
}
private void handleMoveEntity(PacketSendEvent event, int entityId, double deltaX, double deltaY, double deltaZ, Float yaw, Float pitch, boolean isRelative, boolean hasPos) {
TrackerData data = player.compensatedEntities.getTrackedEntity(entityId);
final boolean didNotSendPreWave = hasSentPreWavePacket.compareAndSet(false, true);
if (didNotSendPreWave) player.sendTransaction();
if (data != null) {
// Update the tracked server's entity position
if (isRelative) {
// There is a bug where vehicles may start flying due to mojang setting packet position on the client
// (Works at 0 ping but causes funny bugs at any higher ping)
// As we don't want vehicles to fly, we need to replace it with a teleport if it is player vehicle
//
// Don't bother with client controlled vehicles though
boolean vanillaVehicleFlight = player.compensatedEntities.serverPlayerVehicle != null
&& player.compensatedEntities.serverPlayerVehicle == entityId
&& player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9)
// TODO: https://discord.com/channels/721686193061888071/721686193515003966/1310659538831020123
// Why does the server now send an entity rel move packet matching the player's vehicle movement every time?
&& PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_21_2)
&& PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9);
// ViaVersion sends two relative packets when moving more than 4 blocks
// This is broken and causes the client to interpolate like (0, 4) and (1, 3) instead of (1, 7)
// This causes impossible hits, so grim must replace this with a teleport entity packet
// Not ideal, but neither is 1.8 players on a 1.9+ server.
if (vanillaVehicleFlight ||
((Math.abs(deltaX) >= 3.9375 || Math.abs(deltaY) >= 3.9375 || Math.abs(deltaZ) >= 3.9375) && player.getClientVersion().isOlderThan(ClientVersion.V_1_9) && PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9))) {
player.user.writePacket(new WrapperPlayServerEntityTeleport(entityId, new Vector3d(data.getX() + deltaX, data.getY() + deltaY, data.getZ() + deltaZ), yaw == null ? data.getXRot() : yaw, pitch == null ? data.getYRot() : pitch, false));
event.setCancelled(true);
return;
}
data.setX(data.getX() + deltaX);
data.setY(data.getY() + deltaY);
data.setZ(data.getZ() + deltaZ);
} else {
data.setX(deltaX);
data.setY(deltaY);
data.setZ(deltaZ);
}
if (yaw != null) {
data.setXRot(yaw);
data.setYRot(pitch);
}
// We can't hang two relative moves on one transaction
if (data.getLastTransactionHung() == player.lastTransactionSent.get()) {
player.sendTransaction();
}
data.setLastTransactionHung(player.lastTransactionSent.get());
}
int lastTrans = player.lastTransactionSent.get();
player.latencyUtils.addRealTimeTask(lastTrans, () -> {
PacketEntity entity = player.compensatedEntities.getEntity(entityId);
if (entity == null) return;
if (entity instanceof PacketEntityTrackXRot xRotEntity && yaw != null) {
xRotEntity.packetYaw = yaw;
xRotEntity.steps = entity.isBoat ? 10 : 3;
}
entity.onFirstTransaction(isRelative, hasPos, deltaX, deltaY, deltaZ, player);
});
player.latencyUtils.addRealTimeTask(lastTrans + 1, () -> {
PacketEntity entity = player.compensatedEntities.getEntity(entityId);
if (entity == null) return;
entity.onSecondTransaction();
});
}
public void addEntity(int entityID, UUID uuid, EntityType type, Vector3d position, float xRot, float yRot, List<EntityData<?>> entityMetadata, int extraData) {
if (despawnedEntitiesThisTransaction.contains(entityID)) {
player.sendTransaction();
}
player.compensatedEntities.serverPositionsMap.put(entityID, new TrackerData(position.getX(), position.getY(), position.getZ(), xRot, yRot, type, player.lastTransactionSent.get()));
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
PacketEntity entity = player.compensatedEntities.addEntity(entityID, uuid, type, position, xRot, extraData);
if (entity instanceof DashableEntity dashable) {
player.dashableEntities.addEntity(entityID, dashable);
}
if (entityMetadata != null) {
if (EntityMetadataPoseUtil.usesPoseMetadata(entity) && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) {
Pose initialPose = EntityMetadataPoseUtil.getPoseFromMetadata(entityMetadata);
if (initialPose != null) {
entity.currentPose = initialPose;
}
}
player.compensatedEntities.updateEntityMetadata(entityID, entityMetadata);
}
});
}
private void schedulePoseTransition(WrapperPlayServerEntityMetadata entityMetadata, PacketSendEvent event) {
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_14)) return;
int entityId = entityMetadata.getEntityId();
if (entityId == player.entityID) return;
Pose newPose = EntityMetadataPoseUtil.getPoseFromMetadata(entityMetadata.getEntityMetadata());
if (newPose == null) return;
boolean shouldTrackPoseTransition = false;
PacketEntity entity = player.compensatedEntities.getEntity(entityId);
if (entity != null) {
shouldTrackPoseTransition = EntityMetadataPoseUtil.usesPoseMetadata(entity);
} else {
// If the client didn't respond to the spawn packet yet, we need to check if we should track the pose transition based on the entity type
// is there a better way to do this?
TrackerData trackedEntity = player.compensatedEntities.getTrackedEntity(entityId);
if (trackedEntity != null) {
shouldTrackPoseTransition = EntityMetadataPoseUtil.usesPoseMetadata(trackedEntity.getEntityType());
}
}
if (!shouldTrackPoseTransition) return;
player.sendTransaction();
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
PacketEntity target = player.compensatedEntities.getEntity(entityId);
if (target == null) {
return;
}
target.beginPoseTransition(newPose);
});
event.getTasksAfterSend().add(() -> {
player.sendTransaction();
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
PacketEntity target = player.compensatedEntities.getEntity(entityId);
if (target == null) {
return;
}
target.completePoseTransition(newPose);
});
});
}
private boolean isDirectlyAffectingPlayer(GrimPlayer player, int entityID) {
// The attributes for this entity is active, currently
return (player.compensatedEntities.serverPlayerVehicle == null && entityID == player.entityID) ||
(player.compensatedEntities.serverPlayerVehicle != null && entityID == player.compensatedEntities.serverPlayerVehicle);
}
public void onEndOfTickEvent(boolean async, boolean flush) {
// Only send a transaction at the end of the tick if we are tracking players
player.sendTransaction(async);
if (flush) player.user.flushPackets();
}
public void tickStartTick() {
hasSentPreWavePacket.set(false);
}
@Override
public void onReload(@NotNull ConfigManager config) {
maxFireworkBoostPing = config.getIntElse("max-ping-firework-boost", 1000);
}
}
// NOTE (AI): The entity-effect branches sit at lines 193-233; the rest of the file replicates other clientbound state (player info, attributes, status, slots) through the same transaction mechanism.Maintain the user's active effect list from the entity-effect packet so checks and the emulator can read current potion modifiers.
fastHandle matches GPacketPlayServerEntityEffect, builds a PotionEffect from the effect id, duration and amplifier, then queues the add behind a transaction confirmation: pre() inserts the effect and marks it processed, post() clears the marker. It also clears the using-item flag when the effect ends item use.
// ===== FILE: artemisac-artemis-minecraft-anticheat, ac.artemis.core/src/main/java/ac/artemis/core/v4/processor/potion/PotionPreProcessor.java =====
package ac.artemis.core.v4.processor.potion;
import ac.artemis.core.v4.check.FastProcessHandler;
import ac.artemis.core.v4.data.holders.ConnectionHolder;
import ac.artemis.core.v4.utils.function.PacketAction;
import cc.ghast.packet.PacketAPI;
import ac.artemis.packet.spigot.wrappers.GPacket;
import cc.ghast.packet.wrapper.packet.play.client.GPacketPlayClientTransaction;
import ac.artemis.core.v4.data.PlayerData;
import ac.artemis.core.v4.emulator.potion.PotionEffect;
import ac.artemis.core.v4.processor.AbstractHandler;
import cc.ghast.packet.wrapper.packet.play.server.GPacketPlayServerEntityEffect;
import cc.ghast.packet.wrapper.packet.play.server.GPacketPlayServerEntityEffectRemove;
import java.util.Map;
import java.util.Random;
import java.util.WeakHashMap;
public class PotionPreProcessor extends AbstractHandler implements FastProcessHandler {
public PotionPreProcessor(PlayerData data) {
super("Potion [0x01]", data);
}
@Override
public void handle(final GPacket packet) {
}
@Override
public void fastHandle(GPacket packet) {
if (packet instanceof GPacketPlayServerEntityEffect) {
final GPacketPlayServerEntityEffect eff = (GPacketPlayServerEntityEffect) packet;
if (eff.getEntityId() == data.getPlayer().getEntityId()) {
final PotionEffect effect = new PotionEffect(eff.getEffectId(), eff.getDuration(), eff.getAmplifier());
data.connection.confirmFunction(ConnectionHolder.ConfirmationType.TRANSACTION, new PacketAction() {
@Override
public void pre() {
data.user.getEffects().add(effect);
data.user.setLastAddEffect(effect);
data.user.setEffectAddProcessed(true);
if (data.user.isUsingItem() && data.user.isUsingPotion()) {
data.user.setUsingItem(false);
data.user.setUsingPotion(false);
}
}
@Override
public void post() {
data.user.setEffectAddProcessed(false);
}
});
}
}
else if (packet instanceof GPacketPlayServerEntityEffectRemove) {
final GPacketPlayServerEntityEffectRemove eff = (GPacketPlayServerEntityEffectRemove) packet;
if (eff.getEntityId() == data.getPlayer().getEntityId()) {
final PotionEffect effect = data.user.getEffects().parallelStream().filter(e -> e.getPotionID() == eff.getEffectId()).findAny().orElse(null);
if (effect == null) return;
data.connection.confirmFunction(ConnectionHolder.ConfirmationType.TRANSACTION, new PacketAction() {
@Override
public void pre() {
data.user.getEffects().remove(effect);
data.user.setLastRemoveEffect(effect);
data.user.setEffectRemoveProcessed(true);
}
@Override
public void post() {
data.user.setEffectRemoveProcessed(false);
}
});
}
}
}
}
// NOTE (AI): The S1D branch is lines 32-57; the sibling remove branch (lines 59-81) is documented under S1EPacketRemoveEntityEffect.Track each potion type's amplifier and duration as a lag-compensated many-state so checks read the effect that actually reached the client.
PotionTracker subscribes to ENTITY_EFFECT on the send side, takes a confirmation handle, and stages the new Potion in an ObjectManyState: addNew on begin, flushOld plus an active-count after the client confirms. REMOVE_ENTITY_EFFECT stages an EMPTY_POTION the same way so an expired effect cannot linger.
// ===== FILE: amnoah-BetterAnticheat, core/src/main/java/better/anticheat/core/player/tracker/impl/potion/PotionTracker.java =====
package better.anticheat.core.player.tracker.impl.potion;
import better.anticheat.core.player.Player;
import better.anticheat.core.player.tracker.Tracker;
import com.github.retrooper.packetevents.event.simple.PacketPlayReceiveEvent;
import com.github.retrooper.packetevents.event.simple.PacketPlaySendEvent;
import com.github.retrooper.packetevents.protocol.attribute.Attributes;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.potion.PotionType;
import com.github.retrooper.packetevents.protocol.potion.PotionTypes;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRemoveEntityEffect;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAttributes;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import wtf.spare.sparej.incrementer.IntIncrementer;
import wtf.spare.sparej.xstate.manystate.ObjectManyState;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class PotionTracker extends Tracker {
private static final Potion EMPTY_POTION = new Potion(0, -1);
private final Map<PotionType, ObjectManyState<Potion>> potionMap = new Object2ObjectArrayMap<>();
public PotionTracker(Player player) {
super(player);
for (PotionType potionType : PotionTypes.values()) {
ObjectManyState<Potion> newManyState = new ObjectManyState<>();
newManyState.addNew(EMPTY_POTION);
potionMap.put(potionType, newManyState);
}
}
public ObjectManyState<Potion> getPotion(PotionType potionType) {
return potionMap.get(potionType);
}
@Override
public void handlePacketPlayReceive(PacketPlayReceiveEvent event) {
if (event.getPacketType() != PacketType.Play.Client.CLIENT_TICK_END) return;
// Prevent concurrent modifications.
List<PotionType> removals = new ArrayList<>();
/*
* TODO: Figure out if this is necessary.
* If I'm totally honest, I don't know whether the server or client has definitive control of when a potion
* has ended. I'd assume based on
for (PotionType key : potionMap.keySet()) {
ObjectManyState<Potion> potions = potionMap.get(key);
if (potions.getCurrent().getActiveCount() != null) {
potions.getCurrent().getActiveCount().increment();
if (!potions.getCurrent().isActive()) removals.add(key);
continue;
}
if (potions.getOld() != null && potions.getOld().getActiveCount() != null) {
potions.getOld().getActiveCount().increment();
if (!potions.getOld().isActive()) potions.flushOld();
}
}
for (PotionType potionType : removals) potionMap.remove(potionType);
*/
}
@Override
public void handlePacketPlaySend(PacketPlaySendEvent event) {
switch (event.getPacketType()) {
case ENTITY_EFFECT -> {
WrapperPlayServerEntityEffect wrapper = new WrapperPlayServerEntityEffect(event);
if (wrapper.getEntityId() != player.getUser().getEntityId()) return;
var confirmation = player.getConfirmationTracker().confirm();
Potion potion = new Potion(wrapper.getEffectAmplifier(), wrapper.getEffectDurationTicks());
confirmation.onBegin(() -> {
potionMap.get(wrapper.getPotionType()).addNew(potion);
});
confirmation.onAfterConfirm(() -> {
potionMap.get(wrapper.getPotionType()).flushOld();
potion.setActiveCount(new IntIncrementer(0));
});
}
case REMOVE_ENTITY_EFFECT -> {
WrapperPlayServerRemoveEntityEffect wrapper = new WrapperPlayServerRemoveEntityEffect(event);
if (wrapper.getEntityId() != player.getUser().getEntityId()) return;
event.getUser().sendMessage("Removed potion!");
var confirmation = player.getConfirmationTracker().confirm();
/*
* When this packet is beginning to be received, we should begin to transition to an empty potion state
* for this effect. By the time it has been officially received, we should remove the old potion that
* was in there.
*/
confirmation.onBegin(() -> potionMap.get(wrapper.getPotionType()).addNew(EMPTY_POTION));
confirmation.onAfterConfirm(() -> potionMap.get(wrapper.getPotionType()).flushOld());
}
}
}
}
// NOTE (AI): The ENTITY_EFFECT branch is lines 75-89; the remove branch is lines 90-105. The commented block in handlePacketPlayReceive is an abandoned tick-based expiry idea.Keep a thread-safe potion effect list on the player data so movement and velocity checks can query current modifiers.
PotionHandler seeds the list from the Bukkit player's active effects at construction, then onPotionEffect(WrapperPlayServerEntityEffect) replaces the entry for the potion type under a write lock, storing the amplifier, duration and visibility flags. hasPotionEffect and getEffectByType expose the state to checks.
// ===== FILE: funkemunky-KauriV3, Anticheat/src/main/java/dev/brighten/ac/handler/PotionHandler.java =====
package dev.brighten.ac.handler;
import com.github.retrooper.packetevents.protocol.potion.PotionType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect;
import dev.brighten.ac.data.APlayer;
import dev.brighten.ac.utils.KPotionEffect;
import dev.brighten.ac.utils.KProperties;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class PotionHandler {
private final APlayer data;
private final List<KPotionEffect> potionEffects = new ArrayList<>();
private final ReadWriteLock lock = new ReentrantReadWriteLock();
public PotionHandler(APlayer data) {
this.data = data;
lock.writeLock().lock();
try {
data.getBukkitPlayer().getActivePotionEffects().stream()
.map(pe ->
new KPotionEffect(
SpigotConversionUtil.fromBukkitPotionEffectType(pe.getType()),
KProperties.fromBukkit(pe)
))
.forEach(potionEffects::add);
} finally {
lock.writeLock().unlock();
}
}
public void onFlying(WrapperPlayClientPlayerFlying packet) {
lock.readLock().lock();
try {
for (KPotionEffect effect : potionEffects) {
lock.readLock().lock();
try {
if (data.getBukkitPlayer().hasPotionEffect(SpigotConversionUtil.toBukkitPotionEffectType(effect.potionType()))) continue;
data.runKeepaliveAction(d -> {
lock.writeLock().lock();
try {
data.getPotionHandler().potionEffects.remove(effect);
} finally {
lock.writeLock().unlock();
}
});
} finally {
lock.readLock().unlock();
}
}
} finally {
lock.readLock().unlock();
}
}
public void onPotionEffect(WrapperPlayServerEntityEffect packet) {
data.runKeepaliveAction(d -> {
var type = packet.getPotionType();
lock.writeLock().lock();
try {
data.getPotionHandler().potionEffects.removeIf(pe -> pe.potionType().equals(type));
data.getPotionHandler().potionEffects
.add(new KPotionEffect(type, new KProperties(packet.getEffectAmplifier()
, packet.getEffectDurationTicks(),
packet.isAmbient(), packet.isVisible(), packet.isShowIcon(), null)));
} finally {
lock.readLock().unlock();
}
});
}
public boolean hasPotionEffect(PotionType type) {
lock.readLock().lock();
try {
for (KPotionEffect potionEffect : potionEffects) {
if (potionEffect.potionType().equals(type))
return true;
}
return false;
} finally {
lock.readLock().unlock();
}
}
public Optional<KPotionEffect> getEffectByType(PotionType type) {
lock.readLock().lock();
try {
for (KPotionEffect potionEffect : potionEffects) {
if (potionEffect.potionType().equals(type))
return Optional.of(potionEffect);
}
return Optional.empty();
} finally {
lock.readLock().unlock();
}
}
public List<KPotionEffect> getPotionEffects() {
lock.readLock().lock();
try {
return new ArrayList<>(potionEffects);
} finally {
lock.readLock().unlock();
}
}
}
// NOTE (AI): onPotionEffect (lines 67-81) is the S1D consumer; the onFlying path polls Bukkit state to catch expiries the server already removed.Extract effect type, amplifier and duration from the entity-effect packet across every supported protocol version.
EntityEffectReader is registered for the ENTITY_EFFECT packet in PacketReaders. effectType() reads the potion-type field on 1.19+, the integer slot on 1.18.2, and the legacy byte below; effectAmplifier() and effectDuration() shift their field indexes at 1.21. Each accessor falls back to 0 on a missing field.
// ===== FILE: intave-intave, src/main/java/de/jpx3/intave/packet/reader/EntityEffectReader.java =====
package de.jpx3.intave.packet.reader;
import com.comphenix.protocol.events.PacketContainer;
import de.jpx3.intave.adapter.MinecraftVersions;
import org.bukkit.potion.PotionEffectType;
import static de.jpx3.intave.adapter.MinecraftVersions.VER1_21;
public final class EntityEffectReader extends EntityReader {
private static final boolean SECURE_CHAT = MinecraftVersions.VER1_19.atOrAbove();
private static final boolean CAVE_AND_CLIFFS = MinecraftVersions.VER1_18_2.atOrAbove();
public int effectType() {
PacketContainer packet = packet();
if (SECURE_CHAT) {
PotionEffectType potionEffectType = packet.getEffectTypes().readSafely(0);
if (potionEffectType == null) {
return 0;
}
//noinspection deprecation
return potionEffectType.getId();
} else if (CAVE_AND_CLIFFS) {
Integer potionEffectType = packet.getIntegers().readSafely(1);
if (potionEffectType == null) {
return 0;
}
return potionEffectType;
} else {
Byte potionEffectType = packet.getBytes().readSafely(0);
if (potionEffectType == null) {
potionEffectType = 0;
}
return potionEffectType;
}
}
public int effectAmplifier() {
PacketContainer packet = packet();
if (VER1_21.atOrAbove()) {
Integer potionEffectAmplifier = packet.getIntegers().readSafely(1);
if (potionEffectAmplifier == null) {
potionEffectAmplifier = 0;
}
return potionEffectAmplifier;
} else {
Byte potionEffectAmplifier = packet.getBytes().readSafely(CAVE_AND_CLIFFS ? 0 : 1);
if (potionEffectAmplifier == null) {
potionEffectAmplifier = 0;
}
return potionEffectAmplifier;
}
}
public int effectDuration() {
int fieldIndex = VER1_21.atOrAbove() ? 3 : (CAVE_AND_CLIFFS && !SECURE_CHAT ? 2 : 1);
Integer potionEffectDuration = packet().getIntegers().readSafely(fieldIndex);
if (potionEffectDuration == null) {
potionEffectDuration = 0;
}
return potionEffectDuration;
}
}
// NOTE (AI): ProtocolLib readSafely accessors with version-dependent indexes; the reader is wired in PacketReaders.setup(ENTITY_EFFECT, ...).Related Packets
Wiki Cross-Reference
The client displays the effect level as amplifier plus one, so amplifier 0 means level 1.
MCP 1.8.9 S1DPacketEntityEffect implements Packet
1.8.9 callers: EntityTrackerEntry.? sends new S1DPacketEntityEffect (line 452) +2 more: https://github.com/Marcelektro/MavenMCP-1.8.9/blob/master/src/main/java/net/minecraft/entity/EntityTrackerEntry.java
Cross-checked against minecraft.wiki (CC BY-SA 3.0) for 1.8.9 accuracy.
Vanilla Internals
Full 1.8.9 logic-class sources that send or handle this packet, stored verbatim.