From 1260aa1de5634cb73efa801f4a6dfc5f6d78d133 Mon Sep 17 00:00:00 2001 From: booky10 Date: Fri, 30 Aug 2024 22:53:19 +0200 Subject: [PATCH] Add some transformations for slot changes --- .../util/PacketTransformationUtil.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/github/retrooper/packetevents/util/PacketTransformationUtil.java b/api/src/main/java/com/github/retrooper/packetevents/util/PacketTransformationUtil.java index a2c9fa2a8d..4e333f7fd0 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/util/PacketTransformationUtil.java +++ b/api/src/main/java/com/github/retrooper/packetevents/util/PacketTransformationUtil.java @@ -19,13 +19,15 @@ package com.github.retrooper.packetevents.util; import com.github.retrooper.packetevents.manager.server.ServerVersion; -import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper; import com.github.retrooper.packetevents.protocol.player.Equipment; import com.github.retrooper.packetevents.protocol.world.chunk.LightData; import com.github.retrooper.packetevents.wrapper.PacketWrapper; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerChunkData; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDestroyEntities; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEquipment; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetCursorItem; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetPlayerInventory; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetSlot; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateLight; import java.util.Collections; @@ -73,6 +75,18 @@ public static PacketWrapper[] transform(PacketWrapper wrapper) { return output; } + } else if (wrapper instanceof WrapperPlayServerSetSlot) { + // some plugins will probably fail to update this correctly, so just transform it when sending + WrapperPlayServerSetSlot setSlot = (WrapperPlayServerSetSlot) wrapper; + if (setSlot.getSlot() == -1) { // transform to cursor item + if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_2)) { + wrapper = new WrapperPlayServerSetCursorItem(setSlot.getItem()); + } + } else if (setSlot.getWindowId() == -2) { // transform to player inventory set + if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_2)) { + wrapper = new WrapperPlayServerSetPlayerInventory(setSlot.getSlot(), setSlot.getItem()); + } + } } return new PacketWrapper[]{wrapper}; }