public class DelayedPacketManager extends java.lang.Object implements ProtocolManager, InternalManager
Modifier and Type | Field and Description |
---|---|
static ReportType |
REPORT_CANNOT_REGISTER_QUEUED_LISTENER |
static ReportType |
REPORT_CANNOT_SEND_QUEUED_PACKET |
Constructor and Description |
---|
DelayedPacketManager(ErrorReporter reporter,
MinecraftVersion version) |
Modifier and Type | Method and Description |
---|---|
void |
addPacketListener(PacketListener listener)
Adds a packet listener.
|
void |
broadcastServerPacket(PacketContainer packet)
Broadcast a given packet to every connected player on the server.
|
void |
broadcastServerPacket(PacketContainer packet,
org.bukkit.entity.Entity entity,
boolean includeTracker)
Broadcast a packet to every player that is receiving information about a given entity.
|
void |
broadcastServerPacket(PacketContainer packet,
org.bukkit.Location origin,
int maxObserverDistance)
Broadcast a packet to every player within the given maximum observer distance.
|
void |
close()
Called when ProtocolLib is closing.
|
PacketContainer |
createPacket(int id)
Deprecated.
|
PacketContainer |
createPacket(int id,
boolean forceDefaults)
Deprecated.
|
PacketContainer |
createPacket(PacketType type)
Constructs a new encapsulated Minecraft packet with the given ID.
|
PacketContainer |
createPacket(PacketType type,
boolean forceDefaults)
Constructs a new encapsulated Minecraft packet with the given ID.
|
PacketConstructor |
createPacketConstructor(int id,
java.lang.Object... arguments)
Construct a packet using the special builtin Minecraft constructors.
|
PacketConstructor |
createPacketConstructor(PacketType type,
java.lang.Object... arguments)
Construct a packet using the special builtin Minecraft constructors.
|
AsynchronousManager |
getAsynchronousManager()
Retrieve the current asynchronous packet manager.
|
InternalManager |
getDelegate()
Retrieve the underlying protocol manager.
|
org.bukkit.entity.Entity |
getEntityFromID(org.bukkit.World container,
int id)
Retrieve the associated entity.
|
java.util.List<org.bukkit.entity.Player> |
getEntityTrackers(org.bukkit.entity.Entity entity)
Retrieve every client that is receiving information about a given entity.
|
MinecraftVersion |
getMinecraftVersion()
Retrieve the current Minecraft version.
|
com.google.common.collect.ImmutableSet<PacketListener> |
getPacketListeners()
Retrieves a list of every registered packet listener.
|
PacketFilterManager.PlayerInjectHooks |
getPlayerHook()
Retrieves how the server packets are read.
|
java.util.Set<java.lang.Integer> |
getReceivingFilters()
Deprecated.
|
java.util.Set<PacketType> |
getReceivingFilterTypes()
Retrieves a immutable set containing the type of the received client packets that will be observed by listeners.
|
java.util.Set<java.lang.Integer> |
getSendingFilters()
Deprecated.
|
java.util.Set<PacketType> |
getSendingFilterTypes()
Retrieves a immutable set containing the type of the sent server packets that will be observed by listeners.
|
boolean |
isClosed()
Determines whether or not this protocol manager has been disabled.
|
boolean |
isDebug()
Determine if debug mode is enabled.
|
void |
recieveClientPacket(org.bukkit.entity.Player sender,
PacketContainer packet)
Simulate recieving a certain packet from a given player.
|
void |
recieveClientPacket(org.bukkit.entity.Player sender,
PacketContainer packet,
boolean filters)
Simulate receiving a certain packet from a given player.
|
void |
recieveClientPacket(org.bukkit.entity.Player sender,
PacketContainer packet,
NetworkMarker marker,
boolean filters)
Simulate recieving a certain packet from a given player.
|
void |
registerEvents(org.bukkit.plugin.PluginManager manager,
org.bukkit.plugin.Plugin plugin)
Register this protocol manager on Bukkit.
|
void |
removePacketListener(PacketListener listener)
Removes a given packet listener.
|
void |
removePacketListeners(org.bukkit.plugin.Plugin plugin)
Removes every listener associated with the given plugin.
|
void |
sendServerPacket(org.bukkit.entity.Player receiver,
PacketContainer packet)
Send a packet to the given player.
|
void |
sendServerPacket(org.bukkit.entity.Player receiver,
PacketContainer packet,
boolean filters)
Send a packet to the given player.
|
void |
sendServerPacket(org.bukkit.entity.Player receiver,
PacketContainer packet,
NetworkMarker marker,
boolean filters)
Send a packet to the given player.
|
void |
setAsynchronousManager(AsynchronousManager asyncManager)
Update the asynchronous manager.
|
void |
setDebug(boolean debug)
Set whether or not debug mode is enabled.
|
protected void |
setDelegate(InternalManager delegate)
Update the delegate to the underlying manager.
|
void |
setPlayerHook(PacketFilterManager.PlayerInjectHooks playerHook)
Sets how the server packets are read.
|
void |
updateEntity(org.bukkit.entity.Entity entity,
java.util.List<org.bukkit.entity.Player> observers)
Completely resend an entity to a list of clients.
|
public static final ReportType REPORT_CANNOT_SEND_QUEUED_PACKET
public static final ReportType REPORT_CANNOT_REGISTER_QUEUED_LISTENER
public DelayedPacketManager(@Nonnull ErrorReporter reporter, @Nonnull MinecraftVersion version)
public InternalManager getDelegate()
public MinecraftVersion getMinecraftVersion()
ProtocolManager
getMinecraftVersion
in interface ProtocolManager
protected void setDelegate(InternalManager delegate)
This will prompt this packet manager to immediately transmit and register all queued packets an listeners.
delegate
- - delegate to the new manager.public void setPlayerHook(PacketFilterManager.PlayerInjectHooks playerHook)
InternalManager
setPlayerHook
in interface InternalManager
playerHook
- - the new injection method for reading server packets.public PacketFilterManager.PlayerInjectHooks getPlayerHook()
InternalManager
getPlayerHook
in interface InternalManager
public void sendServerPacket(org.bukkit.entity.Player receiver, PacketContainer packet) throws java.lang.reflect.InvocationTargetException
PacketStream
sendServerPacket
in interface PacketStream
receiver
- - the reciever.packet
- - packet to send.java.lang.reflect.InvocationTargetException
- - if an error occured when sending the packet.public void sendServerPacket(org.bukkit.entity.Player receiver, PacketContainer packet, boolean filters) throws java.lang.reflect.InvocationTargetException
ProtocolManager
Re-sending a previously cancelled packet is discouraged. Use AsyncMarker.incrementProcessingDelay()
to delay a packet until a certain condition has been met.
sendServerPacket
in interface PacketStream
sendServerPacket
in interface ProtocolManager
receiver
- - the receiver.packet
- - packet to send.filters
- - whether or not to invoke any packet filters below ListenerPriority.MONITOR
.java.lang.reflect.InvocationTargetException
- - if an error occurred when sending the packet.public void sendServerPacket(org.bukkit.entity.Player receiver, PacketContainer packet, NetworkMarker marker, boolean filters) throws java.lang.reflect.InvocationTargetException
PacketStream
sendServerPacket
in interface PacketStream
receiver
- - the receiver.packet
- - packet to send.marker
- - the network marker to use.filters
- - whether or not to invoke any packet filters below ListenerPriority.MONITOR
.java.lang.reflect.InvocationTargetException
- - if an error occured when sending the packet.public void recieveClientPacket(org.bukkit.entity.Player sender, PacketContainer packet) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
PacketStream
recieveClientPacket
in interface PacketStream
sender
- - the sender.packet
- - the packet that was sent.java.lang.IllegalAccessException
- If the underlying method caused an error.java.lang.reflect.InvocationTargetException
- If the reflection machinery failed.public void recieveClientPacket(org.bukkit.entity.Player sender, PacketContainer packet, boolean filters) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
ProtocolManager
Receiving a previously cancelled packet is discouraged. Use AsyncMarker.incrementProcessingDelay()
to delay a packet until a certain condition has been met.
recieveClientPacket
in interface PacketStream
recieveClientPacket
in interface ProtocolManager
sender
- - the sender.packet
- - the packet that was sent.filters
- - whether or not to invoke any packet filters below ListenerPriority.MONITOR
.java.lang.IllegalAccessException
- If the underlying method caused an error.java.lang.reflect.InvocationTargetException
- If the reflection machinery failed.public void recieveClientPacket(org.bukkit.entity.Player sender, PacketContainer packet, NetworkMarker marker, boolean filters) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
PacketStream
recieveClientPacket
in interface PacketStream
sender
- - the sender.packet
- - the packet that was sent.marker
- - the network marker to use.filters
- - whether or not to invoke any packet filters below ListenerPriority.MONITOR
.java.lang.IllegalAccessException
- If the underlying method caused an error.java.lang.reflect.InvocationTargetException
- If the reflection machinery failed.public void broadcastServerPacket(PacketContainer packet, org.bukkit.entity.Entity entity, boolean includeTracker)
ProtocolManager
This is usually every player in the same world within an observable distance. If the entity is a player, it will only be included if includeTracker is TRUE.
broadcastServerPacket
in interface ProtocolManager
packet
- - the packet to broadcast.entity
- - the entity whose trackers we will inform.includeTracker
- - whether or not to also transmit the packet to the entity, if it is a tracker.public void broadcastServerPacket(PacketContainer packet, org.bukkit.Location origin, int maxObserverDistance)
ProtocolManager
broadcastServerPacket
in interface ProtocolManager
packet
- - the packet to broadcast.origin
- - the origin to consider when calculating the distance to each observer.maxObserverDistance
- - the maximum distance to the origin.public void broadcastServerPacket(PacketContainer packet)
ProtocolManager
broadcastServerPacket
in interface ProtocolManager
packet
- - the packet to broadcast.public com.google.common.collect.ImmutableSet<PacketListener> getPacketListeners()
ProtocolManager
getPacketListeners
in interface ProtocolManager
public void addPacketListener(PacketListener listener)
ProtocolManager
Adding an already registered listener has no effect. If you need to change the packets the current listener is observing, you must first remove the packet listener before you can register it again.
addPacketListener
in interface ProtocolManager
listener
- - new packet listener.public void removePacketListener(PacketListener listener)
ProtocolManager
Attempting to remove a listener that doesn't exist has no effect.
removePacketListener
in interface ProtocolManager
listener
- - the packet listener to remove.public void removePacketListeners(org.bukkit.plugin.Plugin plugin)
ProtocolManager
removePacketListeners
in interface ProtocolManager
plugin
- - the plugin to unload.@Deprecated public PacketContainer createPacket(int id)
ProtocolManager
Deprecated: Use ProtocolManager.createPacket(PacketType)
instead.
createPacket
in interface ProtocolManager
id
- - packet ID.@Deprecated public PacketContainer createPacket(int id, boolean forceDefaults)
ProtocolManager
If set to true, the forceDefaults option will force the system to automatically give non-primitive fields in the packet sensible default values. For instance, certain packets - like Packet60Explosion - require a List or Set to be non-null. If the forceDefaults option is true, the List or Set will be automatically created.
Deprecated: Use ProtocolManager.createPacket(PacketType, boolean)
instead.
createPacket
in interface ProtocolManager
id
- - packet ID.forceDefaults
- - TRUE to use sensible defaults in most fields, FALSE otherwise.public PacketConstructor createPacketConstructor(int id, java.lang.Object... arguments)
ProtocolManager
Deprecated: Use ProtocolManager.createPacketConstructor(PacketType, Object...)
instead.
createPacketConstructor
in interface ProtocolManager
id
- - the packet ID.arguments
- - arguments that will be passed to the constructor.public PacketConstructor createPacketConstructor(PacketType type, java.lang.Object... arguments)
ProtocolManager
createPacketConstructor
in interface ProtocolManager
arguments
- - arguments that will be passed to the constructor.@Deprecated public java.util.Set<java.lang.Integer> getSendingFilters()
ProtocolManager
Deprecated: Use ProtocolManager.getSendingFilterTypes()
instead.
getSendingFilters
in interface ProtocolManager
@Deprecated public java.util.Set<java.lang.Integer> getReceivingFilters()
ProtocolManager
Deprecated: Use ProtocolManager.getReceivingFilterTypes()
instead.
getReceivingFilters
in interface ProtocolManager
public PacketContainer createPacket(PacketType type)
ProtocolManager
createPacket
in interface ProtocolManager
type
- - packet type.public PacketContainer createPacket(PacketType type, boolean forceDefaults)
ProtocolManager
If set to true, the forceDefaults option will force the system to automatically give non-primitive fields in the packet sensible default values. For instance, certain packets - like Packet60Explosion - require a List or Set to be non-null. If the forceDefaults option is true, the List or Set will be automatically created.
createPacket
in interface ProtocolManager
type
- - packet type.forceDefaults
- - TRUE to use sensible defaults in most fields, FALSE otherwise.public java.util.Set<PacketType> getSendingFilterTypes()
ProtocolManager
getSendingFilterTypes
in interface ProtocolManager
public java.util.Set<PacketType> getReceivingFilterTypes()
ProtocolManager
getReceivingFilterTypes
in interface ProtocolManager
public void updateEntity(org.bukkit.entity.Entity entity, java.util.List<org.bukkit.entity.Player> observers) throws FieldAccessException
ProtocolManager
Note that this method is NOT thread safe. If you call this method from anything but the main thread, it will throw an exception.
updateEntity
in interface ProtocolManager
entity
- - entity to refresh.observers
- - the clients to update.FieldAccessException
public org.bukkit.entity.Entity getEntityFromID(org.bukkit.World container, int id) throws FieldAccessException
ProtocolManager
getEntityFromID
in interface ProtocolManager
container
- - the world the entity belongs to.id
- - the unique ID of the entity.FieldAccessException
- Reflection failed.public java.util.List<org.bukkit.entity.Player> getEntityTrackers(org.bukkit.entity.Entity entity) throws FieldAccessException
ProtocolManager
getEntityTrackers
in interface ProtocolManager
entity
- - the entity that is being tracked.FieldAccessException
- If reflection failed.public boolean isClosed()
ProtocolManager
isClosed
in interface ProtocolManager
public AsynchronousManager getAsynchronousManager()
ProtocolManager
getAsynchronousManager
in interface ProtocolManager
public boolean isDebug()
InternalManager
isDebug
in interface InternalManager
public void setDebug(boolean debug)
InternalManager
setDebug
in interface InternalManager
debug
- - TRUE if it is, FALSE otherwise.public void setAsynchronousManager(AsynchronousManager asyncManager)
asyncManager
- - the asynchronous manager.public void registerEvents(org.bukkit.plugin.PluginManager manager, org.bukkit.plugin.Plugin plugin)
InternalManager
registerEvents
in interface InternalManager
manager
- - Bukkit plugin manager that provides player join/leave events.plugin
- - the parent plugin.public void close()
InternalManager
close
in interface InternalManager