Package com.comphenix.protocol.wrappers
Class CustomPacketPayloadWrapper
java.lang.Object
com.comphenix.protocol.wrappers.CustomPacketPayloadWrapper
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 Summary
ConstructorsConstructorDescriptionCustomPacketPayloadWrapper(byte[] payload, MinecraftKey id) Constructs a new payload wrapper instance using the given message payload and id. -
Method Summary
Modifier and TypeMethodDescriptionstatic CustomPacketPayloadWrapperfromUnknownPayload(Object payload) Constructs this wrapper from any CustomPayload type.Get a converter to convert this wrapper to a generic handle and an UnknownPayload type to this wrapper.static Class<?> Get the CustomPacketPayload class that is backing this wrapper (available since Minecraft 1.20.2).getId()Get the message id of this wrapper.byte[]Get the message payload of this wrapper.Constructs a NEW handle instance of a payload wrapper to use in a CustomPayload packet.
-
Constructor Details
-
CustomPacketPayloadWrapper
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
Get the CustomPacketPayload class that is backing this wrapper (available since Minecraft 1.20.2).- Returns:
- the CustomPacketPayload class.
-
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
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
Get the message id of this wrapper.- Returns:
- the message id of this wrapper.
-
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.
-