Class PacketAdapter

java.lang.Object
com.comphenix.protocol.events.PacketAdapter
All Implemented Interfaces:
PacketListener

public abstract class PacketAdapter extends Object implements PacketListener
Represents a packet listener with useful constructors.

Remember to override onPacketReceiving() and onPacketSending(), depending on the ConnectionSide.

  • Field Details

  • Constructor Details

    • PacketAdapter

      public PacketAdapter(@Nonnull PacketAdapter.AdapterParameteters params)
      Initialize a packet adapter using a collection of parameters. Use params() to get an instance to this builder.
      Parameters:
      params - - the parameters.
    • PacketAdapter

      public PacketAdapter(org.bukkit.plugin.Plugin plugin, PacketType... types)
      Initialize a packet listener with the given parameters.
      Parameters:
      plugin - - the plugin.
      types - - the packet types.
    • PacketAdapter

      public PacketAdapter(org.bukkit.plugin.Plugin plugin, Iterable<? extends PacketType> types)
      Initialize a packet listener with the given parameters.
      Parameters:
      plugin - - the plugin.
      types - - the packet types.
    • PacketAdapter

      public PacketAdapter(org.bukkit.plugin.Plugin plugin, ListenerPriority listenerPriority, Iterable<? extends PacketType> types)
      Initialize a packet listener with the given parameters.
      Parameters:
      plugin - - the plugin.
      listenerPriority - - the priority.
      types - - the packet types.
    • PacketAdapter

      public PacketAdapter(org.bukkit.plugin.Plugin plugin, ListenerPriority listenerPriority, Iterable<? extends PacketType> types, ListenerOptions... options)
      Initialize a packet listener with the given parameters.
      Parameters:
      plugin - - the plugin.
      listenerPriority - - the priority.
      types - - the packet types.
      options - - the options.
    • PacketAdapter

      public PacketAdapter(org.bukkit.plugin.Plugin plugin, ListenerPriority listenerPriority, PacketType... types)
      Initialize a packet listener with the given parameters.
      Parameters:
      plugin - - the plugin.
      listenerPriority - - the priority.
      types - - the packet types.
  • Method Details

    • getPluginName

      public static String getPluginName(PacketListener listener)
      Retrieves the name of the plugin that has been associated with the listener.
      Parameters:
      listener - - the listener.
      Returns:
      Name of the associated plugin.
    • getPluginName

      public static String getPluginName(org.bukkit.plugin.Plugin plugin)
      Retrieves the name of the given plugin.
      Parameters:
      plugin - - the plugin.
      Returns:
      Name of the given plugin.
    • params

      public static PacketAdapter.AdapterParameteters params()
      Construct a helper object for passing parameters to the packet adapter.

      This is often simpler and better than passing them directly to each constructor.

      Returns:
      Helper object.
    • params

      public static PacketAdapter.AdapterParameteters params(org.bukkit.plugin.Plugin plugin, PacketType... packets)
      Construct a helper object for passing parameters to the packet adapter.

      This is often simpler and better than passing them directly to each constructor.

      Parameters:
      plugin - - the plugin that spawned this listener.
      packets - - the packet types the listener is looking for.
      Returns:
      Helper object.
    • onPacketReceiving

      public void onPacketReceiving(PacketEvent event)
      Description copied from interface: PacketListener
      Invoked right before a received packet from a client is being processed.

      This method will be called asynchronously (or on the netty event loop) by default. If the ListenerOptions.SYNC option is specified, the invocation of this method will be synced to the main server thread which might cause issues due to delayed packets.

      Specified by:
      onPacketReceiving in interface PacketListener
      Parameters:
      event - - the packet that has been received.
    • onPacketSending

      public void onPacketSending(PacketEvent event)
      Description copied from interface: PacketListener
      Invoked right before a packet is transmitted from the server to the client.

      Note that the packet may be replaced, if needed.

      This method is executed on the main server thread by default. However, some spigot forks (like paper) schedule specific packets off the main thread. If the ListenerOptions.ASYNC option is not specified any invocation of this method will be on the main server thread.

      Specified by:
      onPacketSending in interface PacketListener
      Parameters:
      event - - the packet that should be sent.
    • getReceivingWhitelist

      public ListeningWhitelist getReceivingWhitelist()
      Description copied from interface: PacketListener
      Retrieve which packets sent by the client this listener will observe.
      Specified by:
      getReceivingWhitelist in interface PacketListener
      Returns:
      List of server packets to observe, along with the priority.
    • getSendingWhitelist

      public ListeningWhitelist getSendingWhitelist()
      Description copied from interface: PacketListener
      Retrieve which packets sent by the server this listener will observe.
      Specified by:
      getSendingWhitelist in interface PacketListener
      Returns:
      List of server packets to observe, along with the priority.
    • getPlugin

      public org.bukkit.plugin.Plugin getPlugin()
      Description copied from interface: PacketListener
      Retrieve the plugin that created list packet listener.
      Specified by:
      getPlugin in interface PacketListener
      Returns:
      The plugin, or NULL if not available.
    • toString

      public String toString()
      Overrides:
      toString in class Object