Package org.bukkit.plugin.messaging
Interface Messenger
- All Known Implementing Classes:
StandardMessenger
public interface Messenger
A class responsible for managing the registrations of plugin channels and
their listeners.
Channel names must contain a colon separator and consist of only [a-z0-9/._-]
- i.e. they MUST be valid
NamespacedKey
. The "BungeeCord" channel is
an exception and may only take this form.-
Field Summary
Modifier and TypeFieldDescriptionstatic int
Represents the largest size that a Plugin Channel may be.static int
Represents the largest size that an individual Plugin Message may be. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispatchIncomingMessage(Player source, String channel, byte[] message)
Dispatches the specified incoming message to any registered listeners.getIncomingChannelRegistrations(String channel)
Gets a set containing all the incoming plugin channel registrations that are on the requested channel.getIncomingChannelRegistrations(Plugin plugin)
Gets a set containing all the incoming plugin channel registrations that the specified plugin has.getIncomingChannelRegistrations(Plugin plugin, String channel)
Gets a set containing all the incoming plugin channel registrations that the specified plugin has on the requested channel.Gets a set containing all the incoming plugin channels.getIncomingChannels(Plugin plugin)
Gets a set containing all the incoming plugin channels that the specified plugin is registered for.Gets a set containing all the outgoing plugin channels.getOutgoingChannels(Plugin plugin)
Gets a set containing all the outgoing plugin channels that the specified plugin is registered to.boolean
isIncomingChannelRegistered(Plugin plugin, String channel)
Checks if the specified plugin has registered to receive incoming messages through the requested channel.boolean
isOutgoingChannelRegistered(Plugin plugin, String channel)
Checks if the specified plugin has registered to send outgoing messages through the requested channel.boolean
isRegistrationValid(PluginMessageListenerRegistration registration)
Checks if the specified plugin message listener registration is valid.boolean
isReservedChannel(String channel)
Checks if the specified channel is a reserved name.registerIncomingPluginChannel(Plugin plugin, String channel, PluginMessageListener listener)
Registers the specific plugin for listening on the requested incoming plugin channel, allowing it to act upon any plugin messages.void
registerOutgoingPluginChannel(Plugin plugin, String channel)
Registers the specific plugin to the requested outgoing plugin channel, allowing it to send messages through that channel to any clients.void
unregisterIncomingPluginChannel(Plugin plugin)
Unregisters the specific plugin from listening on all plugin channels through all listeners.void
unregisterIncomingPluginChannel(Plugin plugin, String channel)
Unregisters the specific plugin from listening on the requested incoming plugin channel, no longer allowing it to act upon any plugin messages.void
unregisterIncomingPluginChannel(Plugin plugin, String channel, PluginMessageListener listener)
Unregisters the specific plugin's listener from listening on the requested incoming plugin channel, no longer allowing it to act upon any plugin messages.void
unregisterOutgoingPluginChannel(Plugin plugin)
Unregisters the specific plugin from all outgoing plugin channels, no longer allowing it to send any plugin messages.void
unregisterOutgoingPluginChannel(Plugin plugin, String channel)
Unregisters the specific plugin from the requested outgoing plugin channel, no longer allowing it to send messages through that channel to any clients.
-
Field Details
-
MAX_MESSAGE_SIZE
static final int MAX_MESSAGE_SIZERepresents the largest size that an individual Plugin Message may be.- See Also:
- Constant Field Values
-
MAX_CHANNEL_SIZE
static final int MAX_CHANNEL_SIZERepresents the largest size that a Plugin Channel may be.- See Also:
- Constant Field Values
-
-
Method Details
-
isReservedChannel
Checks if the specified channel is a reserved name.
All channels within the "minecraft" namespace except for "minecraft:brand" are reserved.- Parameters:
channel
- Channel name to check.- Returns:
- True if the channel is reserved, otherwise false.
- Throws:
IllegalArgumentException
- Thrown if channel is null.
-
registerOutgoingPluginChannel
Registers the specific plugin to the requested outgoing plugin channel, allowing it to send messages through that channel to any clients.- Parameters:
plugin
- Plugin that wishes to send messages through the channel.channel
- Channel to register.- Throws:
IllegalArgumentException
- Thrown if plugin or channel is null.
-
unregisterOutgoingPluginChannel
Unregisters the specific plugin from the requested outgoing plugin channel, no longer allowing it to send messages through that channel to any clients.- Parameters:
plugin
- Plugin that no longer wishes to send messages through the channel.channel
- Channel to unregister.- Throws:
IllegalArgumentException
- Thrown if plugin or channel is null.
-
unregisterOutgoingPluginChannel
Unregisters the specific plugin from all outgoing plugin channels, no longer allowing it to send any plugin messages.- Parameters:
plugin
- Plugin that no longer wishes to send plugin messages.- Throws:
IllegalArgumentException
- Thrown if plugin is null.
-
registerIncomingPluginChannel
@NotNull PluginMessageListenerRegistration registerIncomingPluginChannel(@NotNull Plugin plugin, @NotNull String channel, @NotNull PluginMessageListener listener)Registers the specific plugin for listening on the requested incoming plugin channel, allowing it to act upon any plugin messages.- Parameters:
plugin
- Plugin that wishes to register to this channel.channel
- Channel to register.listener
- Listener to receive messages on.- Returns:
- The resulting registration that was made as a result of this method.
- Throws:
IllegalArgumentException
- Thrown if plugin, channel or listener is null, or the listener is already registered for this channel.
-
unregisterIncomingPluginChannel
void unregisterIncomingPluginChannel(@NotNull Plugin plugin, @NotNull String channel, @NotNull PluginMessageListener listener)Unregisters the specific plugin's listener from listening on the requested incoming plugin channel, no longer allowing it to act upon any plugin messages.- Parameters:
plugin
- Plugin that wishes to unregister from this channel.channel
- Channel to unregister.listener
- Listener to stop receiving messages on.- Throws:
IllegalArgumentException
- Thrown if plugin, channel or listener is null.
-
unregisterIncomingPluginChannel
Unregisters the specific plugin from listening on the requested incoming plugin channel, no longer allowing it to act upon any plugin messages.- Parameters:
plugin
- Plugin that wishes to unregister from this channel.channel
- Channel to unregister.- Throws:
IllegalArgumentException
- Thrown if plugin or channel is null.
-
unregisterIncomingPluginChannel
Unregisters the specific plugin from listening on all plugin channels through all listeners.- Parameters:
plugin
- Plugin that wishes to unregister from this channel.- Throws:
IllegalArgumentException
- Thrown if plugin is null.
-
getOutgoingChannels
Gets a set containing all the outgoing plugin channels.- Returns:
- List of all registered outgoing plugin channels.
-
getOutgoingChannels
Gets a set containing all the outgoing plugin channels that the specified plugin is registered to.- Parameters:
plugin
- Plugin to retrieve channels for.- Returns:
- List of all registered outgoing plugin channels that a plugin is registered to.
- Throws:
IllegalArgumentException
- Thrown if plugin is null.
-
getIncomingChannels
Gets a set containing all the incoming plugin channels.- Returns:
- List of all registered incoming plugin channels.
-
getIncomingChannels
Gets a set containing all the incoming plugin channels that the specified plugin is registered for.- Parameters:
plugin
- Plugin to retrieve channels for.- Returns:
- List of all registered incoming plugin channels that the plugin is registered for.
- Throws:
IllegalArgumentException
- Thrown if plugin is null.
-
getIncomingChannelRegistrations
@NotNull Set<PluginMessageListenerRegistration> getIncomingChannelRegistrations(@NotNull Plugin plugin)Gets a set containing all the incoming plugin channel registrations that the specified plugin has.- Parameters:
plugin
- Plugin to retrieve registrations for.- Returns:
- List of all registrations that the plugin has.
- Throws:
IllegalArgumentException
- Thrown if plugin is null.
-
getIncomingChannelRegistrations
@NotNull Set<PluginMessageListenerRegistration> getIncomingChannelRegistrations(@NotNull String channel)Gets a set containing all the incoming plugin channel registrations that are on the requested channel.- Parameters:
channel
- Channel to retrieve registrations for.- Returns:
- List of all registrations that are on the channel.
- Throws:
IllegalArgumentException
- Thrown if channel is null.
-
getIncomingChannelRegistrations
@NotNull Set<PluginMessageListenerRegistration> getIncomingChannelRegistrations(@NotNull Plugin plugin, @NotNull String channel)Gets a set containing all the incoming plugin channel registrations that the specified plugin has on the requested channel.- Parameters:
plugin
- Plugin to retrieve registrations for.channel
- Channel to filter registrations by.- Returns:
- List of all registrations that the plugin has.
- Throws:
IllegalArgumentException
- Thrown if plugin or channel is null.
-
isRegistrationValid
Checks if the specified plugin message listener registration is valid.A registration is considered valid if it has not be unregistered and that the plugin is still enabled.
- Parameters:
registration
- Registration to check.- Returns:
- True if the registration is valid, otherwise false.
-
isIncomingChannelRegistered
Checks if the specified plugin has registered to receive incoming messages through the requested channel.- Parameters:
plugin
- Plugin to check registration for.channel
- Channel to test for.- Returns:
- True if the channel is registered, else false.
-
isOutgoingChannelRegistered
Checks if the specified plugin has registered to send outgoing messages through the requested channel.- Parameters:
plugin
- Plugin to check registration for.channel
- Channel to test for.- Returns:
- True if the channel is registered, else false.
-
dispatchIncomingMessage
void dispatchIncomingMessage(@NotNull Player source, @NotNull String channel, @NotNull byte[] message)Dispatches the specified incoming message to any registered listeners.- Parameters:
source
- Source of the message.channel
- Channel that the message was sent by.message
- Raw payload of the message.
-