Class PacketFilterManager

java.lang.Object
com.comphenix.protocol.injector.PacketFilterManager
All Implemented Interfaces:
InternalManager, ListenerInvoker, PacketStream, ProtocolManager

public final class PacketFilterManager extends Object implements ListenerInvoker, InternalManager
  • Field Details

    • REPORT_CANNOT_LOAD_PACKET_LIST

      public static final ReportType REPORT_CANNOT_LOAD_PACKET_LIST
    • REPORT_CANNOT_INITIALIZE_PACKET_INJECTOR

      public static final ReportType REPORT_CANNOT_INITIALIZE_PACKET_INJECTOR
    • REPORT_PLUGIN_DEPEND_MISSING

      public static final ReportType REPORT_PLUGIN_DEPEND_MISSING
    • REPORT_UNSUPPORTED_SERVER_PACKET

      public static final ReportType REPORT_UNSUPPORTED_SERVER_PACKET
    • REPORT_UNSUPPORTED_CLIENT_PACKET

      public static final ReportType REPORT_UNSUPPORTED_CLIENT_PACKET
    • REPORT_CANNOT_UNINJECT_PLAYER

      public static final ReportType REPORT_CANNOT_UNINJECT_PLAYER
    • REPORT_CANNOT_UNINJECT_OFFLINE_PLAYER

      public static final ReportType REPORT_CANNOT_UNINJECT_OFFLINE_PLAYER
    • REPORT_CANNOT_INJECT_PLAYER

      public static final ReportType REPORT_CANNOT_INJECT_PLAYER
    • REPORT_CANNOT_UNREGISTER_PLUGIN

      public static final ReportType REPORT_CANNOT_UNREGISTER_PLUGIN
    • REPORT_PLUGIN_VERIFIER_ERROR

      public static final ReportType REPORT_PLUGIN_VERIFIER_ERROR
    • TICKS_PER_SECOND

      public static final int TICKS_PER_SECOND
      The number of ticks in a second.
      See Also:
      Constant Field Values
  • Constructor Details

    • PacketFilterManager

      public PacketFilterManager(PacketFilterBuilder builder)
      Only create instances of this class if ProtocolLib is disabled.
      Parameters:
      builder - - PacketFilterBuilder
  • Method Details

    • newBuilder

      public static PacketFilterBuilder newBuilder()
      Construct a new packet filter builder.
      Returns:
      New builder.
    • getProtocolVersion

      public int getProtocolVersion(org.bukkit.entity.Player player)
      Description copied from interface: ProtocolManager
      Retrieve 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:
      getProtocolVersion in interface ProtocolManager
      Parameters:
      player - - the player.
      Returns:
      The associated protocol version, or Integer.MIN_VALUE if unknown.
    • getMinecraftVersion

      public MinecraftVersion getMinecraftVersion()
      Description copied from interface: ProtocolManager
      Retrieve the current Minecraft version.
      Specified by:
      getMinecraftVersion in interface ProtocolManager
      Returns:
      The current version.
    • getAsynchronousManager

      public AsynchronousManager getAsynchronousManager()
      Description copied from interface: ProtocolManager
      Retrieve the current asynchronous packet manager.
      Specified by:
      getAsynchronousManager in interface ProtocolManager
      Returns:
      Asynchronous packet manager.
    • isDebug

      public boolean isDebug()
      Description copied from interface: InternalManager
      Determine if debug mode is enabled.
      Specified by:
      isDebug in interface InternalManager
      Returns:
      TRUE if it is, FALSE otherwise.
    • setDebug

      public void setDebug(boolean debug)
      Description copied from interface: InternalManager
      Set whether or not debug mode is enabled.
      Specified by:
      setDebug in interface InternalManager
      Parameters:
      debug - - TRUE if it is, FALSE otherwise.
    • getPlayerHook

      public PlayerInjectHooks getPlayerHook()
      Retrieves how the server packets are read.
      Specified by:
      getPlayerHook in interface InternalManager
      Returns:
      Injection method for reading server packets.
    • setPlayerHook

      public void setPlayerHook(PlayerInjectHooks playerHook)
      Sets how the server packets are read.
      Specified by:
      setPlayerHook in interface InternalManager
      Parameters:
      playerHook - - the new injection method for reading server packets.
    • getPacketListeners

      public com.google.common.collect.ImmutableSet<PacketListener> getPacketListeners()
      Description copied from interface: ProtocolManager
      Retrieves a list of every registered packet listener.
      Specified by:
      getPacketListeners in interface ProtocolManager
      Returns:
      Every registered packet listener.
    • addPacketListener

      public void addPacketListener(PacketListener listener)
      Description copied from interface: ProtocolManager
      Adds 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:
      addPacketListener in interface ProtocolManager
      Parameters:
      listener - - new packet listener.
    • isLoginPacket

      public boolean isLoginPacket(PacketType type)
      Determine if a given packet may be sent during login.
      Parameters:
      type - - the packet type.
      Returns:
      TRUE if it may, FALSE otherwise.
    • verifyWhitelist

      public void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist)
      Determine if the packet IDs in a whitelist is valid.
      Specified by:
      verifyWhitelist in interface ProtocolManager
      Parameters:
      listener - - the listener that will be mentioned in the error.
      whitelist - - whitelist of packet IDs.
      Throws:
      IllegalArgumentException - If the whitelist is illegal.
    • removePacketListener

      public void removePacketListener(PacketListener listener)
      Description copied from interface: ProtocolManager
      Removes a given packet listener.

      Attempting to remove a listener that doesn't exist has no effect.

      Specified by:
      removePacketListener in interface ProtocolManager
      Parameters:
      listener - - the packet listener to remove.
    • removePacketListeners

      public void removePacketListeners(org.bukkit.plugin.Plugin plugin)
      Description copied from interface: ProtocolManager
      Removes every listener associated with the given plugin.
      Specified by:
      removePacketListeners in interface ProtocolManager
      Parameters:
      plugin - - the plugin to unload.
    • invokePacketRecieving

      public void invokePacketRecieving(PacketEvent event)
      Description copied from interface: ListenerInvoker
      Invokes the given packet event for every registered listener.
      Specified by:
      invokePacketRecieving in interface ListenerInvoker
      Parameters:
      event - - the packet event to invoke.
    • invokePacketSending

      public void invokePacketSending(PacketEvent event)
      Description copied from interface: ListenerInvoker
      Invokes the given packet event for every registered listener.
      Specified by:
      invokePacketSending in interface ListenerInvoker
      Parameters:
      event - - the packet event to invoke.
    • broadcastServerPacket

      public void broadcastServerPacket(PacketContainer packet)
      Description copied from interface: ProtocolManager
      Broadcast a given packet to every connected player on the server.
      Specified by:
      broadcastServerPacket in interface ProtocolManager
      Parameters:
      packet - - the packet to broadcast.
    • broadcastServerPacket

      public void broadcastServerPacket(PacketContainer packet, org.bukkit.entity.Entity entity, boolean includeTracker)
      Description copied from interface: ProtocolManager
      Broadcast 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:
      broadcastServerPacket in interface ProtocolManager
      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: ProtocolManager
      Broadcast a packet to every player within the given maximum observer distance.
      Specified by:
      broadcastServerPacket in interface ProtocolManager
      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 InvocationTargetException
      Description copied from interface: PacketStream
      Send a packet to the given player.
      Specified by:
      sendServerPacket in interface PacketStream
      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 InvocationTargetException
      Description copied from interface: ProtocolManager
      Send 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:
      sendServerPacket in interface PacketStream
      Specified by:
      sendServerPacket in interface ProtocolManager
      Parameters:
      reciever - - the receiver.
      packet - - packet to send.
      filters - - whether or not to invoke any packet filters below ListenerPriority.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 InvocationTargetException
      Description copied from interface: PacketStream
      Send a packet to the given player.
      Specified by:
      sendServerPacket in interface PacketStream
      Parameters:
      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.
      Throws:
      InvocationTargetException - - if an error occured when sending the packet.
    • sendWirePacket

      public void sendWirePacket(org.bukkit.entity.Player receiver, int id, byte[] bytes) throws InvocationTargetException
      Description copied from interface: PacketStream
      Send a wire packet to the given player.
      Specified by:
      sendWirePacket in interface PacketStream
      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 InvocationTargetException
      Description copied from interface: PacketStream
      Send a wire packet to the given player.
      Specified by:
      sendWirePacket in interface PacketStream
      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, InvocationTargetException
      Description copied from interface: PacketStream
      Simulate recieving a certain packet from a given player.
      Specified by:
      recieveClientPacket in interface PacketStream
      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, InvocationTargetException
      Description copied from interface: ProtocolManager
      Simulate 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:
      recieveClientPacket in interface PacketStream
      Specified by:
      recieveClientPacket in interface ProtocolManager
      Parameters:
      sender - - the sender.
      packet - - the packet that was sent.
      filters - - whether or not to invoke any packet filters below ListenerPriority.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, InvocationTargetException
      Description copied from interface: PacketStream
      Simulate recieving a certain packet from a given player.
      Specified by:
      recieveClientPacket in interface PacketStream
      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 below ListenerPriority.MONITOR.
      Throws:
      IllegalAccessException - If the underlying method caused an error.
      InvocationTargetException - If the reflection machinery failed.
    • createPacket

      public PacketContainer createPacket(PacketType type)
      Description copied from interface: ProtocolManager
      Constructs a new encapsulated Minecraft packet with the given ID.
      Specified by:
      createPacket in interface ProtocolManager
      Parameters:
      type - - packet type.
      Returns:
      New encapsulated Minecraft packet.
    • createPacket

      public PacketContainer createPacket(PacketType type, boolean forceDefaults)
      Description copied from interface: ProtocolManager
      Constructs 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:
      createPacket in interface ProtocolManager
      Parameters:
      type - - packet type.
      forceDefaults - - TRUE to use sensible defaults in most fields, FALSE otherwise.
      Returns:
      New encapsulated Minecraft packet.
    • createPacketConstructor

      public PacketConstructor createPacketConstructor(PacketType type, Object... arguments)
      Description copied from interface: ProtocolManager
      Construct a packet using the special builtin Minecraft constructors.
      Specified by:
      createPacketConstructor in interface ProtocolManager
      Parameters:
      type - - the packet type.
      arguments - - arguments that will be passed to the constructor.
      Returns:
      The packet constructor.
    • getSendingFilterTypes

      public Set<PacketType> getSendingFilterTypes()
      Description copied from interface: ProtocolManager
      Retrieves a immutable set containing the type of the sent server packets that will be observed by listeners.
      Specified by:
      getSendingFilterTypes in interface ProtocolManager
      Returns:
      Every filtered server packet.
    • getReceivingFilterTypes

      public Set<PacketType> getReceivingFilterTypes()
      Description copied from interface: ProtocolManager
      Retrieves a immutable set containing the type of the received client packets that will be observed by listeners.
      Specified by:
      getReceivingFilterTypes in interface ProtocolManager
      Returns:
      Every filtered client packet.
    • updateEntity

      public void updateEntity(org.bukkit.entity.Entity entity, List<org.bukkit.entity.Player> observers) throws FieldAccessException
      Description copied from interface: ProtocolManager
      Completely 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:
      updateEntity in interface ProtocolManager
      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 FieldAccessException
      Description copied from interface: ProtocolManager
      Retrieve the associated entity.
      Specified by:
      getEntityFromID in interface ProtocolManager
      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 FieldAccessException
      Description copied from interface: ProtocolManager
      Retrieve every client that is receiving information about a given entity.
      Specified by:
      getEntityTrackers in interface ProtocolManager
      Parameters:
      entity - - the entity that is being tracked.
      Returns:
      Every client/player that is tracking the given entity.
      Throws:
      FieldAccessException - If reflection failed.
    • initializePlayers

      public void initializePlayers(List<org.bukkit.entity.Player> players)
      Initialize the packet injection for every player.
      Parameters:
      players - - list of players to inject.
    • uninitializePlayers

      public void uninitializePlayers(List<org.bukkit.entity.Player> players)
      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:
      registerEvents in interface InternalManager
      Parameters:
      manager - - Bukkit plugin manager that provides player join/leave events.
      plugin - - the parent plugin.
    • getPacketType

      public PacketType getPacketType(Object packet)
      Description copied from interface: ListenerInvoker
      Retrieve the associated type of a packet.
      Specified by:
      getPacketType in interface ListenerInvoker
      Parameters:
      packet - - the packet.
      Returns:
      The packet type.
    • getClassLoader

      public ClassLoader getClassLoader()
      Retrieves the current plugin class loader.
      Returns:
      Class loader.
    • isClosed

      public boolean isClosed()
      Description copied from interface: ProtocolManager
      Determines whether or not this protocol manager has been disabled.
      Specified by:
      isClosed in interface ProtocolManager
      Returns:
      TRUE if it has, FALSE otherwise.
    • close

      public void close()
      Description copied from interface: InternalManager
      Called when ProtocolLib is closing.
      Specified by:
      close in interface InternalManager
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable