Class AsyncProtocolManager

java.lang.Object
dev.magicmq.pyspigot.bukkit.manager.protocol.AsyncProtocolManager

public class AsyncProtocolManager extends Object
Manager to interface with ProtocolLib's AsynchronousManager. Primarily used by scripts to register and unregister asynchronous packet listeners on Bukkit/Minecraft.
See Also:
  • Constructor Details

    • AsyncProtocolManager

      protected AsyncProtocolManager()
  • Method Details

    • getAsynchronousManager

      public AsynchronousManager getAsynchronousManager()
      Get the current ProtocolLib AsynchronousManager.
      Returns:
      The AsynchronousManager
    • registerAsyncPacketListener

      public ScriptPacketListener registerAsyncPacketListener(PyFunction function, PacketType type)
      Register a new asynchronous packet listener with default priority.

      This method will automatically register a PacketReceivingListener or a PacketSendingListener, depending on if the PacketType is for the server or client, respectively.

      Note: This should be called from scripts only!

      Parameters:
      function - The function that should be called when the packet event occurs
      type - The packet type to listen for
      Returns:
      A ScriptPacketListener representing the asynchronous packet listener that was registered
    • registerAsyncPacketListener

      public ScriptPacketListener registerAsyncPacketListener(PyFunction function, PacketType type, ListenerPriority priority)
      Register a new asynchronous packet listener.

      This method will automatically register a PacketReceivingListener or a PacketSendingListener, depending on if the PacketType is for the server or client, respectively.

      Note: This should be called from scripts only!

      Parameters:
      function - The function that should be called when the packet event occurs
      type - The packet type to listen for
      priority - The priority of the asynchronous packet listener relative to other packet listeners
      Returns:
      A ScriptPacketListener representing the asynchronous packet listener that was registered
    • registerTimeoutPacketListener

      public ScriptPacketListener registerTimeoutPacketListener(PyFunction function, PacketType type)
      Register a new asynchronous timeout packet listener with default priority.

      This method will automatically register a PacketReceivingListener or a PacketSendingListener, depending on if the PacketType is for the server or client, respectively.

      Note: This should be called from scripts only!

      Parameters:
      function - The function that should be called when the packet event occurs
      type - The packet type to listen for
      Returns:
      A ScriptPacketListener representing the asynchronous timeout packet listener that was registered
    • registerTimeoutPacketListener

      public ScriptPacketListener registerTimeoutPacketListener(PyFunction function, PacketType type, ListenerPriority priority)
      Register a new asynchronous timeout packet listener.

      This method will automatically register a PacketReceivingListener or a PacketSendingListener, depending on if the PacketType is for the server or client, respectively.

      Note: This should be called from scripts only!

      Parameters:
      function - The function that should be called when the packet event occurs
      type - The packet type to listen for
      priority - The priority of the asynchronous timeout packet listener relative to other asynchronous timeout packet listeners
      Returns:
      A ScriptPacketListener representing the asynchronous timeout packet listener that was registered
    • unregisterAsyncPacketListener

      public void unregisterAsyncPacketListener(ScriptPacketListener listener)
      Unregister an asynchronous packet listener.

      Note: This should be called from scripts only!

      Parameters:
      listener - The asynchronous packet listener to unregister
    • unregisterAsyncPacketListeners

      public void unregisterAsyncPacketListeners(dev.magicmq.pyspigot.manager.script.Script script)
      Unregister all asynchronous packet listeners belonging to a script.
      Parameters:
      script - The script whose asynchronous packet listeners should be unregistered
    • getAsyncPacketListeners

      public List<ScriptPacketListener> getAsyncPacketListeners(dev.magicmq.pyspigot.manager.script.Script script)
      Get all asynchronous packet listeners associated with a script
      Parameters:
      script - The script to get asynchronous packet listeners from
      Returns:
      An immutable list of ScriptPacketListener containing all asynchronous packet listeners associated with this script. Will return an empty list if there are no asynchronous packet listeners associated with the script
    • getAsyncPacketListener

      public ScriptPacketListener getAsyncPacketListener(dev.magicmq.pyspigot.manager.script.Script script, PacketType packetType)
      Get the asynchronous packet listener for a particular packet type associated with a script
      Parameters:
      script - The script
      packetType - The packet type
      Returns:
      The ScriptPacketListener associated with the script and packet type, or null if there is none