From 82c33abafbc293604f3b41f43624b9a423b59fdd Mon Sep 17 00:00:00 2001 From: 502647092 Date: Fri, 1 Jul 2016 15:24:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=8E=A9=E5=AE=B6=E9=80=80=E5=87=BA?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E4=BF=AE=E5=A4=8DNPE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../AuthMe/process/quit/AsyncronousQuit.java | 133 +++++++++--------- 1 file changed, 69 insertions(+), 64 deletions(-) diff --git a/src/main/java/cn/citycraft/AuthMe/process/quit/AsyncronousQuit.java b/src/main/java/cn/citycraft/AuthMe/process/quit/AsyncronousQuit.java index e7cc5df..15deba7 100644 --- a/src/main/java/cn/citycraft/AuthMe/process/quit/AsyncronousQuit.java +++ b/src/main/java/cn/citycraft/AuthMe/process/quit/AsyncronousQuit.java @@ -17,76 +17,81 @@ import cn.citycraft.AuthMe.settings.Settings; public class AsyncronousQuit { - private boolean isFlying = false; - private boolean isKick = false; - private boolean isOp = false; - private String name; - private boolean needToChange = false; - protected DataSource database; - protected Player player; - protected AuthMe plugin; + private boolean isFlying = false; + private boolean isKick = false; + private boolean isOp = false; + private final String name; + private boolean needToChange = false; + protected DataSource database; + protected Player player; + protected AuthMe plugin; - public AsyncronousQuit(Player p, AuthMe plugin, DataSource database, boolean isKick) { - this.player = p; - this.plugin = plugin; - this.database = database; - this.name = p.getName().toLowerCase(); - this.isKick = isKick; - } + public AsyncronousQuit(final Player p, final AuthMe plugin, final DataSource database, final boolean isKick) { + this.player = p; + this.plugin = plugin; + this.database = database; + this.name = p.getName().toLowerCase(); + this.isKick = isKick; + } - public void process() { - if (player == null) - return; - if (Utils.isNPC(player) || Utils.isUnrestricted(player)) { - return; - } + public void process() { + if (player == null) { + return; + } + if (Utils.isNPC(player) || Utils.isUnrestricted(player)) { + return; + } - String ip = plugin.getIP(player); + final String ip = plugin.getIP(player); - if (PlayerCache.getInstance().isAuthenticated(name)) { - if (Settings.isSaveQuitLocationEnabled && database.isAuthAvailable(name)) { - Location loc = player.getLocation(); - PlayerAuth auth = new PlayerAuth(name, loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName(), player.getName()); - database.updateQuitLoc(auth); - } - PlayerAuth auth = new PlayerAuth(name, ip, System.currentTimeMillis(), player.getName()); - database.updateSession(auth); - } + if (PlayerCache.getInstance().isAuthenticated(name)) { + if (Settings.isSaveQuitLocationEnabled && database.isAuthAvailable(name)) { + final Location loc = player.getLocation(); + final PlayerAuth auth = new PlayerAuth(name, loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName(), player.getName()); + database.updateQuitLoc(auth); + } + final PlayerAuth auth = new PlayerAuth(name, ip, System.currentTimeMillis(), player.getName()); + database.updateSession(auth); + } - if (LimboCache.getInstance().hasLimboPlayer(name)) { - LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); - if (limbo.getGroup() != null && !limbo.getGroup().equals("")) - Utils.addNormal(player, limbo.getGroup()); - needToChange = true; - isOp = limbo.getOperator(); - isFlying = limbo.isFlying(); - if (limbo.getTimeoutTaskId() != null) - limbo.getTimeoutTaskId().cancel(); - if (limbo.getMessageTaskId() != null) - limbo.getMessageTaskId().cancel(); - LimboCache.getInstance().deleteLimboPlayer(name); - } - if (Settings.isSessionsEnabled && !isKick) { - if (Settings.getSessionTimeout != 0) { - BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { + if (LimboCache.getInstance().hasLimboPlayer(name)) { + final LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); + if (limbo.getGroup() != null && !"".equals(limbo.getGroup())) { + Utils.addNormal(player, limbo.getGroup()); + } + needToChange = true; + isOp = limbo.getOperator(); + isFlying = limbo.isFlying(); + if (limbo.getTimeoutTaskId() != null) { + limbo.getTimeoutTaskId().cancel(); + } + if (limbo.getMessageTaskId() != null) { + limbo.getMessageTaskId().cancel(); + } + LimboCache.getInstance().deleteLimboPlayer(name); + } + if (Settings.isSessionsEnabled && !isKick) { + if (Settings.getSessionTimeout != 0) { + final BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { - @Override - public void run() { - PlayerCache.getInstance().removePlayer(name); - if (database.isLogged(name)) - database.setUnlogged(name); - plugin.sessions.remove(name); - } + @Override + public void run() { + PlayerCache.getInstance().removePlayer(name); + if (database.isLogged(name)) { + database.setUnlogged(name); + } + plugin.sessions.remove(name); + } - }, Settings.getSessionTimeout * 20 * 60); - plugin.sessions.put(name, task); - } - } else { - PlayerCache.getInstance().removePlayer(name); - database.setUnlogged(name); - } + }, Settings.getSessionTimeout * 20 * 60); + plugin.sessions.put(name, task); + } + } else { + PlayerCache.getInstance().removePlayer(name); + database.setUnlogged(name); + } - AuthMePlayerListener.gameMode.remove(name); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, isOp, isFlying, needToChange)); - } + AuthMePlayerListener.gameMode.remove(name); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, isOp, isFlying, needToChange)); + } }