From e9308bb231a2a0efcbf9f4be25fc32217dc8d2a1 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Wed, 15 Jul 2015 18:21:06 +0200 Subject: [PATCH] Fix Inventory Loss + Timeout timings --- .../xephi/authme/commands/AdminCommand.java | 20 +++++---- .../authme/commands/UnregisterCommand.java | 2 +- .../authme/process/join/AsyncronousJoin.java | 2 +- .../logout/ProcessSyncronousPlayerLogout.java | 2 +- .../ProcessSyncronousEmailRegister.java | 2 +- .../ProcessSyncronousPasswordRegister.java | 2 +- .../fr/xephi/authme/task/TimeoutTask.java | 45 +++++-------------- 7 files changed, 26 insertions(+), 49 deletions(-) diff --git a/src/main/java/fr/xephi/authme/commands/AdminCommand.java b/src/main/java/fr/xephi/authme/commands/AdminCommand.java index 7a56ca194..bce507722 100644 --- a/src/main/java/fr/xephi/authme/commands/AdminCommand.java +++ b/src/main/java/fr/xephi/authme/commands/AdminCommand.java @@ -176,7 +176,7 @@ public class AdminCommand implements CommandExecutor { return true; } if (auth == null) { - m.send(sender, "user_unknown"); + m.send(sender, "user_unknown"); return true; } long lastLogin = auth.getLastLogin(); @@ -362,9 +362,9 @@ public class AdminCommand implements CommandExecutor { if (sender instanceof Player) { if (Spawn.getInstance().setSpawn(((Player) sender).getLocation())) { sender.sendMessage("[AuthMe] Correctly defined new spawn point"); - } else { + } else { sender.sendMessage("[AuthMe] SetSpawn has failed, please retry"); - } + } } else { sender.sendMessage("[AuthMe] Please use that command in game"); } @@ -427,7 +427,8 @@ public class AdminCommand implements CommandExecutor { ConsoleLogger.showError(ex.getMessage()); } return true; - } else if (args[0].equalsIgnoreCase("changepassword") || args[0].equalsIgnoreCase("cp")) { + } else + if (args[0].equalsIgnoreCase("changepassword") || args[0].equalsIgnoreCase("cp")) { if (args.length != 3) { sender.sendMessage("Usage: /authme changepassword "); return true; @@ -512,7 +513,7 @@ public class AdminCommand implements CommandExecutor { int interval = Settings.getWarnMessageInterval; BukkitScheduler sched = sender.getServer().getScheduler(); if (delay != 0) { - BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name), delay); + BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, target), delay); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval))); @@ -528,7 +529,8 @@ public class AdminCommand implements CommandExecutor { m.send(sender, "unregistered"); ConsoleLogger.info(args[1] + " unregistered"); return true; - } else if (args[0].equalsIgnoreCase("purgelastpos") || args[0].equalsIgnoreCase("resetposition")) { + } else + if (args[0].equalsIgnoreCase("purgelastpos") || args[0].equalsIgnoreCase("resetposition")) { if (args.length != 2) { sender.sendMessage("Usage: /authme purgelastpos "); return true; @@ -581,9 +583,9 @@ public class AdminCommand implements CommandExecutor { sender.sendMessage("Usage: /authme getip "); return true; } - sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress() + ":" + player.getAddress().getPort()); - sender.sendMessage(player.getName() + "'s real IP is : " + plugin.getIP(player)); - return true; + sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress() + ":" + player.getAddress().getPort()); + sender.sendMessage(player.getName() + "'s real IP is : " + plugin.getIP(player)); + return true; } else if (args[0].equalsIgnoreCase("forcelogin")) { if (args.length < 2) { sender.sendMessage("Usage: /authme forcelogin "); diff --git a/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java index dd1a94e94..1361656d6 100644 --- a/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java @@ -88,7 +88,7 @@ public class UnregisterCommand implements CommandExecutor { int interval = Settings.getWarnMessageInterval; BukkitScheduler sched = sender.getServer().getScheduler(); if (delay != 0) { - BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name), delay); + BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval))); diff --git a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java index 12e3f3f7d..cf0fa83a2 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java @@ -200,7 +200,7 @@ public class AsyncronousJoin { int time = Settings.getRegistrationTimeout * 20; int msgInterval = Settings.getWarnMessageInterval; if (time != 0) { - BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name), time); + BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), time); if (!LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().addLimboPlayer(player); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); diff --git a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java index 29077488f..f926c6949 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java @@ -38,7 +38,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable { int interval = Settings.getWarnMessageInterval; BukkitScheduler sched = player.getServer().getScheduler(); if (delay != 0) { - BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name), delay); + BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval)); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java index f90a506d9..e7510eae0 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java @@ -36,7 +36,7 @@ public class ProcessSyncronousEmailRegister implements Runnable { int msgInterval = Settings.getWarnMessageInterval; if (time != 0) { LimboCache.getInstance().getLimboPlayer(name).getTimeoutTaskId().cancel(); - BukkitTask id = Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name), time); + BukkitTask id = Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), time); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java index c85988e46..7a7b41e1b 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java @@ -67,7 +67,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable { int interval = Settings.getWarnMessageInterval; BukkitScheduler sched = plugin.getServer().getScheduler(); if (delay != 0) { - BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name), delay); + BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval)); diff --git a/src/main/java/fr/xephi/authme/task/TimeoutTask.java b/src/main/java/fr/xephi/authme/task/TimeoutTask.java index 1c1c1f692..f31e21a79 100644 --- a/src/main/java/fr/xephi/authme/task/TimeoutTask.java +++ b/src/main/java/fr/xephi/authme/task/TimeoutTask.java @@ -5,11 +5,8 @@ import org.bukkit.GameMode; import org.bukkit.entity.Player; import fr.xephi.authme.AuthMe; -import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.backup.FileCache; -import fr.xephi.authme.cache.limbo.LimboCache; -import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.settings.Messages; @@ -19,10 +16,12 @@ public class TimeoutTask implements Runnable { private String name; private Messages m = Messages.getInstance(); private FileCache playerCache; + private Player player; - public TimeoutTask(AuthMe plugin, String name) { + public TimeoutTask(AuthMe plugin, String name, Player player) { this.plugin = plugin; this.name = name; + this.player = player; this.playerCache = new FileCache(plugin); } @@ -35,38 +34,14 @@ public class TimeoutTask implements Runnable { if (PlayerCache.getInstance().isAuthenticated(name)) return; - for (final Player player : plugin.getServer().getOnlinePlayers()) { - if (player.getName().toLowerCase().equals(name)) { - if (LimboCache.getInstance().hasLimboPlayer(name)) { - LimboPlayer inv = LimboCache.getInstance().getLimboPlayer(name); - inv.getMessageTaskId().cancel(); - inv.getTimeoutTaskId().cancel(); - if (playerCache.doesCacheExist(player)) { - playerCache.removeCache(player); - } - } - final GameMode gm = AuthMePlayerListener.gameMode.get(name); - if (gm != null) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + final GameMode gm = AuthMePlayerListener.gameMode.get(name); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - player.setGameMode(gm); - } - - }); - ConsoleLogger.info("Set " + player.getName() + " to gamemode: " + gm.name()); - } - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - - @Override - public void run() { - if (player.isOnline()) - player.kickPlayer(m.send("timeout")[0]); - } - }); - return; + @Override + public void run() { + if (player.isOnline()) + player.kickPlayer(m.send("timeout")[0]); } - } + }); } }