dmulloy2 / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.
GNU General Public License v2.0
1.04k stars 257 forks source link

Getting MinecraftKey from Listener CUSTOM_PAYLOAD 1.20.5+ #3161

Open deHasher opened 3 months ago

deHasher commented 3 months ago

Make sure you're doing the following

Describe the question On version 1.20.5-1.20.6+ my getChannel() method was broken, how can I fix this? As I understand it, the structure has changed a lot and now something like handle.getStreamCodecs() should be used)

Code

public class WrapperPlayClientCustomPayload extends AbstractPacket {
    public static final PacketType TYPE = PacketType.Play.Client.CUSTOM_PAYLOAD;

    public WrapperPlayClientCustomPayload() {
        super(new PacketContainer(TYPE), TYPE);
        handle.getModifier().writeDefaults();
    }

    public WrapperPlayClientCustomPayload(PacketContainer packet) {
        super(packet, TYPE);
    }

    public MinecraftKey getChannel() {
        // return handle.getMinecraftKeys().readSafely(0); // 1.16.5-1.20.1
        return handle.getCustomPacketPayloads().readSafely(0).getId(); // 1.20.2-1.20.4
    }
}
deHasher commented 3 months ago

https://gist.github.com/deHasher/3a9e3730f2039e359e646eea8f799375