Skip to content

SendPacket ​

com.jsmacrosce.jsmacros.client.api.event.impl.EventSendPacket

Since1.8.4Cancellable

Fires synchronously at the client's packet-send path, including for non-gameplay packets.
Listeners can cancel sending or replace packet; assigning null drops the packet.
A buffer from getPacketBuffer() is independent, so apply edits by decoding it and assigning the result to packet. Use a filterer to limit which packets invoke a listener.

Filterer: FiltererSendPacket. Create it with JsMacros.createEventFilterer("SendPacket") and pass it to the filterer overload of JsMacros.on.

Constructors ​

new EventSendPacket ​

new EventSendPacket(Packet<?> packet)#
Initializes the event with the client core and the supplied outgoing packet, retaining the packet reference without sending or dispatching it. The packet must be non-null. type captures its shortcut name, or its simple class name when no shortcut is registered; this value does not change if packet is later replaced.

Parameters:

  • packet: the non-null outgoing packet to store

Fields ​

packet ​

packet: Packet<?>#
The outgoing packet object. Assigning a replacement changes what is sent; assigning null drops it. Buffer edits do not alter this field unless the decoded packet is assigned here.

type ​

type: Stringread-only#
The convenience name used by PacketByteBufferHelper.getPacketNames() and FiltererSendPacket. Unlisted packet classes use their simple class name; names may vary by game version.

Methods ​

canGetPacketBuffer ​

canGetPacketBuffer(): booleanSince2.0.0#
Checks whether the current packet has a selectable registered phase and standalone codec. This does not guarantee that encoding its contents will succeed; bundles are unsupported.
Returns: whether a standalone packet buffer is supported

getPacketBuffer ​

getPacketBuffer(): PacketByteBufferHelperSince1.8.4#
Encodes the current packet into an independent buffer helper. Read and write operations change only that buffer; to change what is sent, decode the edits and assign the packet to packet. Unsupported packets, including bundles, cause an IllegalArgumentException; canGetPacketBuffer() checks codec availability but does not guarantee encoding succeeds.
Returns: a helper for reading or editing the packet's encoded data.

replacePacket ​

replacePacket(Object... args): voidSince1.8.4#
Constructs a packet of the current packet's class and assigns it to packet. It first tries an exact runtime-argument-type match, then constructors with the same argument count, coercing numeric arguments to parameter types.

Parameters:

  • args: the arguments to pass to the packet's constructor

toString ​

toString(): String#
Returns a diagnostic string containing the event name and the type captured at construction. The format is %s:{"type": "%s"}; it is not JSON, and the type is not escaped.
Returns: a diagnostic string with the event name and captured packet type