From 5379b3955f46b4551a4054930c8b79ce499b41c2 Mon Sep 17 00:00:00 2001 From: snowleo Date: Sat, 4 Aug 2012 11:10:57 +0200 Subject: [PATCH] More thread safety --- .../essentials/chat/EssentialsChatPlayer.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java index 8ca16fbbb..9dce1169c 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -44,11 +44,14 @@ public abstract class EssentialsChatPlayer implements Listener { return true; } - for (IEssentialsChatListener listener : listeners.values()) + synchronized (listeners) { - if (listener.shouldHandleThisChat(event)) + for (IEssentialsChatListener listener : listeners.values()) { - return true; + if (listener.shouldHandleThisChat(event)) + { + return true; + } } } return false; @@ -155,9 +158,12 @@ public abstract class EssentialsChatPlayer implements Listener } String message = String.format(event.getFormat(), type.concat(sender.getDisplayName()), event.getMessage()); - for (IEssentialsChatListener listener : listeners.values()) + synchronized (listeners) { - message = listener.modifyMessage(event, onlinePlayer, message); + for (IEssentialsChatListener listener : listeners.values()) + { + message = listener.modifyMessage(event, onlinePlayer, message); + } } onlineUser.sendMessage(message); }