Interface PluginMessenger


public interface PluginMessenger
Listens to plugin message channels, for one plugin: what it listens to is released when the plugin is disabled.

The server announces every channel it listens to, so that clients and proxies know they can send on it, and keeps announcing new channels to the players already in the game. Messages are sent with Player.sendPluginMessage(Key, byte[]), on any channel, without declaring it first.

Since:
0.1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The most bytes a message received from a player can hold.
    static final int
    The most bytes a message sent to a player can hold.
    static final Key
    The channel on which clients and proxies announce the channels they listen to, handled by the server: nothing can listen or send on it.
    static final Key
    The channel on which clients and proxies withdraw the channels they listened to, handled by the server: nothing can listen or send on it.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the channels the server listens to, those of every plugin.
    listen(Key channel, PluginMessageListener listener)
    Listens to a channel.
  • Field Details

    • MAX_SENT_SIZE

      static final int MAX_SENT_SIZE
      The most bytes a message sent to a player can hold.
      Since:
      0.1.0
      See Also:
    • MAX_RECEIVED_SIZE

      static final int MAX_RECEIVED_SIZE
      The most bytes a message received from a player can hold.
      Since:
      0.1.0
      See Also:
    • REGISTER

      static final Key REGISTER
      The channel on which clients and proxies announce the channels they listen to, handled by the server: nothing can listen or send on it.
      Since:
      0.1.0
    • UNREGISTER

      static final Key UNREGISTER
      The channel on which clients and proxies withdraw the channels they listened to, handled by the server: nothing can listen or send on it.
      Since:
      0.1.0
  • Method Details

    • listen

      Subscription listen(Key channel, PluginMessageListener listener)
      Listens to a channel.

      listener receives the messages players send on the channel while they are in the game, on the network thread: it must not block, and hands any work on the world over to the right thread. Several listeners, of one plugin or several, can listen to the same channel.

      A message can come from the player's client as well as from the proxy: never trust it blindly.

      Parameters:
      channel - the channel
      listener - what to do with each message
      Returns:
      the subscription, to stop listening before the plugin is disabled
      Throws:
      IllegalArgumentException - if channel or listener is null, or if the channel is REGISTER or UNREGISTER
      Since:
      0.1.0
    • channels

      Set<Key> channels()
      Gets the channels the server listens to, those of every plugin.
      Returns:
      the channels, as they are now
      Since:
      0.1.0