Fixed bug with Portal where it continuously sent players until queue cleaned up records 15 seconds later.

This commit is contained in:
Jonathan Williams 2014-05-28 10:43:39 -07:00
parent 449fa13cc3
commit 24ccf133af

View File

@ -3,6 +3,7 @@ package mineplex.core.portal;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
@ -10,17 +11,24 @@ import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class Portal extends MiniPlugin
{
private static Object _transferLock = new Object();
private HashSet<String> _connectingPlayers = new HashSet<String>();
private PortalRepository _repository= new PortalRepository();
private List<String> _transfers = new ArrayList<String>();
private boolean _retrieve = true;
public Portal(JavaPlugin plugin)
{
super("Portal", plugin);
@ -79,30 +87,63 @@ public class Portal extends MiniPlugin
}, 20L);
}
@EventHandler
public void addTransferDelete(final PlayerQuitEvent event)
{
boolean delete = false;
synchronized (_transferLock)
{
delete = _transfers.remove(event.getPlayer().getName());
}
if (delete)
{
Bukkit.getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
_repository.deleteServerTransfers(event.getPlayer().getName());
}
});
}
}
@EventHandler
public void checkForServerTransfers(UpdateEvent event)
{
if (event.getType() != UpdateType.TWOSEC || Bukkit.getOnlinePlayers().length == 0)
_retrieve = !_retrieve;
if (event.getType() != UpdateType.SEC || Bukkit.getOnlinePlayers().length == 0)
return;
Bukkit.getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
if (_retrieve)
{
public void run()
Bukkit.getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
final List<Entry<String, String>> entries = _repository.retrieveServerTransfers();
Bukkit.getScheduler().runTask(GetPlugin(), new Runnable()
public void run()
{
public void run()
final NautHashMap<String, String> entries = _repository.retrieveServerTransfers();
synchronized (_transferLock)
{
for (Entry<String, String> entry : entries)
_transfers.addAll(entries.keySet());
}
Bukkit.getScheduler().runTask(GetPlugin(), new Runnable()
{
public void run()
{
if (GetPlugin().getServer().getPlayer(entry.getKey()) != null)
SendPlayerToServer(GetPlugin().getServer().getPlayer(entry.getKey()), entry.getValue());
for (Entry<String, String> entry : entries.entrySet())
{
if (GetPlugin().getServer().getPlayer(entry.getKey()) != null)
SendPlayerToServer(GetPlugin().getServer().getPlayer(entry.getKey()), entry.getValue());
}
}
}
});
}
});
});
}
});
}
}
}