This commit is contained in:
main() 2012-08-18 14:54:18 +02:00
parent fd9464ced1
commit d0ea4168bc
5 changed files with 40 additions and 21 deletions

View File

@ -469,13 +469,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
wantedConfig = (MultiverseCoreConfiguration) multiverseConfig.get("multiverse-configuration");
} catch (Exception ignore) {
} finally {
Thread thread = Thread.currentThread();
if (configLock.isLocked()) {
//log(Level.FINER, "configLock is locked when attempting to set config variable on thread: " + thread);
}
configLock.lock();
try {
//log(Level.FINER, "Setting config on thread: " + thread);
config = ((wantedConfig == null) ? new MultiverseCoreConfiguration() : wantedConfig);
} finally {
configLock.unlock();

View File

@ -32,9 +32,9 @@ public class MVAsyncPlayerChatListener implements MVChatListener<AsyncPlayerChat
}
/**
* This method is called when a player wants to chat.
* @param event The Event that was fired.
* {@inheritDoc}
*/
@Override
@EventHandler
public void playerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) {
@ -45,19 +45,19 @@ public class MVAsyncPlayerChatListener implements MVChatListener<AsyncPlayerChat
if (plugin.getMVConfig().getPrefixChat()) {
String world;
Thread thread = Thread.currentThread();
if (playerListener.worldsLock.isLocked()) {
if (playerListener.getWorldsLock().isLocked()) {
plugin.log(Level.FINEST, "worldsLock is locked when attempting to handle player chat on thread: " + thread);
}
playerListener.worldsLock.lock();
playerListener.getWorldsLock().lock();
try {
plugin.log(Level.FINEST, "Handling player chat on thread: " + thread);
world = playerListener.playerWorld.get(event.getPlayer().getName());
world = playerListener.getPlayerWorld().get(event.getPlayer().getName());
if (world == null) {
world = event.getPlayer().getWorld().getName();
playerListener.playerWorld.put(event.getPlayer().getName(), world);
playerListener.getPlayerWorld().put(event.getPlayer().getName(), world);
}
} finally {
playerListener.worldsLock.unlock();
playerListener.getWorldsLock().unlock();
}
String prefix = "";
// If we're not a MV world, don't do anything

View File

@ -4,8 +4,15 @@ import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* This interface is implemented by {@link MVPlayerChatListener} and {@link MVAsyncPlayerChatListener}.
* @param <E> The chat event-type.
*/
public interface MVChatListener<E extends Event> extends Listener {
/**
* This method is called when a player wants to chat.
* @param event The Event that was fired.
*/
@EventHandler
public void playerChat(E event);
void playerChat(E event);
}

View File

@ -35,6 +35,7 @@ public class MVPlayerChatListener implements MVChatListener<PlayerChatEvent> {
* This method is called when a player wants to chat.
* @param event The Event that was fired.
*/
@Override
@EventHandler
public void playerChat(PlayerChatEvent event) {
if (event.isCancelled()) {
@ -45,19 +46,19 @@ public class MVPlayerChatListener implements MVChatListener<PlayerChatEvent> {
if (plugin.getMVConfig().getPrefixChat()) {
String world;
Thread thread = Thread.currentThread();
if (playerListener.worldsLock.isLocked()) {
if (playerListener.getWorldsLock().isLocked()) {
plugin.log(Level.FINEST, "worldsLock is locked when attempting to handle player chat on thread: " + thread);
}
playerListener.worldsLock.lock();
playerListener.getWorldsLock().lock();
try {
plugin.log(Level.FINEST, "Handling player chat on thread: " + thread);
world = playerListener.playerWorld.get(event.getPlayer().getName());
world = playerListener.getPlayerWorld().get(event.getPlayer().getName());
if (world == null) {
world = event.getPlayer().getWorld().getName();
playerListener.playerWorld.put(event.getPlayer().getName(), world);
playerListener.getPlayerWorld().put(event.getPlayer().getName(), world);
}
} finally {
playerListener.worldsLock.unlock();
playerListener.getWorldsLock().unlock();
}
String prefix = "";
// If we're not a MV world, don't do anything

View File

@ -40,8 +40,8 @@ public class MVPlayerListener implements Listener {
private final MVWorldManager worldManager;
private final PermissionTools pt;
final ReentrantLock worldsLock = new ReentrantLock();
final Map<String, String> playerWorld = new HashMap<String, String>();
private final ReentrantLock worldsLock = new ReentrantLock();
private final Map<String, String> playerWorld = new HashMap<String, String>();
public MVPlayerListener(MultiverseCore plugin) {
this.plugin = plugin;
@ -49,6 +49,20 @@ public class MVPlayerListener implements Listener {
pt = new PermissionTools(plugin);
}
/**
* @return the worldsLock
*/
public ReentrantLock getWorldsLock() {
return worldsLock;
}
/**
* @return the playerWorld-map
*/
public Map<String, String> getPlayerWorld() {
return playerWorld;
}
/**
* This method is called when a player respawns.
* @param event The Event that was fired.
@ -299,6 +313,7 @@ public class MVPlayerListener implements Listener {
// Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation());
}
@ -328,6 +343,7 @@ public class MVPlayerListener implements Listener {
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
if (player.getWorld() == world.getCBWorld()) {