Commits
md_5 authored adb9f8b5c25
1 1 | package org.bukkit.plugin.messaging; |
2 2 | |
3 3 | import com.google.common.collect.ImmutableSet; |
4 4 | import com.google.common.collect.ImmutableSet.Builder; |
5 5 | import java.util.HashMap; |
6 6 | import java.util.HashSet; |
7 7 | import java.util.Map; |
8 8 | import java.util.Set; |
9 + | import java.util.logging.Level; |
9 10 | import org.bukkit.entity.Player; |
10 11 | import org.bukkit.plugin.Plugin; |
11 12 | |
12 13 | /** |
13 14 | * Standard implementation to {@link Messenger} |
14 15 | */ |
15 16 | public class StandardMessenger implements Messenger { |
16 17 | private final Map<String, Set<PluginMessageListenerRegistration>> incomingByChannel = new HashMap<String, Set<PluginMessageListenerRegistration>>(); |
17 18 | private final Map<Plugin, Set<PluginMessageListenerRegistration>> incomingByPlugin = new HashMap<Plugin, Set<PluginMessageListenerRegistration>>(); |
18 19 | private final Map<String, Set<Plugin>> outgoingByChannel = new HashMap<String, Set<Plugin>>(); |
414 415 | throw new IllegalArgumentException("Player source cannot be null"); |
415 416 | } |
416 417 | if (message == null) { |
417 418 | throw new IllegalArgumentException("Message cannot be null"); |
418 419 | } |
419 420 | validateChannel(channel); |
420 421 | |
421 422 | Set<PluginMessageListenerRegistration> registrations = getIncomingChannelRegistrations(channel); |
422 423 | |
423 424 | for (PluginMessageListenerRegistration registration : registrations) { |
424 - | registration.getListener().onPluginMessageReceived(channel, source, message); |
425 + | try { |
426 + | registration.getListener().onPluginMessageReceived(channel, source, message); |
427 + | } catch (Throwable t) { |
428 + | registration.getPlugin().getLogger().log(Level.WARNING, |
429 + | String.format("Plugin %s generated an exception whilst handling plugin message", |
430 + | registration.getPlugin().getDescription().getFullName() |
431 + | ), t); |
432 + | } |
425 433 | } |
426 434 | } |
427 435 | |
428 436 | /** |
429 437 | * Validates a Plugin Channel name. |
430 438 | * |
431 439 | * @param channel Channel name to validate. |
432 440 | */ |
433 441 | public static void validateChannel(String channel) { |
434 442 | if (channel == null) { |