Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.plugin.messaging.StandardMessenger Class Reference
Inheritance diagram for org.bukkit.plugin.messaging.StandardMessenger:
org.bukkit.plugin.messaging.Messenger

Public Member Functions

boolean isReservedChannel (String channel)
 
void registerOutgoingPluginChannel (Plugin plugin, String channel)
 
void unregisterOutgoingPluginChannel (Plugin plugin, String channel)
 
void unregisterOutgoingPluginChannel (Plugin plugin)
 
PluginMessageListenerRegistration registerIncomingPluginChannel (Plugin plugin, String channel, PluginMessageListener listener)
 
void unregisterIncomingPluginChannel (Plugin plugin, String channel, PluginMessageListener listener)
 
void unregisterIncomingPluginChannel (Plugin plugin, String channel)
 
void unregisterIncomingPluginChannel (Plugin plugin)
 
Set< String > getOutgoingChannels ()
 
Set< String > getOutgoingChannels (Plugin plugin)
 
Set< String > getIncomingChannels ()
 
Set< String > getIncomingChannels (Plugin plugin)
 
Set< PluginMessageListenerRegistrationgetIncomingChannelRegistrations (Plugin plugin)
 
Set< PluginMessageListenerRegistrationgetIncomingChannelRegistrations (String channel)
 
Set< PluginMessageListenerRegistrationgetIncomingChannelRegistrations (Plugin plugin, String channel)
 
boolean isRegistrationValid (PluginMessageListenerRegistration registration)
 
boolean isIncomingChannelRegistered (Plugin plugin, String channel)
 
boolean isOutgoingChannelRegistered (Plugin plugin, String channel)
 
void dispatchIncomingMessage (Player source, String channel, byte[] message)
 

Static Public Member Functions

static void validateChannel (String channel)
 
static void validatePluginMessage (Messenger messenger, Plugin source, String channel, byte[] message)
 

Additional Inherited Members

- Static Public Attributes inherited from org.bukkit.plugin.messaging.Messenger
static final int MAX_MESSAGE_SIZE = 32766
 
static final int MAX_CHANNEL_SIZE = 16
 

Detailed Description

Standard implementation to Messenger

Definition at line 15 of file StandardMessenger.java.

Member Function Documentation

void org.bukkit.plugin.messaging.StandardMessenger.dispatchIncomingMessage ( Player  source,
String  channel,
byte[]  message 
)

Dispatches the specified incoming message to any registered listeners.

Parameters
sourceSource of the message.
channelChannel that the message was sent by.
messageRaw payload of the message.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 412 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.StandardMessenger.getIncomingChannelRegistrations(), org.bukkit.plugin.messaging.PluginMessageListenerRegistration.getListener(), org.bukkit.plugin.messaging.PluginMessageListener.onPluginMessageReceived(), and org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

412  {
413  if (source == null) {
414  throw new IllegalArgumentException("Player source cannot be null");
415  }
416  if (message == null) {
417  throw new IllegalArgumentException("Message cannot be null");
418  }
419  validateChannel(channel);
420 
421  Set<PluginMessageListenerRegistration> registrations = getIncomingChannelRegistrations(channel);
422 
423  for (PluginMessageListenerRegistration registration : registrations) {
424  registration.getListener().onPluginMessageReceived(channel, source, message);
425  }
426  }
Set< PluginMessageListenerRegistration > getIncomingChannelRegistrations(Plugin plugin)
Set<PluginMessageListenerRegistration> org.bukkit.plugin.messaging.StandardMessenger.getIncomingChannelRegistrations ( Plugin  plugin)

Gets a set containing all the incoming plugin channel registrations that the specified plugin has.

Parameters
pluginPlugin to retrieve registrations for.
Returns
List of all registrations that the plugin has.
Exceptions
IllegalArgumentExceptionThrown if plugin is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 303 of file StandardMessenger.java.

Referenced by org.bukkit.plugin.messaging.StandardMessenger.dispatchIncomingMessage().

303  {
304  if (plugin == null) {
305  throw new IllegalArgumentException("Plugin cannot be null");
306  }
307 
308  synchronized (incomingLock) {
309  Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
310 
311  if (registrations != null) {
312  return ImmutableSet.copyOf(registrations);
313  } else {
314  return ImmutableSet.of();
315  }
316  }
317  }
Set<PluginMessageListenerRegistration> org.bukkit.plugin.messaging.StandardMessenger.getIncomingChannelRegistrations ( String  channel)

Gets a set containing all the incoming plugin channel registrations that are on the requested channel.

Parameters
channelChannel to retrieve registrations for.
Returns
List of all registrations that are on the channel.
Exceptions
IllegalArgumentExceptionThrown if channel is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 319 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

319  {
320  validateChannel(channel);
321 
322  synchronized (incomingLock) {
323  Set<PluginMessageListenerRegistration> registrations = incomingByChannel.get(channel);
324 
325  if (registrations != null) {
326  return ImmutableSet.copyOf(registrations);
327  } else {
328  return ImmutableSet.of();
329  }
330  }
331  }
Set<PluginMessageListenerRegistration> org.bukkit.plugin.messaging.StandardMessenger.getIncomingChannelRegistrations ( Plugin  plugin,
String  channel 
)

Gets a set containing all the incoming plugin channel registrations that the specified plugin has on the requested channel.

Parameters
pluginPlugin to retrieve registrations for.
channelChannel to filter registrations by.
Returns
List of all registrations that the plugin has.
Exceptions
IllegalArgumentExceptionThrown if plugin or channel is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 333 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.PluginMessageListenerRegistration.getChannel(), and org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

333  {
334  if (plugin == null) {
335  throw new IllegalArgumentException("Plugin cannot be null");
336  }
337  validateChannel(channel);
338 
339  synchronized (incomingLock) {
340  Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
341 
342  if (registrations != null) {
343  Builder<PluginMessageListenerRegistration> builder = ImmutableSet.builder();
344 
345  for (PluginMessageListenerRegistration registration : registrations) {
346  if (registration.getChannel().equals(channel)) {
347  builder.add(registration);
348  }
349  }
350 
351  return builder.build();
352  } else {
353  return ImmutableSet.of();
354  }
355  }
356  }
Set<String> org.bukkit.plugin.messaging.StandardMessenger.getIncomingChannels ( )

Gets a set containing all the incoming plugin channels.

Returns
List of all registered incoming plugin channels.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 274 of file StandardMessenger.java.

274  {
275  synchronized (incomingLock) {
276  Set<String> keys = incomingByChannel.keySet();
277  return ImmutableSet.copyOf(keys);
278  }
279  }
Set<String> org.bukkit.plugin.messaging.StandardMessenger.getIncomingChannels ( Plugin  plugin)

Gets a set containing all the incoming plugin channels that the specified plugin is registered for.

Parameters
pluginPlugin to retrieve channels for.
Returns
List of all registered incoming plugin channels that the plugin is registered for.
Exceptions
IllegalArgumentExceptionThrown if plugin is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 281 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.PluginMessageListenerRegistration.getChannel().

281  {
282  if (plugin == null) {
283  throw new IllegalArgumentException("Plugin cannot be null");
284  }
285 
286  synchronized (incomingLock) {
287  Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
288 
289  if (registrations != null) {
290  Builder<String> builder = ImmutableSet.builder();
291 
292  for (PluginMessageListenerRegistration registration : registrations) {
293  builder.add(registration.getChannel());
294  }
295 
296  return builder.build();
297  } else {
298  return ImmutableSet.of();
299  }
300  }
301  }
Set<String> org.bukkit.plugin.messaging.StandardMessenger.getOutgoingChannels ( )

Gets a set containing all the outgoing plugin channels.

Returns
List of all registered outgoing plugin channels.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 251 of file StandardMessenger.java.

251  {
252  synchronized (outgoingLock) {
253  Set<String> keys = outgoingByChannel.keySet();
254  return ImmutableSet.copyOf(keys);
255  }
256  }
Set<String> org.bukkit.plugin.messaging.StandardMessenger.getOutgoingChannels ( Plugin  plugin)

Gets a set containing all the outgoing plugin channels that the specified plugin is registered to.

Parameters
pluginPlugin to retrieve channels for.
Returns
List of all registered outgoing plugin channels that a plugin is registered to.
Exceptions
IllegalArgumentExceptionThrown if plugin is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 258 of file StandardMessenger.java.

258  {
259  if (plugin == null) {
260  throw new IllegalArgumentException("Plugin cannot be null");
261  }
262 
263  synchronized (outgoingLock) {
264  Set<String> channels = outgoingByPlugin.get(plugin);
265 
266  if (channels != null) {
267  return ImmutableSet.copyOf(channels);
268  } else {
269  return ImmutableSet.of();
270  }
271  }
272  }
boolean org.bukkit.plugin.messaging.StandardMessenger.isIncomingChannelRegistered ( Plugin  plugin,
String  channel 
)

Checks if the specified plugin has registered to receive incoming messages through the requested channel.

Parameters
pluginPlugin to check registration for.
channelChannel to test for.
Returns
True if the channel is registered, else false.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 374 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.PluginMessageListenerRegistration.getChannel(), and org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

374  {
375  if (plugin == null) {
376  throw new IllegalArgumentException("Plugin cannot be null");
377  }
378  validateChannel(channel);
379 
380  synchronized (incomingLock) {
381  Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
382 
383  if (registrations != null) {
384  for (PluginMessageListenerRegistration registration : registrations) {
385  if (registration.getChannel().equals(channel)) {
386  return true;
387  }
388  }
389  }
390 
391  return false;
392  }
393  }
boolean org.bukkit.plugin.messaging.StandardMessenger.isOutgoingChannelRegistered ( Plugin  plugin,
String  channel 
)

Checks if the specified plugin has registered to send outgoing messages through the requested channel.

Parameters
pluginPlugin to check registration for.
channelChannel to test for.
Returns
True if the channel is registered, else false.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 395 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

395  {
396  if (plugin == null) {
397  throw new IllegalArgumentException("Plugin cannot be null");
398  }
399  validateChannel(channel);
400 
401  synchronized (outgoingLock) {
402  Set<String> channels = outgoingByPlugin.get(plugin);
403 
404  if (channels != null) {
405  return channels.contains(channel);
406  }
407 
408  return false;
409  }
410  }
boolean org.bukkit.plugin.messaging.StandardMessenger.isRegistrationValid ( PluginMessageListenerRegistration  registration)

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
registrationRegistration to check.
Returns
True if the registration is valid, otherwise false.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 358 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.PluginMessageListenerRegistration.getPlugin().

358  {
359  if (registration == null) {
360  throw new IllegalArgumentException("Registration cannot be null");
361  }
362 
363  synchronized (incomingLock) {
364  Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(registration.getPlugin());
365 
366  if (registrations != null) {
367  return registrations.contains(registration);
368  }
369 
370  return false;
371  }
372  }
boolean org.bukkit.plugin.messaging.StandardMessenger.isReservedChannel ( String  channel)

Checks if the specified channel is a reserved name.

Parameters
channelChannel name to check.
Returns
True if the channel is reserved, otherwise false.
Exceptions
IllegalArgumentExceptionThrown if channel is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 168 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

Referenced by org.bukkit.plugin.messaging.StandardMessenger.registerIncomingPluginChannel(), and org.bukkit.plugin.messaging.StandardMessenger.registerOutgoingPluginChannel().

168  {
169  validateChannel(channel);
170 
171  return channel.equals("REGISTER") || channel.equals("UNREGISTER");
172  }
PluginMessageListenerRegistration org.bukkit.plugin.messaging.StandardMessenger.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.

Parameters
pluginPlugin that wishes to register to this channel.
channelChannel to register.
listenerListener to receive messages on.
Returns
The resulting registration that was made as a result of this method.
Exceptions
IllegalArgumentExceptionThrown if plugin, channel or listener is null, or the listener is already registered for this channel.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 203 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.StandardMessenger.isReservedChannel(), and org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

203  {
204  if (plugin == null) {
205  throw new IllegalArgumentException("Plugin cannot be null");
206  }
207  validateChannel(channel);
208  if (isReservedChannel(channel)) {
209  throw new ReservedChannelException(channel);
210  }
211  if (listener == null) {
212  throw new IllegalArgumentException("Listener cannot be null");
213  }
214 
215  PluginMessageListenerRegistration result = new PluginMessageListenerRegistration(this, plugin, channel, listener);
216 
217  addToIncoming(result);
218 
219  return result;
220  }
void org.bukkit.plugin.messaging.StandardMessenger.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.

Parameters
pluginPlugin that wishes to send messages through the channel.
channelChannel to register.
Exceptions
IllegalArgumentExceptionThrown if plugin or channel is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 174 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.StandardMessenger.isReservedChannel(), and org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

174  {
175  if (plugin == null) {
176  throw new IllegalArgumentException("Plugin cannot be null");
177  }
178  validateChannel(channel);
179  if (isReservedChannel(channel)) {
180  throw new ReservedChannelException(channel);
181  }
182 
183  addToOutgoing(plugin, channel);
184  }
void org.bukkit.plugin.messaging.StandardMessenger.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.

Parameters
pluginPlugin that wishes to unregister from this channel.
channelChannel to unregister.
listenerListener to stop receiving messages on.
Exceptions
IllegalArgumentExceptionThrown if plugin, channel or listener is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 222 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

222  {
223  if (plugin == null) {
224  throw new IllegalArgumentException("Plugin cannot be null");
225  }
226  if (listener == null) {
227  throw new IllegalArgumentException("Listener cannot be null");
228  }
229  validateChannel(channel);
230 
231  removeFromIncoming(new PluginMessageListenerRegistration(this, plugin, channel, listener));
232  }
void org.bukkit.plugin.messaging.StandardMessenger.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.

Parameters
pluginPlugin that wishes to unregister from this channel.
channelChannel to unregister.
Exceptions
IllegalArgumentExceptionThrown if plugin or channel is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 234 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

234  {
235  if (plugin == null) {
236  throw new IllegalArgumentException("Plugin cannot be null");
237  }
238  validateChannel(channel);
239 
240  removeFromIncoming(plugin, channel);
241  }
void org.bukkit.plugin.messaging.StandardMessenger.unregisterIncomingPluginChannel ( Plugin  plugin)

Unregisters the specific plugin from listening on all plugin channels through all listeners.

Parameters
pluginPlugin that wishes to unregister from this channel.
Exceptions
IllegalArgumentExceptionThrown if plugin is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 243 of file StandardMessenger.java.

243  {
244  if (plugin == null) {
245  throw new IllegalArgumentException("Plugin cannot be null");
246  }
247 
248  removeFromIncoming(plugin);
249  }
void org.bukkit.plugin.messaging.StandardMessenger.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.

Parameters
pluginPlugin that no longer wishes to send messages through the channel.
channelChannel to unregister.
Exceptions
IllegalArgumentExceptionThrown if plugin or channel is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 186 of file StandardMessenger.java.

References org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

186  {
187  if (plugin == null) {
188  throw new IllegalArgumentException("Plugin cannot be null");
189  }
190  validateChannel(channel);
191 
192  removeFromOutgoing(plugin, channel);
193  }
void org.bukkit.plugin.messaging.StandardMessenger.unregisterOutgoingPluginChannel ( Plugin  plugin)

Unregisters the specific plugin from all outgoing plugin channels, no longer allowing it to send any plugin messages.

Parameters
pluginPlugin that no longer wishes to send plugin messages.
Exceptions
IllegalArgumentExceptionThrown if plugin is null.

Implements org.bukkit.plugin.messaging.Messenger.

Definition at line 195 of file StandardMessenger.java.

195  {
196  if (plugin == null) {
197  throw new IllegalArgumentException("Plugin cannot be null");
198  }
199 
200  removeFromOutgoing(plugin);
201  }
static void org.bukkit.plugin.messaging.StandardMessenger.validatePluginMessage ( Messenger  messenger,
Plugin  source,
String  channel,
byte[]  message 
)
static

Validates the input of a Plugin Message, ensuring the arguments are all valid.

Parameters
messengerMessenger to use for validation.
sourceSource plugin of the Message.
channelPlugin Channel to send the message by.
messageRaw message payload to send.
Exceptions
IllegalArgumentExceptionThrown if the source plugin is disabled.
IllegalArgumentExceptionThrown if source, channel or message is null.
MessageTooLargeExceptionThrown if the message is too big.
ChannelNameTooLongExceptionThrown if the channel name is too long.
ChannelNotRegisteredExceptionThrown if the channel is not registered for this plugin.

Definition at line 460 of file StandardMessenger.java.

References org.bukkit.plugin.Plugin.isEnabled(), org.bukkit.plugin.messaging.Messenger.isOutgoingChannelRegistered(), org.bukkit.plugin.messaging.Messenger.MAX_MESSAGE_SIZE, and org.bukkit.plugin.messaging.StandardMessenger.validateChannel().

460  {
461  if (messenger == null) {
462  throw new IllegalArgumentException("Messenger cannot be null");
463  }
464  if (source == null) {
465  throw new IllegalArgumentException("Plugin source cannot be null");
466  }
467  if (!source.isEnabled()) {
468  throw new IllegalArgumentException("Plugin must be enabled to send messages");
469  }
470  if (message == null) {
471  throw new IllegalArgumentException("Message cannot be null");
472  }
473  if (!messenger.isOutgoingChannelRegistered(source, channel)) {
474  throw new ChannelNotRegisteredException(channel);
475  }
476  if (message.length > Messenger.MAX_MESSAGE_SIZE) {
477  throw new MessageTooLargeException(message);
478  }
479  validateChannel(channel);
480  }

The documentation for this class was generated from the following file: