Class PluginMessageManager

java.lang.Object
dev.magicmq.pyspigot.bukkit.manager.messaging.PluginMessageManager

public class PluginMessageManager extends Object
Manager to interface with Spigot/Paper's plugin messaging system. Primarily used by scripts to register and unregister plugin message listeners. Can also be used to send plugin messages.
See Also:
  • Method Details

    • sendBungeeMessage

      public void sendBungeeMessage(Player player, String messageType, Object... payload)
      Send a plugin message of the specified message type/subchannel on the "BungeeCord" channel with the specified payload.

      The payload will differ depending on the message type or subchannel and is typically a server name or player name.

      Parameters:
      player - The player to use when sending the plugin message
      messageType - The message type or subchannel, for example, "Connect" or "PlayerCount"
      payload - The payload to send with the message
    • sendMessage

      public void sendMessage(Player player, String channel, Object... payload)
      Send a plugin message on the specified channel with the specified payload. Allowed types for the payload include String, Integer, Short, Byte, Boolean, and a byte array.
      Parameters:
      player - The player to use when sending the plugin message
      channel - The channel to send the message on
      payload - The payload to send with the message
    • sendRawMessage

      public void sendRawMessage(Player player, String channel, byte[] payload)
      Send a plugin message on the specified channel with the specified payload. The payload should be passed as a raw byte array.
      Parameters:
      player - The player to use when sending the plugin message
      channel - The channel to send the message on
      payload - The payload to send with the message
    • registerListener

      public ScriptPluginMessageListener registerListener(PyFunction function, String channel)
      Register a new plugin message listener to listen on the given channel.

      Note: This should be called from scripts only!

      Parameters:
      function - The function that should be called when a message is received on the channel
      channel - The channel to listen on
      Returns:
      The plugin message listener that was registered
    • unregisterListener

      public void unregisterListener(ScriptPluginMessageListener listener)
      Unregister a plugin message listener.

      Note: This should be called from scripts only!

      Parameters:
      listener - The listener to unregister
    • unregisterListeners

      public void unregisterListeners(dev.magicmq.pyspigot.manager.script.Script script)
      Unregister all plugin message listeners belonging to a script.
      Parameters:
      script - The script whose plugin message listeners should be unregistered
    • getListener

      public ScriptPluginMessageListener getListener(dev.magicmq.pyspigot.manager.script.Script script, String channel)
      Get the plugin message listener for a particular channel associated with a script
      Parameters:
      script - The script
      channel - The channel
      Returns:
      The listener associated with the script and channel, or null if there is none
    • getListeners

      public List<ScriptPluginMessageListener> getListeners(dev.magicmq.pyspigot.manager.script.Script script)
      Get all plugin message listeners associated with a script.
      Parameters:
      script - The script to get plugin message listeners from
      Returns:
      An immutable List containing all plugin message listeners associated with the script. Will return an empty list if there are no plugin message listeners associated with the script
    • get

      public static PluginMessageManager get()
      Get the singleton instance of this PluginMessageManager.
      Returns:
      The instance