Only dispose users who are offline at point of disposal.

This should cater for quick reconnects on lagged servers.
This commit is contained in:
KHobbits 2014-05-10 15:36:58 +01:00
parent f09180659d
commit b00c31730f
2 changed files with 64 additions and 59 deletions

View File

@ -37,25 +37,25 @@ public class EssentialsPlayerListener implements Listener
{ {
private static final Logger LOGGER = Logger.getLogger("Essentials"); private static final Logger LOGGER = Logger.getLogger("Essentials");
private final transient IEssentials ess; private final transient IEssentials ess;
public EssentialsPlayerListener(final IEssentials parent) public EssentialsPlayerListener(final IEssentials parent)
{ {
this.ess = parent; this.ess = parent;
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerRespawn(final PlayerRespawnEvent event) public void onPlayerRespawn(final PlayerRespawnEvent event)
{ {
final User user = ess.getUser(event.getPlayer()); final User user = ess.getUser(event.getPlayer());
updateCompass(user); updateCompass(user);
user.setDisplayNick(); user.setDisplayNick();
if (ess.getSettings().isTeleportInvulnerability()) if (ess.getSettings().isTeleportInvulnerability())
{ {
user.enableInvulnerabilityAfterTeleport(); user.enableInvulnerabilityAfterTeleport();
} }
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(final AsyncPlayerChatEvent event) public void onPlayerChat(final AsyncPlayerChatEvent event)
{ {
@ -89,11 +89,11 @@ public class EssentialsPlayerListener implements Listener
ess.getLogger().info("Ignore could not block chat due to custom chat plugin event."); ess.getLogger().info("Ignore could not block chat due to custom chat plugin event.");
} }
} }
user.updateActivity(true); user.updateActivity(true);
user.setDisplayNick(); user.setDisplayNick();
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent event) public void onPlayerMove(final PlayerMoveEvent event)
{ {
@ -103,19 +103,19 @@ public class EssentialsPlayerListener implements Listener
{ {
return; return;
} }
if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers()) if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers())
{ {
event.getHandlers().unregister(this); event.getHandlers().unregister(this);
if (ess.getSettings().isDebug()) if (ess.getSettings().isDebug())
{ {
LOGGER.log(Level.INFO, "Unregistering move listener"); LOGGER.log(Level.INFO, "Unregistering move listener");
} }
return; return;
} }
final User user = ess.getUser(event.getPlayer()); final User user = ess.getUser(event.getPlayer());
if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers())
{ {
@ -146,12 +146,12 @@ public class EssentialsPlayerListener implements Listener
user.updateActivity(true); user.updateActivity(true);
} }
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerQuit(final PlayerQuitEvent event) public void onPlayerQuit(final PlayerQuitEvent event)
{ {
final User user = ess.getUser(event.getPlayer()); final User user = ess.getUser(event.getPlayer());
if (ess.getSettings().allowSilentJoinQuit() && user.isAuthorized("essentials.silentquit")) if (ess.getSettings().allowSilentJoinQuit() && user.isAuthorized("essentials.silentquit"))
{ {
event.setQuitMessage(null); event.setQuitMessage(null);
@ -164,7 +164,7 @@ public class EssentialsPlayerListener implements Listener
.replace("{PLAYER}", player.getDisplayName()) .replace("{PLAYER}", player.getDisplayName())
.replace("{USERNAME}", player.getName())); .replace("{USERNAME}", player.getName()));
} }
if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled())
{ {
user.setGodModeEnabled(false); user.setGodModeEnabled(false);
@ -181,7 +181,7 @@ public class EssentialsPlayerListener implements Listener
user.updateActivity(false); user.updateActivity(false);
user.dispose(); user.dispose();
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(final PlayerJoinEvent event) public void onPlayerJoin(final PlayerJoinEvent event)
{ {
@ -199,42 +199,44 @@ public class EssentialsPlayerListener implements Listener
event.setJoinMessage(null); event.setJoinMessage(null);
} }
} }
public void delayedJoin(final Player player, final String message) public void delayedJoin(final Player player, final String message)
{ {
if (!player.isOnline()) if (!player.isOnline())
{ {
return; return;
} }
ess.getBackup().onPlayerJoin(); ess.getBackup().onPlayerJoin();
final User user = ess.getUser(player); final User dUser = ess.getUser(player);
if (user.isNPC()) if (dUser.isNPC())
{ {
user.setNPC(false); dUser.setNPC(false);
} }
final long currentTime = System.currentTimeMillis(); final long currentTime = System.currentTimeMillis();
user.checkMuteTimeout(currentTime); dUser.checkMuteTimeout(currentTime);
user.updateActivity(false); dUser.updateActivity(false);
ess.scheduleSyncDelayedTask(new Runnable() ess.scheduleSyncDelayedTask(new Runnable()
{ {
@Override @Override
public void run() public void run()
{ {
final User user = ess.getUser(player);
if (!user.getBase().isOnline()) if (!user.getBase().isOnline())
{ {
return; return;
} }
user.setLastAccountName(user.getBase().getName()); user.setLastAccountName(user.getBase().getName());
user.setLastLogin(currentTime); user.setLastLogin(currentTime);
user.setDisplayNick(); user.setDisplayNick();
updateCompass(user); updateCompass(user);
if (!ess.getVanishedPlayers().isEmpty() && !user.isAuthorized("essentials.vanish.see")) if (!ess.getVanishedPlayers().isEmpty() && !user.isAuthorized("essentials.vanish.see"))
{ {
for (String p : ess.getVanishedPlayers()) for (String p : ess.getVanishedPlayers())
@ -246,12 +248,12 @@ public class EssentialsPlayerListener implements Listener
} }
} }
} }
if (user.isAuthorized("essentials.sleepingignored")) if (user.isAuthorized("essentials.sleepingignored"))
{ {
user.getBase().setSleepingIgnored(true); user.getBase().setSleepingIgnored(true);
} }
if ((ess.getSettings().allowSilentJoinQuit() && user.isAuthorized("essentials.silentjoin")) || message == null) if ((ess.getSettings().allowSilentJoinQuit() && user.isAuthorized("essentials.silentjoin")) || message == null)
{ {
// Do nothing - silently join // Do nothing - silently join
@ -267,7 +269,7 @@ public class EssentialsPlayerListener implements Listener
{ {
ess.getServer().broadcastMessage(message); ess.getServer().broadcastMessage(message);
} }
if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd")) if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
{ {
try try
@ -289,7 +291,7 @@ public class EssentialsPlayerListener implements Listener
} }
} }
} }
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
{ {
final List<String> mail = user.getMails(); final List<String> mail = user.getMails();
@ -302,7 +304,7 @@ public class EssentialsPlayerListener implements Listener
user.sendMessage(tl("youHaveNewMail", mail.size())); user.sendMessage(tl("youHaveNewMail", mail.size()));
} }
} }
if (user.isAuthorized("essentials.fly.safelogin")) if (user.isAuthorized("essentials.fly.safelogin"))
{ {
user.getBase().setFallDistance(0); user.getBase().setFallDistance(0);
@ -311,11 +313,11 @@ public class EssentialsPlayerListener implements Listener
user.getBase().setAllowFlight(true); user.getBase().setAllowFlight(true);
user.getBase().setFlying(true); user.getBase().setFlying(true);
user.getBase().sendMessage(tl("flyMode", tl("enabled"), user.getDisplayName())); user.getBase().sendMessage(tl("flyMode", tl("enabled"), user.getDisplayName()));
} }
} }
user.getBase().setFlySpeed(0.1f); user.getBase().setFlySpeed(0.1f);
user.getBase().setWalkSpeed(0.2f); user.getBase().setWalkSpeed(0.2f);
} }
}); });
} }
@ -334,7 +336,7 @@ public class EssentialsPlayerListener implements Listener
user.getBase().setCompassTarget(updateLoc); user.getBase().setCompassTarget(updateLoc);
} }
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerLogin2(final PlayerLoginEvent event) public void onPlayerLogin2(final PlayerLoginEvent event)
{ {
@ -345,11 +347,11 @@ public class EssentialsPlayerListener implements Listener
default: default:
return; return;
} }
final String banReason = tl("banFormat", tl("defaultBanReason"), "Console"); final String banReason = tl("banFormat", tl("defaultBanReason"), "Console");
event.disallow(Result.KICK_BANNED, banReason); event.disallow(Result.KICK_BANNED, banReason);
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerLogin(final PlayerLoginEvent event) public void onPlayerLogin(final PlayerLoginEvent event)
{ {
@ -361,9 +363,9 @@ public class EssentialsPlayerListener implements Listener
default: default:
return; return;
} }
final User user = ess.getUser(event.getPlayer()); final User user = ess.getUser(event.getPlayer());
if (event.getResult() == Result.KICK_BANNED || user.getBase().isBanned()) if (event.getResult() == Result.KICK_BANNED || user.getBase().isBanned())
{ {
final boolean banExpired = user.checkBanTimeout(System.currentTimeMillis()); final boolean banExpired = user.checkBanTimeout(System.currentTimeMillis());
@ -383,7 +385,7 @@ public class EssentialsPlayerListener implements Listener
return; return;
} }
} }
if (event.getResult() == Result.KICK_FULL && !user.isAuthorized("essentials.joinfullserver")) if (event.getResult() == Result.KICK_FULL && !user.isAuthorized("essentials.joinfullserver"))
{ {
event.disallow(Result.KICK_FULL, tl("serverFull")); event.disallow(Result.KICK_FULL, tl("serverFull"));
@ -391,7 +393,7 @@ public class EssentialsPlayerListener implements Listener
} }
event.allow(); event.allow();
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event) public void onPlayerTeleport(final PlayerTeleportEvent event)
{ {
@ -411,7 +413,7 @@ public class EssentialsPlayerListener implements Listener
} }
} }
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerEggThrow(final PlayerEggThrowEvent event) public void onPlayerEggThrow(final PlayerEggThrowEvent event)
{ {
@ -423,7 +425,7 @@ public class EssentialsPlayerListener implements Listener
user.getBase().updateInventory(); user.getBase().updateInventory();
} }
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event) public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event)
{ {
@ -441,7 +443,7 @@ public class EssentialsPlayerListener implements Listener
}); });
} }
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
{ {
@ -464,7 +466,7 @@ public class EssentialsPlayerListener implements Listener
user.updateActivity(true); user.updateActivity(true);
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerChangedWorldFlyReset(final PlayerChangedWorldEvent event) public void onPlayerChangedWorldFlyReset(final PlayerChangedWorldEvent event)
{ {
@ -489,7 +491,7 @@ public class EssentialsPlayerListener implements Listener
{ {
user.getBase().setFlySpeed(user.getBase().getFlySpeed() * 0.99999f); user.getBase().setFlySpeed(user.getBase().getFlySpeed() * 0.99999f);
} }
if (user.getBase().getWalkSpeed() > ess.getSettings().getMaxWalkSpeed() && !user.isAuthorized("essentials.speed.bypass")) if (user.getBase().getWalkSpeed() > ess.getSettings().getMaxWalkSpeed() && !user.isAuthorized("essentials.speed.bypass"))
{ {
user.getBase().setWalkSpeed((float)ess.getSettings().getMaxWalkSpeed()); user.getBase().setWalkSpeed((float)ess.getSettings().getMaxWalkSpeed());
@ -500,7 +502,7 @@ public class EssentialsPlayerListener implements Listener
} }
} }
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) public void onPlayerChangedWorld(final PlayerChangedWorldEvent event)
{ {
@ -512,7 +514,7 @@ public class EssentialsPlayerListener implements Listener
{ {
user.sendMessage(tl("noGodWorldWarning")); user.sendMessage(tl("noGodWorldWarning"));
} }
if (!user.getWorld().getName().equals(newWorld)) if (!user.getWorld().getName().equals(newWorld))
{ {
user.sendMessage(tl("currentWorld", newWorld)); user.sendMessage(tl("currentWorld", newWorld));
@ -522,7 +524,7 @@ public class EssentialsPlayerListener implements Listener
user.setVanished(user.isAuthorized("essentials.vanish")); user.setVanished(user.isAuthorized("essentials.vanish"));
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteract(final PlayerInteractEvent event) public void onPlayerInteract(final PlayerInteractEvent event)
{ {
@ -571,7 +573,7 @@ public class EssentialsPlayerListener implements Listener
try try
{ {
final Location otarget = LocationUtil.getTarget(user.getBase()); final Location otarget = LocationUtil.getTarget(user.getBase());
ess.scheduleSyncDelayedTask( ess.scheduleSyncDelayedTask(
new Runnable() new Runnable()
{ {
@ -597,7 +599,7 @@ public class EssentialsPlayerListener implements Listener
} }
} }
} }
private boolean usePowertools(final User user, final int id) private boolean usePowertools(final User user, final int id)
{ {
final List<String> commandList = user.getPowertool(id); final List<String> commandList = user.getPowertool(id);
@ -635,7 +637,7 @@ public class EssentialsPlayerListener implements Listener
} }
return used; return used;
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerPickupItem(final PlayerPickupItemEvent event) public void onPlayerPickupItem(final PlayerPickupItemEvent event)
{ {
@ -647,14 +649,14 @@ public class EssentialsPlayerListener implements Listener
} }
} }
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClickEvent(final InventoryClickEvent event) public void onInventoryClickEvent(final InventoryClickEvent event)
{ {
Player refreshPlayer = null; Player refreshPlayer = null;
final Inventory top = event.getView().getTopInventory(); final Inventory top = event.getView().getTopInventory();
final InventoryType type = top.getType(); final InventoryType type = top.getType();
if (type == InventoryType.PLAYER) if (type == InventoryType.PLAYER)
{ {
final User user = ess.getUser((Player)event.getWhoClicked()); final User user = ess.getUser((Player)event.getWhoClicked());
@ -699,7 +701,7 @@ public class EssentialsPlayerListener implements Listener
refreshPlayer = user.getBase(); refreshPlayer = user.getBase();
} }
} }
if (refreshPlayer != null) if (refreshPlayer != null)
{ {
final Player player = refreshPlayer; final Player player = refreshPlayer;
@ -713,7 +715,7 @@ public class EssentialsPlayerListener implements Listener
}, 1); }, 1);
} }
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onInventoryCloseEvent(final InventoryCloseEvent event) public void onInventoryCloseEvent(final InventoryCloseEvent event)
{ {
@ -752,7 +754,7 @@ public class EssentialsPlayerListener implements Listener
refreshPlayer = user.getBase(); refreshPlayer = user.getBase();
} }
} }
if (refreshPlayer != null) if (refreshPlayer != null)
{ {
final Player player = refreshPlayer; final Player player = refreshPlayer;
@ -766,7 +768,7 @@ public class EssentialsPlayerListener implements Listener
}, 1); }, 1);
} }
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerFishEvent(final PlayerFishEvent event) public void onPlayerFishEvent(final PlayerFishEvent event)
{ {

View File

@ -237,7 +237,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
private void _dispose() private void _dispose()
{ {
this.base = new OfflinePlayer(base.getUniqueId(), ess.getServer()); if (!base.isOnline())
{
this.base = new OfflinePlayer(base.getUniqueId(), ess.getServer());
}
} }
@Override @Override