public class PacketEvent
extends java.util.EventObject
implements org.bukkit.event.Cancellable
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,
org.bukkit.entity.Player client)
Creates an event representing a client 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.
|
PacketContainer |
getPacket()
Retrieves the packet that will be sent to the player.
|
int |
getPacketID()
Retrieves the packet ID.
|
org.bukkit.entity.Player |
getPlayer()
Retrieves the player that has sent the packet or is recieving it.
|
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 |
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 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 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 fromSynchronous(PacketEvent event, AsyncMarker marker)
event
- - the original synchronous event.marker
- - the asynchronous marker.public PacketContainer getPacket()
public void setPacket(PacketContainer packet)
packet
- - the packet that will be sent instead.public int getPacketID()
public boolean isCancelled()
isCancelled
in interface org.bukkit.event.Cancellable
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()