public final class PacketFilterManager extends java.lang.Object implements ProtocolManager, ListenerInvoker, InternalManager
Modifier and Type | Class and Description |
---|---|
static class |
PacketFilterManager.PlayerInjectHooks
Sets the inject hook type.
|
Modifier and Type | Field and Description |
---|---|
static ReportType |
REPORT_CANNOT_INITIALIZE_PACKET_INJECTOR |
static ReportType |
REPORT_CANNOT_INJECT_PLAYER |
static ReportType |
REPORT_CANNOT_LOAD_PACKET_LIST |
static ReportType |
REPORT_CANNOT_UNINJECT_OFFLINE_PLAYER |
static ReportType |
REPORT_CANNOT_UNINJECT_PLAYER |
static ReportType |
REPORT_CANNOT_UNREGISTER_PLUGIN |
static ReportType |
REPORT_PLUGIN_DEPEND_MISSING |
static ReportType |
REPORT_PLUGIN_VERIFIER_ERROR |
static ReportType |
REPORT_UNSUPPORTED_CLIENT_PACKET_ID |
static ReportType |
REPORT_UNSUPPORTED_SERVER_PACKET_ID |
static int |
TICKS_PER_SECOND
The number of ticks in a second.
|
Constructor and Description |
---|
PacketFilterManager(PacketFilterBuilder builder)
Only create instances of this class if protocol lib is disabled.
|
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)
Deprecated.
|
PacketConstructor |
createPacketConstructor(PacketType type,
java.lang.Object... arguments)
Construct a packet using the special builtin Minecraft constructors.
|
protected void |
finalize() |
AsynchronousManager |
getAsynchronousManager()
Retrieve the current asynchronous packet manager.
|
java.lang.ClassLoader |
getClassLoader()
Retrieves the current plugin class loader.
|
static java.util.Set<java.lang.Integer> |
getClientPackets()
Deprecated.
|
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.
|
com.comphenix.protocol.injector.packet.InterceptWritePacket |
getInterceptWritePacket()
Retrieve the object responsible for intercepting write packets.
|
MinecraftVersion |
getMinecraftVersion()
Retrieve the current Minecraft version.
|
java.lang.Class<?> |
getPacketClassFromID(int packetID,
boolean forceVanilla)
Deprecated.
|
int |
getPacketID(java.lang.Object packet)
Deprecated.
|
com.google.common.collect.ImmutableSet<PacketListener> |
getPacketListeners()
Retrieves a list of every registered packet listener.
|
PacketType |
getPacketType(java.lang.Object packet)
Retrieve the associated type of a packet.
|
PacketFilterManager.PlayerInjectHooks |
getPlayerHook()
Retrieves how the server packets are read.
|
java.util.Set<java.lang.Integer> |
getReceivingFilters()
Retrieves a immutable set containing the ID of the received client packets that will be observed by listeners.
|
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.
|
static java.util.Set<java.lang.Integer> |
getServerPackets()
Deprecated.
|
void |
initializePlayers(org.bukkit.entity.Player[] players)
Initialize the packet injection for every player.
|
void |
invokePacketRecieving(PacketEvent event)
Invokes the given packet event for every registered listener.
|
void |
invokePacketSending(PacketEvent event)
Invokes the given packet event for every registered listener.
|
boolean |
isClosed()
Determines whether or not this protocol manager has been disabled.
|
boolean |
isDebug()
Determine if debug mode is enabled.
|
static PacketFilterBuilder |
newBuilder()
Construct a new packet filter builder.
|
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 |
registerPacketClass(java.lang.Class<?> clazz,
int packetID)
Deprecated.
|
void |
removePacketListener(PacketListener listener)
Removes a given packet listener.
|
void |
removePacketListeners(org.bukkit.plugin.Plugin plugin)
Removes every listener associated with the given plugin.
|
boolean |
requireInputBuffer(int packetId)
Determine if a given packet requires input buffering.
|
void |
sendServerPacket(org.bukkit.entity.Player reciever,
PacketContainer packet)
Send a packet to the given player.
|
void |
sendServerPacket(org.bukkit.entity.Player reciever,
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 |
setDebug(boolean debug)
Set whether or not debug mode is enabled.
|
void |
setPlayerHook(PacketFilterManager.PlayerInjectHooks playerHook)
Sets how the server packets are read.
|
void |
uninitializePlayers(org.bukkit.entity.Player[] players)
Uninitialize the packet injection of every player.
|
void |
unregisterPacketClass(java.lang.Class<?> clazz)
Deprecated.
|
void |
updateEntity(org.bukkit.entity.Entity entity,
java.util.List<org.bukkit.entity.Player> observers)
Completely resend an entity to a list of clients.
|
static void |
verifyWhitelist(PacketListener listener,
ListeningWhitelist whitelist)
Determine if the packet IDs in a whitelist is valid.
|
public static final ReportType REPORT_CANNOT_LOAD_PACKET_LIST
public static final ReportType REPORT_CANNOT_INITIALIZE_PACKET_INJECTOR
public static final ReportType REPORT_PLUGIN_DEPEND_MISSING
public static final ReportType REPORT_UNSUPPORTED_SERVER_PACKET_ID
public static final ReportType REPORT_UNSUPPORTED_CLIENT_PACKET_ID
public static final ReportType REPORT_CANNOT_UNINJECT_PLAYER
public static final ReportType REPORT_CANNOT_UNINJECT_OFFLINE_PLAYER
public static final ReportType REPORT_CANNOT_INJECT_PLAYER
public static final ReportType REPORT_CANNOT_UNREGISTER_PLUGIN
public static final ReportType REPORT_PLUGIN_VERIFIER_ERROR
public static final int TICKS_PER_SECOND
public PacketFilterManager(PacketFilterBuilder builder)
public static PacketFilterBuilder newBuilder()
public MinecraftVersion getMinecraftVersion()
ProtocolManager
getMinecraftVersion
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 PacketFilterManager.PlayerInjectHooks getPlayerHook()
getPlayerHook
in interface InternalManager
public void setPlayerHook(PacketFilterManager.PlayerInjectHooks playerHook)
setPlayerHook
in interface InternalManager
playerHook
- - the new injection method for reading server packets.public com.google.common.collect.ImmutableSet<PacketListener> getPacketListeners()
ProtocolManager
getPacketListeners
in interface ProtocolManager
public com.comphenix.protocol.injector.packet.InterceptWritePacket getInterceptWritePacket()
ListenerInvoker
getInterceptWritePacket
in interface ListenerInvoker
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 static void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist)
listener
- - the listener that will be mentioned in the error.whitelist
- - whitelist of packet IDs.java.lang.IllegalArgumentException
- If the whitelist is illegal.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.public void invokePacketRecieving(PacketEvent event)
ListenerInvoker
invokePacketRecieving
in interface ListenerInvoker
event
- - the packet event to invoke.public void invokePacketSending(PacketEvent event)
ListenerInvoker
invokePacketSending
in interface ListenerInvoker
event
- - the packet event to invoke.public boolean requireInputBuffer(int packetId)
ListenerInvoker
requireInputBuffer
in interface ListenerInvoker
packetId
- - the packet to check.public void broadcastServerPacket(PacketContainer packet)
ProtocolManager
broadcastServerPacket
in interface ProtocolManager
packet
- - the packet to broadcast.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 sendServerPacket(org.bukkit.entity.Player reciever, PacketContainer packet) throws java.lang.reflect.InvocationTargetException
PacketStream
sendServerPacket
in interface PacketStream
reciever
- - 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 reciever, 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
reciever
- - 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.@Deprecated public PacketContainer createPacket(int id)
ProtocolManager
Deprecated: Use ProtocolManager.createPacket(PacketType)
instead.
createPacket
in interface ProtocolManager
id
- - packet ID.public PacketContainer createPacket(PacketType type)
ProtocolManager
createPacket
in interface ProtocolManager
type
- - packet type.@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 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.@Deprecated 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
public java.util.Set<java.lang.Integer> getReceivingFilters()
ProtocolManager
Deprecated: Use ProtocolManager.getReceivingFilterTypes()
instead.
getReceivingFilters
in interface ProtocolManager
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 void initializePlayers(org.bukkit.entity.Player[] players)
players
- - list of players to inject.public void uninitializePlayers(org.bukkit.entity.Player[] players)
players
- - list of players to uninject.public void registerEvents(org.bukkit.plugin.PluginManager manager, org.bukkit.plugin.Plugin plugin)
registerEvents
in interface InternalManager
manager
- - Bukkit plugin manager that provides player join/leave events.plugin
- - the parent plugin.@Deprecated public int getPacketID(java.lang.Object packet)
ListenerInvoker
getPacketID
in interface ListenerInvoker
packet
- - the packet.public PacketType getPacketType(java.lang.Object packet)
ListenerInvoker
getPacketType
in interface ListenerInvoker
packet
- - the packet.@Deprecated public void registerPacketClass(java.lang.Class<?> clazz, int packetID)
ListenerInvoker
registerPacketClass
in interface ListenerInvoker
clazz
- - class to register.packetID
- - the the new associated packet ID.@Deprecated public void unregisterPacketClass(java.lang.Class<?> clazz)
ListenerInvoker
unregisterPacketClass
in interface ListenerInvoker
clazz
- - class to associate.@Deprecated public java.lang.Class<?> getPacketClassFromID(int packetID, boolean forceVanilla)
ListenerInvoker
getPacketClassFromID
in interface ListenerInvoker
packetID
- - the packet ID.forceVanilla
- - whether or not to look for vanilla classes, not injected classes.@Deprecated public static java.util.Set<java.lang.Integer> getServerPackets() throws FieldAccessException
FieldAccessException
- If we're unable to retrieve the server packet data from Minecraft.@Deprecated public static java.util.Set<java.lang.Integer> getClientPackets() throws FieldAccessException
FieldAccessException
- If we're unable to retrieve the client packet data from Minecraft.public java.lang.ClassLoader getClassLoader()
public boolean isClosed()
ProtocolManager
isClosed
in interface ProtocolManager
public void close()
InternalManager
close
in interface InternalManager
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable