diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java index 497492c8..9fcd8c70 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java @@ -1,12 +1,9 @@ package com.onarandombox.MultiverseCore.listeners; -import java.util.logging.Level; - -import org.bukkit.event.Listener; - import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import org.bukkit.event.Listener; /** * Multiverse's {@link org.bukkit.event.Listener} for players. @@ -33,21 +30,10 @@ public abstract class MVChatListener implements Listener { // Check whether the Server is set to prefix the chat with the World name. // If not we do nothing, if so we need to check if the World has an Alias. if (plugin.getMVConfig().getPrefixChat()) { - String world; - Thread thread = Thread.currentThread(); - if (playerListener.getWorldsLock().isLocked()) { - plugin.log(Level.FINEST, "worldsLock is locked when attempting to handle player chat on thread: " + thread); - } - playerListener.getWorldsLock().lock(); - try { - plugin.log(Level.FINEST, "Handling player chat on thread: " + thread); - world = playerListener.getPlayerWorld().get(event.getPlayer().getName()); - if (world == null) { - world = event.getPlayer().getWorld().getName(); - playerListener.getPlayerWorld().put(event.getPlayer().getName(), world); - } - } finally { - playerListener.getWorldsLock().unlock(); + String world = playerListener.getPlayerWorld().get(event.getPlayer().getName()); + if (world == null) { + world = event.getPlayer().getWorld().getName(); + playerListener.getPlayerWorld().put(event.getPlayer().getName(), world); } String prefix = ""; // If we're not a MV world, don't do anything diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index a97265af..ed8c0397 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -27,9 +27,8 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import java.util.HashMap; import java.util.Map; -import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; /** @@ -40,8 +39,7 @@ public class MVPlayerListener implements Listener { private final MVWorldManager worldManager; private final PermissionTools pt; - private final ReentrantLock worldsLock = new ReentrantLock(); - private final Map playerWorld = new HashMap(); + private final Map playerWorld = new ConcurrentHashMap(); public MVPlayerListener(MultiverseCore plugin) { this.plugin = plugin; @@ -49,13 +47,6 @@ public class MVPlayerListener implements Listener { pt = new PermissionTools(plugin); } - /** - * @return the worldsLock - */ - public ReentrantLock getWorldsLock() { - return worldsLock; - } - /** * @return the playerWorld-map */ @@ -134,17 +125,7 @@ public class MVPlayerListener implements Listener { } // Handle the Players GameMode setting for the new world. this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); - Thread thread = Thread.currentThread(); - if (worldsLock.isLocked()) { - plugin.log(Level.FINEST, "worldsLock is locked when attempting to cache player world on thread: " + thread); - } - worldsLock.lock(); - try { - plugin.log(Level.FINEST, "Caching player world on thread: " + thread); - playerWorld.put(p.getName(), p.getWorld().getName()); - } finally { - worldsLock.unlock(); - } + playerWorld.put(p.getName(), p.getWorld().getName()); } /** @@ -155,17 +136,7 @@ public class MVPlayerListener implements Listener { public void playerChangedWorld(PlayerChangedWorldEvent event) { // Permissions now determine whether or not to handle a gamemode. this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); - Thread thread = Thread.currentThread(); - if (worldsLock.isLocked()) { - plugin.log(Level.FINEST, "worldsLock is locked when attempting to cache player world on thread: " + thread); - } - worldsLock.lock(); - try { - plugin.log(Level.FINEST, "Caching player world on thread: " + thread); - playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName()); - } finally { - worldsLock.unlock(); - } + playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName()); } /** diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldProperties.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldProperties.java index 0dda072a..0db2d5f1 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldProperties.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldProperties.java @@ -345,6 +345,7 @@ public class TestWorldProperties { when(mockPlayer.getWorld()).thenReturn(mvWorld.getCBWorld()); when(mockPlayer.hasPlayedBefore()).thenReturn(true); when(mockPlayer.hasPermission("multiverse.access.world")).thenReturn(true); + when(mockPlayer.getName()).thenReturn("MultiverseMan"); playerChatEvent = PowerMockito.mock(AsyncPlayerChatEvent.class); when(playerChatEvent.getPlayer()).thenReturn(mockPlayer); when(playerChatEvent.getFormat()).thenReturn("format");