What is a PacketEvents Listener
Packet listeners are used to process (or modify) incoming and outgoing information.
Packet Listener
The Packet Listener is a feature provided by PacketEvents to read, modify, cancel and delay packets. All packets in the game invoke the packet listener. Moreover, PacketEvents offers the PacketType registry which allows you to detect what kind of packet is being sent or received. Once you have detected your desired packet, you may utilize our wrappers for reading and/or modification.
Furthermore, if you wish to modify a packet in your listener, simply using setters in your packet wrappers does not suffice. PacketEvents optimizes its performance by only applying changes to the packet, if you explicitly mark the event to be re-encoded.
Mark the event to be re-encoded whenever you apply changes to a packet.
Listener Priorities
You can register as many listeners as you want, hence having some sort of order in PacketEvents is necessary. Just like the Bukkit API, PacketEvents allows you to assign priorities to your listeners. The LOWEST priority is the first to be invoked, while the MONITOR priority is last to be invoked. The listener with the HIGHEST priority has the final say on the state of packets.
Valid priorities can be viewed here.
Please avoid modifying packets in the MONITOR priority:
Only use this priority if you want to perform logic based on the outcome of the event.
If possible, pick the NORMAL priority:
This allows other projects to easily overturn your decisions.
Last updated