Class PacketFilterManager
- All Implemented Interfaces:
InternalManager,ListenerInvoker,PacketStream,ProtocolManager
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic ReportTypestatic ReportTypestatic ReportTypestatic ReportTypestatic ReportTypestatic ReportTypestatic ReportTypestatic ReportTypestatic ReportTypestatic ReportTypestatic intThe number of ticks in a second. -
Constructor Summary
ConstructorsConstructorDescriptionPacketFilterManager(PacketFilterBuilder builder)Only create instances of this class if ProtocolLib is disabled. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPacketListener(PacketListener listener)Adds a packet listener.voidbroadcastServerPacket(PacketContainer packet)Broadcast a given packet to every connected player on the server.voidbroadcastServerPacket(PacketContainer packet, org.bukkit.entity.Entity entity, boolean includeTracker)Broadcast a packet to every player that is receiving information about a given entity.voidbroadcastServerPacket(PacketContainer packet, org.bukkit.Location origin, int maxObserverDistance)Broadcast a packet to every player within the given maximum observer distance.voidclose()Called when ProtocolLib is closing.createPacket(PacketType type)Constructs a new encapsulated Minecraft packet with the given ID.createPacket(PacketType type, boolean forceDefaults)Constructs a new encapsulated Minecraft packet with the given ID.createPacketConstructor(PacketType type, Object... arguments)Construct a packet using the special builtin Minecraft constructors.protected voidfinalize()Retrieve the current asynchronous packet manager.Retrieves the current plugin class loader.org.bukkit.entity.EntitygetEntityFromID(org.bukkit.World container, int id)Retrieve the associated entity.List<org.bukkit.entity.Player>getEntityTrackers(org.bukkit.entity.Entity entity)Retrieve every client that is receiving information about a given entity.Retrieve the current Minecraft version.com.google.common.collect.ImmutableSet<PacketListener>Retrieves a list of every registered packet listener.getPacketType(Object packet)Retrieve the associated type of a packet.Retrieves how the server packets are read.intgetProtocolVersion(org.bukkit.entity.Player player)Retrieve the protocol version of a given player.Retrieves a immutable set containing the type of the received client packets that will be observed by listeners.Retrieves a immutable set containing the type of the sent server packets that will be observed by listeners.voidinitializePlayers(List<org.bukkit.entity.Player> players)Initialize the packet injection for every player.voidinvokePacketRecieving(PacketEvent event)Invokes the given packet event for every registered listener.voidinvokePacketSending(PacketEvent event)Invokes the given packet event for every registered listener.booleanisClosed()Determines whether or not this protocol manager has been disabled.booleanisDebug()Determine if debug mode is enabled.booleanisLoginPacket(PacketType type)Determine if a given packet may be sent during login.static PacketFilterBuilderConstruct a new packet filter builder.voidrecieveClientPacket(org.bukkit.entity.Player sender, PacketContainer packet)Simulate recieving a certain packet from a given player.voidrecieveClientPacket(org.bukkit.entity.Player sender, PacketContainer packet, boolean filters)Simulate receiving a certain packet from a given player.voidrecieveClientPacket(org.bukkit.entity.Player sender, PacketContainer packet, NetworkMarker marker, boolean filters)Simulate recieving a certain packet from a given player.voidregisterEvents(org.bukkit.plugin.PluginManager manager, org.bukkit.plugin.Plugin plugin)Register this protocol manager on Bukkit.voidremovePacketListener(PacketListener listener)Removes a given packet listener.voidremovePacketListeners(org.bukkit.plugin.Plugin plugin)Removes every listener associated with the given plugin.voidsendServerPacket(org.bukkit.entity.Player reciever, PacketContainer packet)Send a packet to the given player.voidsendServerPacket(org.bukkit.entity.Player reciever, PacketContainer packet, boolean filters)Send a packet to the given player.voidsendServerPacket(org.bukkit.entity.Player receiver, PacketContainer packet, NetworkMarker marker, boolean filters)Send a packet to the given player.voidsendWirePacket(org.bukkit.entity.Player receiver, int id, byte[] bytes)Send a wire packet to the given player.voidsendWirePacket(org.bukkit.entity.Player receiver, WirePacket packet)Send a wire packet to the given player.voidsetDebug(boolean debug)Set whether or not debug mode is enabled.voidsetPlayerHook(PlayerInjectHooks playerHook)Sets how the server packets are read.voiduninitializePlayers(List<org.bukkit.entity.Player> players)Uninitialize the packet injection of every player.voidupdateEntity(org.bukkit.entity.Entity entity, List<org.bukkit.entity.Player> observers)Completely resend an entity to a list of clients.voidverifyWhitelist(PacketListener listener, ListeningWhitelist whitelist)Determine if the packet IDs in a whitelist is valid.
-
Field Details
-
REPORT_CANNOT_LOAD_PACKET_LIST
-
REPORT_CANNOT_INITIALIZE_PACKET_INJECTOR
-
REPORT_PLUGIN_DEPEND_MISSING
-
REPORT_UNSUPPORTED_SERVER_PACKET
-
REPORT_UNSUPPORTED_CLIENT_PACKET
-
REPORT_CANNOT_UNINJECT_PLAYER
-
REPORT_CANNOT_UNINJECT_OFFLINE_PLAYER
-
REPORT_CANNOT_INJECT_PLAYER
-
REPORT_CANNOT_UNREGISTER_PLUGIN
-
REPORT_PLUGIN_VERIFIER_ERROR
-
TICKS_PER_SECOND
public static final int TICKS_PER_SECONDThe number of ticks in a second.- See Also:
- Constant Field Values
-
-
Constructor Details
-
PacketFilterManager
Only create instances of this class if ProtocolLib is disabled.- Parameters:
builder- - PacketFilterBuilder
-
-
Method Details
-
newBuilder
Construct a new packet filter builder.- Returns:
- New builder.
-
getProtocolVersion
public int getProtocolVersion(org.bukkit.entity.Player player)Description copied from interface:ProtocolManagerRetrieve the protocol version of a given player.This only really makes sense of a server that support clients of multiple Minecraft versions, such as Spigot #1628.
- Specified by:
getProtocolVersionin interfaceProtocolManager- Parameters:
player- - the player.- Returns:
- The associated protocol version, or
Integer.MIN_VALUEif unknown.
-
getMinecraftVersion
Description copied from interface:ProtocolManagerRetrieve the current Minecraft version.- Specified by:
getMinecraftVersionin interfaceProtocolManager- Returns:
- The current version.
-
getAsynchronousManager
Description copied from interface:ProtocolManagerRetrieve the current asynchronous packet manager.- Specified by:
getAsynchronousManagerin interfaceProtocolManager- Returns:
- Asynchronous packet manager.
-
isDebug
public boolean isDebug()Description copied from interface:InternalManagerDetermine if debug mode is enabled.- Specified by:
isDebugin interfaceInternalManager- Returns:
- TRUE if it is, FALSE otherwise.
-
setDebug
public void setDebug(boolean debug)Description copied from interface:InternalManagerSet whether or not debug mode is enabled.- Specified by:
setDebugin interfaceInternalManager- Parameters:
debug- - TRUE if it is, FALSE otherwise.
-
getPlayerHook
Retrieves how the server packets are read.- Specified by:
getPlayerHookin interfaceInternalManager- Returns:
- Injection method for reading server packets.
-
setPlayerHook
Sets how the server packets are read.- Specified by:
setPlayerHookin interfaceInternalManager- Parameters:
playerHook- - the new injection method for reading server packets.
-
getPacketListeners
Description copied from interface:ProtocolManagerRetrieves a list of every registered packet listener.- Specified by:
getPacketListenersin interfaceProtocolManager- Returns:
- Every registered packet listener.
-
addPacketListener
Description copied from interface:ProtocolManagerAdds a packet listener.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.
- Specified by:
addPacketListenerin interfaceProtocolManager- Parameters:
listener- - new packet listener.
-
isLoginPacket
Determine if a given packet may be sent during login.- Parameters:
type- - the packet type.- Returns:
- TRUE if it may, FALSE otherwise.
-
verifyWhitelist
Determine if the packet IDs in a whitelist is valid.- Specified by:
verifyWhitelistin interfaceProtocolManager- Parameters:
listener- - the listener that will be mentioned in the error.whitelist- - whitelist of packet IDs.- Throws:
IllegalArgumentException- If the whitelist is illegal.
-
removePacketListener
Description copied from interface:ProtocolManagerRemoves a given packet listener.Attempting to remove a listener that doesn't exist has no effect.
- Specified by:
removePacketListenerin interfaceProtocolManager- Parameters:
listener- - the packet listener to remove.
-
removePacketListeners
public void removePacketListeners(org.bukkit.plugin.Plugin plugin)Description copied from interface:ProtocolManagerRemoves every listener associated with the given plugin.- Specified by:
removePacketListenersin interfaceProtocolManager- Parameters:
plugin- - the plugin to unload.
-
invokePacketRecieving
Description copied from interface:ListenerInvokerInvokes the given packet event for every registered listener.- Specified by:
invokePacketRecievingin interfaceListenerInvoker- Parameters:
event- - the packet event to invoke.
-
invokePacketSending
Description copied from interface:ListenerInvokerInvokes the given packet event for every registered listener.- Specified by:
invokePacketSendingin interfaceListenerInvoker- Parameters:
event- - the packet event to invoke.
-
broadcastServerPacket
Description copied from interface:ProtocolManagerBroadcast a given packet to every connected player on the server.- Specified by:
broadcastServerPacketin interfaceProtocolManager- Parameters:
packet- - the packet to broadcast.
-
broadcastServerPacket
public void broadcastServerPacket(PacketContainer packet, org.bukkit.entity.Entity entity, boolean includeTracker)Description copied from interface:ProtocolManagerBroadcast a packet to every player that is receiving information about a given entity.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.
- Specified by:
broadcastServerPacketin interfaceProtocolManager- Parameters:
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.
-
broadcastServerPacket
public void broadcastServerPacket(PacketContainer packet, org.bukkit.Location origin, int maxObserverDistance)Description copied from interface:ProtocolManagerBroadcast a packet to every player within the given maximum observer distance.- Specified by:
broadcastServerPacketin interfaceProtocolManager- Parameters:
packet- - the packet to broadcast.origin- - the origin to consider when calculating the distance to each observer.maxObserverDistance- - the maximum distance to the origin.
-
sendServerPacket
public void sendServerPacket(org.bukkit.entity.Player reciever, PacketContainer packet) throws InvocationTargetExceptionDescription copied from interface:PacketStreamSend a packet to the given player.- Specified by:
sendServerPacketin interfacePacketStream- Parameters:
reciever- - the reciever.packet- - packet to send.- Throws:
InvocationTargetException- - if an error occured when sending the packet.
-
sendServerPacket
public void sendServerPacket(org.bukkit.entity.Player reciever, PacketContainer packet, boolean filters) throws InvocationTargetExceptionDescription copied from interface:ProtocolManagerSend a packet to the given player.Re-sending a previously cancelled packet is discouraged. Use
AsyncMarker.incrementProcessingDelay()to delay a packet until a certain condition has been met.- Specified by:
sendServerPacketin interfacePacketStream- Specified by:
sendServerPacketin interfaceProtocolManager- Parameters:
reciever- - the receiver.packet- - packet to send.filters- - whether or not to invoke any packet filters belowListenerPriority.MONITOR.- Throws:
InvocationTargetException- - if an error occurred when sending the packet.
-
sendServerPacket
public void sendServerPacket(org.bukkit.entity.Player receiver, PacketContainer packet, NetworkMarker marker, boolean filters) throws InvocationTargetExceptionDescription copied from interface:PacketStreamSend a packet to the given player.- Specified by:
sendServerPacketin interfacePacketStream- Parameters:
receiver- - the receiver.packet- - packet to send.marker- - the network marker to use.filters- - whether or not to invoke any packet filters belowListenerPriority.MONITOR.- Throws:
InvocationTargetException- - if an error occured when sending the packet.
-
sendWirePacket
public void sendWirePacket(org.bukkit.entity.Player receiver, int id, byte[] bytes) throws InvocationTargetExceptionDescription copied from interface:PacketStreamSend a wire packet to the given player.- Specified by:
sendWirePacketin interfacePacketStream- Parameters:
receiver- - the receiver.id- - packet id.bytes- - packet bytes.- Throws:
InvocationTargetException- if an error occured when sending the packet.
-
sendWirePacket
public void sendWirePacket(org.bukkit.entity.Player receiver, WirePacket packet) throws InvocationTargetExceptionDescription copied from interface:PacketStreamSend a wire packet to the given player.- Specified by:
sendWirePacketin interfacePacketStream- Parameters:
receiver- - the receiver.packet- - packet to send.- Throws:
InvocationTargetException- if an error occured when sending the packet.
-
recieveClientPacket
public void recieveClientPacket(org.bukkit.entity.Player sender, PacketContainer packet) throws IllegalAccessException, InvocationTargetExceptionDescription copied from interface:PacketStreamSimulate recieving a certain packet from a given player.- Specified by:
recieveClientPacketin interfacePacketStream- Parameters:
sender- - the sender.packet- - the packet that was sent.- Throws:
IllegalAccessException- If the underlying method caused an error.InvocationTargetException- If the reflection machinery failed.
-
recieveClientPacket
public void recieveClientPacket(org.bukkit.entity.Player sender, PacketContainer packet, boolean filters) throws IllegalAccessException, InvocationTargetExceptionDescription copied from interface:ProtocolManagerSimulate receiving a certain packet from a given player.Receiving a previously cancelled packet is discouraged. Use
AsyncMarker.incrementProcessingDelay()to delay a packet until a certain condition has been met.- Specified by:
recieveClientPacketin interfacePacketStream- Specified by:
recieveClientPacketin interfaceProtocolManager- Parameters:
sender- - the sender.packet- - the packet that was sent.filters- - whether or not to invoke any packet filters belowListenerPriority.MONITOR.- Throws:
IllegalAccessException- If the underlying method caused an error.InvocationTargetException- If the reflection machinery failed.
-
recieveClientPacket
public void recieveClientPacket(org.bukkit.entity.Player sender, PacketContainer packet, NetworkMarker marker, boolean filters) throws IllegalAccessException, InvocationTargetExceptionDescription copied from interface:PacketStreamSimulate recieving a certain packet from a given player.- Specified by:
recieveClientPacketin interfacePacketStream- Parameters:
sender- - the sender.packet- - the packet that was sent.marker- - the network marker to use.filters- - whether or not to invoke any packet filters belowListenerPriority.MONITOR.- Throws:
IllegalAccessException- If the underlying method caused an error.InvocationTargetException- If the reflection machinery failed.
-
createPacket
Description copied from interface:ProtocolManagerConstructs a new encapsulated Minecraft packet with the given ID.- Specified by:
createPacketin interfaceProtocolManager- Parameters:
type- - packet type.- Returns:
- New encapsulated Minecraft packet.
-
createPacket
Description copied from interface:ProtocolManagerConstructs a new encapsulated Minecraft packet with the given ID.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.
- Specified by:
createPacketin interfaceProtocolManager- Parameters:
type- - packet type.forceDefaults- - TRUE to use sensible defaults in most fields, FALSE otherwise.- Returns:
- New encapsulated Minecraft packet.
-
createPacketConstructor
Description copied from interface:ProtocolManagerConstruct a packet using the special builtin Minecraft constructors.- Specified by:
createPacketConstructorin interfaceProtocolManager- Parameters:
type- - the packet type.arguments- - arguments that will be passed to the constructor.- Returns:
- The packet constructor.
-
getSendingFilterTypes
Description copied from interface:ProtocolManagerRetrieves a immutable set containing the type of the sent server packets that will be observed by listeners.- Specified by:
getSendingFilterTypesin interfaceProtocolManager- Returns:
- Every filtered server packet.
-
getReceivingFilterTypes
Description copied from interface:ProtocolManagerRetrieves a immutable set containing the type of the received client packets that will be observed by listeners.- Specified by:
getReceivingFilterTypesin interfaceProtocolManager- Returns:
- Every filtered client packet.
-
updateEntity
public void updateEntity(org.bukkit.entity.Entity entity, List<org.bukkit.entity.Player> observers) throws FieldAccessExceptionDescription copied from interface:ProtocolManagerCompletely resend an entity to a list of clients.Note that this method is NOT thread safe. If you call this method from anything but the main thread, it will throw an exception.
- Specified by:
updateEntityin interfaceProtocolManager- Parameters:
entity- - entity to refresh.observers- - the clients to update.- Throws:
FieldAccessException
-
getEntityFromID
public org.bukkit.entity.Entity getEntityFromID(org.bukkit.World container, int id) throws FieldAccessExceptionDescription copied from interface:ProtocolManagerRetrieve the associated entity.- Specified by:
getEntityFromIDin interfaceProtocolManager- Parameters:
container- - the world the entity belongs to.id- - the unique ID of the entity.- Returns:
- The associated entity.
- Throws:
FieldAccessException- Reflection failed.
-
getEntityTrackers
public List<org.bukkit.entity.Player> getEntityTrackers(org.bukkit.entity.Entity entity) throws FieldAccessExceptionDescription copied from interface:ProtocolManagerRetrieve every client that is receiving information about a given entity.- Specified by:
getEntityTrackersin interfaceProtocolManager- Parameters:
entity- - the entity that is being tracked.- Returns:
- Every client/player that is tracking the given entity.
- Throws:
FieldAccessException- If reflection failed.
-
initializePlayers
Initialize the packet injection for every player.- Parameters:
players- - list of players to inject.
-
uninitializePlayers
Uninitialize the packet injection of every player.- Parameters:
players- - list of players to uninject.
-
registerEvents
public void registerEvents(org.bukkit.plugin.PluginManager manager, org.bukkit.plugin.Plugin plugin)Register this protocol manager on Bukkit.- Specified by:
registerEventsin interfaceInternalManager- Parameters:
manager- - Bukkit plugin manager that provides player join/leave events.plugin- - the parent plugin.
-
getPacketType
Description copied from interface:ListenerInvokerRetrieve the associated type of a packet.- Specified by:
getPacketTypein interfaceListenerInvoker- Parameters:
packet- - the packet.- Returns:
- The packet type.
-
getClassLoader
Retrieves the current plugin class loader.- Returns:
- Class loader.
-
isClosed
public boolean isClosed()Description copied from interface:ProtocolManagerDetermines whether or not this protocol manager has been disabled.- Specified by:
isClosedin interfaceProtocolManager- Returns:
- TRUE if it has, FALSE otherwise.
-
close
public void close()Description copied from interface:InternalManagerCalled when ProtocolLib is closing.- Specified by:
closein interfaceInternalManager
-
finalize
-