Move player loading and updates to new thread, to reduce on join lag.

This commit is contained in:
KHobbits 2012-04-06 19:19:08 +01:00
parent 6504c88bf7
commit 9e86681722

View file

@ -122,15 +122,26 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(final PlayerJoinEvent event)
{
ess.scheduleAsyncDelayedTask(new Runnable()
{
@Override
public void run()
{
delayedJoin(event.getPlayer());
}
});
}
public void delayedJoin(final Player player)
{
ess.getBackup().onPlayerJoin();
final User user = ess.getUser(event.getPlayer());
final User user = ess.getUser(player);
user.setDisplayNick();
user.setLastLogin(System.currentTimeMillis());
user.updateActivity(false);
updateCompass(user);
user.setLastLogin(System.currentTimeMillis());
user.updateActivity(false);
if (user.isAuthorized("essentials.sleepingignored"))
{
user.setSleepingIgnored(true);
@ -172,6 +183,27 @@ public class EssentialsPlayerListener implements Listener
}
}
private void updateCompass(final User user)
{
Location loc = user.getHome(user.getLocation());
if (loc == null)
{
loc = user.getBedSpawnLocation();
}
if (loc != null)
{
final Location updateLoc = loc;
ess.scheduleSyncDelayedTask(new Runnable()
{
@Override
public void run()
{
user.setCompassTarget(updateLoc);
}
});
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerLogin(final PlayerLoginEvent event)
{
@ -211,19 +243,6 @@ public class EssentialsPlayerListener implements Listener
event.allow();
}
private void updateCompass(final User user)
{
Location loc = user.getHome(user.getLocation());
if (loc == null)
{
loc = user.getBedSpawnLocation();
}
if (loc != null)
{
user.setCompassTarget(loc);
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event)
{