Class CustomPacketPayloadWrapper

java.lang.Object
com.comphenix.protocol.wrappers.CustomPacketPayloadWrapper

public final class CustomPacketPayloadWrapper extends Object
A wrapper for the CustomPacketPayload class in 1.20.2. Due to the nature of the class, not all types are supported by default. Constructing a new wrapper instance will give out a handle to a completely new implemented type, that allows to set a key and some kind of data of any choice.

Note that constructing this class from a generic handle is only possible for the spigot-specific UnknownPayload type. All other payloads should be accessed via a structure modifier directly.

  • Constructor Details

    • CustomPacketPayloadWrapper

      public CustomPacketPayloadWrapper(byte[] payload, MinecraftKey id)
      Constructs a new payload wrapper instance using the given message payload and id.
      Parameters:
      payload - the payload of the message.
      id - the id of the message.
      Throws:
      NullPointerException - if the given payload or id is null.
  • Method Details

    • getCustomPacketPayloadClass

      public static Class<?> getCustomPacketPayloadClass()
      Get the CustomPacketPayload class that is backing this wrapper (available since Minecraft 1.20.2).
      Returns:
      the CustomPacketPayload class.
    • getConverter

      public static EquivalentConverter<CustomPacketPayloadWrapper> getConverter()
      Get a converter to convert this wrapper to a generic handle and an UnknownPayload type to this wrapper.
      Returns:
      a converter for this wrapper.
    • fromUnknownPayload

      public static CustomPacketPayloadWrapper fromUnknownPayload(Object payload)
      Constructs this wrapper from any CustomPayload type.

      Note: the buffer of the given payload (if any) will NOT be released by this operation. Make sure to release the buffer manually if you discard the packet to prevent memory leaks.

      Parameters:
      payload - the instance of the custom payload to convert to this wrapper.
      Returns:
      a wrapper holding the minecraft key and payload of the given custom payload instance.
    • getPayload

      public byte[] getPayload()
      Get the message payload of this wrapper. Changes made to the returned array will be reflected into this wrapper.
      Returns:
      the message payload.
    • getId

      public MinecraftKey getId()
      Get the message id of this wrapper.
      Returns:
      the message id of this wrapper.
    • newHandle

      public Object newHandle()
      Constructs a NEW handle instance of a payload wrapper to use in a CustomPayload packet.
      Returns:
      a new payload wrapper instance using the provided message id and payload.