ProtocolLib icon indicating copy to clipboard operation
ProtocolLib copied to clipboard

Getting MinecraftKey from Listener CUSTOM_PAYLOAD 1.20.5+

Open deHasher opened this issue 1 year ago • 1 comments

Make sure you're doing the following

  • [✓] You're using the latest build for your server version
  • [✓] This isn't an issue caused by another plugin
  • [✓] You've checked for duplicate issues
  • [✓] You didn't use /reload

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 avatar Aug 01 '24 03:08 deHasher

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

deHasher avatar Aug 01 '24 04:08 deHasher