Interface CommandAPIPacket
- All Known Implementing Classes:
ProtocolVersionTooOldPacket,SetVersionPacket,UpdateRequirementsPacket
The write(FriendlyByteBuffer, Object, int) method should be mirrored by a static
deserialize(FriendlyByteBuffer input) method. This deserialize method can assume any
bytes written by the write method will be present to reconstruct this packet from an array of bytes.
To set up a packet properly, it needs to be registered to one of the channels of CommandAPIProtocol. There,
the packet's deserialize method will be linked to a protocol id. An appropriate method should be added
to one of the implementations of CommandAPIPacketHandler to handle this packet when received.
It is also recommended to make the packet a record. This creates appropriate implementations for Object.toString(),
Object.equals(Object), and Object.hashCode(), which helps with compatibility with certain error messages
and the testing framework.
-
Method Summary
Modifier and TypeMethodDescriptionvoidwrite(FriendlyByteBuffer buffer, Object target, int protocolVersion) Writes the data of this packet to aFriendlyByteBuffer.
-
Method Details
-
write
void write(FriendlyByteBuffer buffer, Object target, int protocolVersion) throws ProtocolVersionTooOldException Writes the data of this packet to aFriendlyByteBuffer.- Parameters:
buffer- The byte buffer to write to.target- The OutputChannel this packet is being sent to.protocolVersion- TheCommandAPIProtocol.PROTOCOL_VERSIONof the CommandAPI instance this packet is being sent to. Implementations of this method should make sure not to send any data the receiving instance can not understand. If this packet simply cannot be sent to the receiving version, it is appropriate to throw anProtocolVersionTooOldException.- Throws:
ProtocolVersionTooOldException- if this packet cannot be sent to the receiving protocol version.
-