Class ProtocolManager

java.lang.Object
dev.magicmq.pyspigot.bungee.manager.protocol.ProtocolManager

public class ProtocolManager extends Object
Manager to interface with Protocolize. Primarily used by scripts to register and unregister packet listeners on the BungeeCord proxy.

Do not call this manager if Protocolize is not loaded and enabled on the server! It will not work.

See Also:
  • Protocolize
  • Method Details

    • registerPacketListener

      public ScriptPacketListener<?> registerPacketListener(PyFunction receiveFunction, PyFunction sendFunction, Class<?> packet, dev.simplix.protocolize.api.Direction direction)
      Register a new packet listener with default priority.

      Note: This should be called from scripts only!

      Parameters:
      receiveFunction - The function that should be called when the packet is received
      sendFunction - The function that should be called when the packet is sent
      packet - The packet to listen to
      direction - The direction (either Direction.UPSTREAM or Direction.DOWNSTREAM
      Returns:
      A ScriptPacketListener representing the packet listener that was registered
    • registerPacketListener

      public ScriptPacketListener<?> registerPacketListener(PyFunction receiveFunction, PyFunction sendFunction, Class<?> packet, dev.simplix.protocolize.api.Direction direction, int priority)
      Register a new packet listener with default priority.

      Note: This should be called from scripts only!

      Parameters:
      receiveFunction - The function that should be called when the packet is received
      sendFunction - The function that should be called when the packet is sent
      packet - The packet to listen to
      direction - The direction (either Direction.UPSTREAM or Direction.DOWNSTREAM
      priority - The priority of the listener
      Returns:
      A ScriptPacketListener representing the packet listener that was registered
    • unregisterPacketListener

      public void unregisterPacketListener(ScriptPacketListener<?> listener)
      Unregister a packet listener.

      Note: This should be called from scripts only!

      Parameters:
      listener - The packet listener to unregister
    • unregisterPacketListeners

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

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

      public ScriptPacketListener<?> getPacketListener(dev.magicmq.pyspigot.manager.script.Script script, Class<?> packet)
      Get the packet listener for a particular packet associated with a script.
      Parameters:
      script - The script
      packet - The packet
      Returns:
      The ScriptPacketListener associated with the script and packet type, null if there is none
    • sendPacket

      public void sendPacket(UUID playerUUID, dev.simplix.protocolize.api.packet.AbstractPacket packet)
      Send a Protocolize packet to the player with the given UUID.

      Note: This should be called from scripts only!

      Parameters:
      playerUUID - The UUID of the player to send the packet to
      packet - The packet to send
    • sendPacket

      public void sendPacket(UUID playerUUID, net.md_5.bungee.protocol.DefinedPacket packet)
      Send a generic BungeeCord packet to the player with the given UUID.

      Note: This should be called from scripts only!

      Parameters:
      playerUUID - The UUID of the player to send the packet to
      packet - The packet to send
    • get

      public static ProtocolManager get()