diff options
author | snowleo <schneeleo@gmail.com> | 2012-08-04 10:48:56 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2012-08-04 10:48:56 +0200 |
commit | bf93bb2026e1d3474be88759e72b144e218387db (patch) | |
tree | 1de997645499c96ec4e369c71f8f08254ac737bd /EssentialsXMPP | |
parent | af73c11638fda0c65fa68506d301b2a68b780bf6 (diff) | |
download | Essentials-bf93bb2026e1d3474be88759e72b144e218387db.tar Essentials-bf93bb2026e1d3474be88759e72b144e218387db.tar.gz Essentials-bf93bb2026e1d3474be88759e72b144e218387db.tar.lz Essentials-bf93bb2026e1d3474be88759e72b144e218387db.tar.xz Essentials-bf93bb2026e1d3474be88759e72b144e218387db.zip |
Thread safety for XMPP
Diffstat (limited to 'EssentialsXMPP')
-rw-r--r-- | EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java | 15 | ||||
-rw-r--r-- | EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java | 2 |
2 files changed, 11 insertions, 6 deletions
diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java index 468a7ec4e..17827c3c7 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.xmpp; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; +import java.util.List; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -20,21 +21,21 @@ class EssentialsXMPPPlayerListener implements Listener this.ess = ess; } - @EventHandler(priority= EventPriority.MONITOR) + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(final PlayerJoinEvent event) { final User user = ess.getUser(event.getPlayer()); sendMessageToSpyUsers("Player " + user.getDisplayName() + " joined the game"); } - @EventHandler(priority= EventPriority.MONITOR) + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerChat(final AsyncPlayerChatEvent event) { final User user = ess.getUser(event.getPlayer()); sendMessageToSpyUsers(String.format(event.getFormat(), user.getDisplayName(), event.getMessage())); } - @EventHandler(priority= EventPriority.MONITOR) + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(final PlayerQuitEvent event) { final User user = ess.getUser(event.getPlayer()); @@ -45,9 +46,13 @@ class EssentialsXMPPPlayerListener implements Listener { try { - for (String address : EssentialsXMPP.getInstance().getSpyUsers()) + List<String> users = EssentialsXMPP.getInstance().getSpyUsers(); + synchronized (users) { - EssentialsXMPP.getInstance().sendMessage(address, message); + for (String address : users) + { + EssentialsXMPP.getInstance().sendMessage(address, message); + } } } catch (Exception ex) diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java index a35312129..6439c9b9d 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java @@ -9,7 +9,7 @@ import java.util.*; public class UserManager implements IConf { private final transient EssentialsConf users; - private final transient List<String> spyusers = new ArrayList<String>(); + private final transient List<String> spyusers = Collections.synchronizedList(new ArrayList<String>()); private final static String ADDRESS = "address"; private final static String SPY = "spy"; |