public class PacketEvent
extends java.util.EventObject
implements org.bukkit.event.Cancellable
Modifier and Type | Field and Description |
---|---|
static ReportType |
REPORT_CHANGING_PACKET_TYPE_IS_CONFUSING |
Constructor and Description |
---|
PacketEvent(java.lang.Object source)
Use the static constructors to create instances of this event.
|
Modifier and Type | Method and Description |
---|---|
static PacketEvent |
fromClient(java.lang.Object source,
PacketContainer packet,
NetworkMarker marker,
org.bukkit.entity.Player client)
Creates an event representing a client packet transmission.
|
static PacketEvent |
fromClient(java.lang.Object source,
PacketContainer packet,
org.bukkit.entity.Player client)
Creates an event representing a client packet transmission.
|
static PacketEvent |
fromServer(java.lang.Object source,
PacketContainer packet,
NetworkMarker marker,
org.bukkit.entity.Player recipient)
Creates an event representing a server packet transmission.
|
static PacketEvent |
fromServer(java.lang.Object source,
PacketContainer packet,
org.bukkit.entity.Player recipient)
Creates an event representing a server packet transmission.
|
static PacketEvent |
fromSynchronous(PacketEvent event,
AsyncMarker marker)
Create an asynchronous packet event from a synchronous event and a async marker.
|
AsyncMarker |
getAsyncMarker()
Retrieve the asynchronous marker.
|
NetworkMarker |
getNetworkMarker()
Retrieve the object responsible for managing the serialized input and output of a packet.
|
PacketContainer |
getPacket()
Retrieves the packet that will be sent to the player.
|
int |
getPacketID()
Deprecated.
|
PacketType |
getPacketType()
Retrieve the packet type.
|
org.bukkit.entity.Player |
getPlayer()
Retrieves the player that has sent the packet or is recieving it.
|
boolean |
isAsync()
Determine if we are executing the packet event in an asynchronous thread.
|
boolean |
isAsynchronous()
Determine if the packet event has been executed asynchronously or not.
|
boolean |
isCancelled()
Retrieves whether or not the packet should be cancelled.
|
boolean |
isReadOnly()
Determine if the current packet event is read only.
|
boolean |
isServerPacket()
Whether or not this packet was created by the server.
|
void |
setAsyncMarker(AsyncMarker asyncMarker)
Set the asynchronous marker.
|
void |
setCancelled(boolean cancel)
Sets whether or not the packet should be cancelled.
|
void |
setNetworkMarker(NetworkMarker networkMarker)
Update the network manager.
|
void |
setPacket(PacketContainer packet)
Replace the packet that will be sent to the player.
|
void |
setReadOnly(boolean readOnly)
Set the read-only state of this packet event.
|
public static final ReportType REPORT_CHANGING_PACKET_TYPE_IS_CONFUSING
public PacketEvent(java.lang.Object source)
source
- - the event source.public static PacketEvent fromClient(java.lang.Object source, PacketContainer packet, org.bukkit.entity.Player client)
source
- - the event source.packet
- - the packet.client
- - the client that sent the packet.public static PacketEvent fromClient(java.lang.Object source, PacketContainer packet, NetworkMarker marker, org.bukkit.entity.Player client)
source
- - the event source.packet
- - the packet.marker
- - the network marker.client
- - the client that sent the packet.public static PacketEvent fromServer(java.lang.Object source, PacketContainer packet, org.bukkit.entity.Player recipient)
source
- - the event source.packet
- - the packet.recipient
- - the client that will receieve the packet.public static PacketEvent fromServer(java.lang.Object source, PacketContainer packet, NetworkMarker marker, org.bukkit.entity.Player recipient)
source
- - the event source.packet
- - the packet.marker
- - the network marker.recipient
- - the client that will receieve the packet.public static PacketEvent fromSynchronous(PacketEvent event, AsyncMarker marker)
event
- - the original synchronous event.marker
- - the asynchronous marker.public boolean isAsync()
If so, you must synchronize all calls to the Bukkit API.
Generally, most server packets are executed on the main thread, whereas client packets are all executed asynchronously.
public PacketContainer getPacket()
public void setPacket(PacketContainer packet)
packet
- - the packet that will be sent instead.@Deprecated public int getPacketID()
Deprecated: Use getPacketType()
instead.
public PacketType getPacketType()
public boolean isCancelled()
isCancelled
in interface org.bukkit.event.Cancellable
public NetworkMarker getNetworkMarker()
Note that the serialized input data is only available for client-side packets, and the output handlers can only be applied to server-side packets.
public void setNetworkMarker(NetworkMarker networkMarker)
This method is internal - do not call.
networkMarker
- - the new network manager.public void setCancelled(boolean cancel)
Warning: A cancelled packet should never be re-transmitted. Use the asynchronous packet manager if you need to perform extensive processing. It should also be used if you need to synchronize with the main thread.
This ensures that other plugins can work with the same packet.
An asynchronous listener can also delay a packet indefinitely without having to block its thread.
setCancelled
in interface org.bukkit.event.Cancellable
cancel
- - TRUE if it should be cancelled, FALSE otherwise.public org.bukkit.entity.Player getPlayer()
public boolean isServerPacket()
Most listeners can deduce this by noting which listener method was invoked.
public AsyncMarker getAsyncMarker()
If the packet is synchronous, this marker will be used to schedule an asynchronous event. In the following asynchronous event, the marker is used to correctly pass the packet around to the different threads.
Note that if there are no asynchronous events that can receive this packet, the marker is NULL.
public void setAsyncMarker(AsyncMarker asyncMarker)
If the marker is non-null at the end of an synchronous event processing, the packet will be scheduled to be processed asynchronously with the given settings.
Note that if there are no asynchronous events that can receive this packet, the marker should be NULL.
asyncMarker
- - the new asynchronous marker, or NULL.java.lang.IllegalStateException
- If the current event is asynchronous.public boolean isReadOnly()
This is used to ensure that a monitor listener doesn't accidentally alter the state of the event. However, it is still possible to modify the packet itself, as it would require too many resources to verify its integrity.
Thus, the packet is considered immutable if the packet event is read only.
public void setReadOnly(boolean readOnly)
This will be reset for every packet listener.
readOnly
- - TRUE if it is read-only, FALSE otherwise.public boolean isAsynchronous()