Solved Extract Position from Chat message (ProtocolLib)

Discussion in 'Spigot Plugin Development' started by Kiryu144, Feb 1, 2020.

  1. Looking at the following packet I am having a listener to:

    [​IMG]
    I am trying to get the Position Byte.
    I have tried a lot, but I don't really understand ProtocolAPI's Packet class.

    Here is what I have so far
    Code (Java):
    ProtocolLibrary.getProtocolManager().addPacketListener(
                new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.CHAT) {
                    @Override
                    public void onPacketSending(PacketEvent event) {
                        String message = event.getPacket().getChatComponents().getValues().get(0).getJson();
                        System.out.println(message);
                    }
                }
            );
     
  2. SteelPhoenix

    Moderator

    In newer versions ProtocolLib has an enum for this

    Code (Java):
    public ChatType getChatType() {
        return handle.getChatTypes().read(0);
    }
    public void setChatType(ChatType type) {
        handle.getChatTypes().write(0, type);
    }
    Otherwise you just read/write the byte at the first index
     
  3. Alright, that was the solution. Thank you! :D