diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java index 69774e221..33cef3ded 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -117,7 +117,10 @@ public class LimboCache { * @param name String */ public void deleteLimboPlayer(String name) { - cache.remove(name); + if(cache.containsKey(name)) { + cache.get(name).clearTask(); + cache.remove(name); + } } /** @@ -148,8 +151,9 @@ public class LimboCache { * @param player Player */ public void updateLimboPlayer(Player player) { - if (this.hasLimboPlayer(player.getName().toLowerCase())) { - this.deleteLimboPlayer(player.getName().toLowerCase()); + String name = player.getName().toLowerCase(); + if (hasLimboPlayer(name)) { + deleteLimboPlayer(name); } addLimboPlayer(player); } diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java index 96c5a9ee9..76ed21e8e 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java @@ -108,8 +108,9 @@ public class LimboPlayer { * @param i BukkitTask */ public void setTimeoutTaskId(BukkitTask i) { - if (this.timeoutTaskId != null) + if (this.timeoutTaskId != null) { this.timeoutTaskId.cancel(); + } this.timeoutTaskId = i; } @@ -128,11 +129,27 @@ public class LimboPlayer { * @param messageTaskId BukkitTask */ public void setMessageTaskId(BukkitTask messageTaskId) { - if (this.messageTaskId != null) + if (this.messageTaskId != null) { this.messageTaskId.cancel(); + } this.messageTaskId = messageTaskId; } + /** + * Method clearTask. + * + */ + public void clearTask() { + if (messageTaskId != null) { + messageTaskId.cancel(); + } + messageTaskId = null; + if (timeoutTaskId != null) { + timeoutTaskId.cancel(); + } + timeoutTaskId = null; + } + /** * Method isFlying. * diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index aa49d3f29..01724b3a1 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -50,14 +50,12 @@ public class AsynchronousJoin { } public void process() { - if (AuthMePlayerListener.gameMode.containsKey(name)) - AuthMePlayerListener.gameMode.remove(name); - AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode()); - - if (Utils.isNPC(player) || Utils.isUnrestricted(player)) { + if (Utils.isUnrestricted(player)) { return; } + AuthMePlayerListener.gameMode.put(name, player.getGameMode()); + if (plugin.ess != null && Settings.disableSocialSpy) { plugin.ess.getUser(player).setSocialSpyEnabled(false); } 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 28faa5bf3..bd1bb174f 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java @@ -41,15 +41,13 @@ public class ProcessSyncronousPasswordRegister implements Runnable { this.plugin = plugin; } - protected void forceCommands() { + private void forceCommands() { for (String command : Settings.forceRegisterCommands) { - try { - player.performCommand(command.replace("%p", player.getName())); - } catch (Exception ignored) { - } + player.performCommand(command.replace("%p", player.getName())); } for (String command : Settings.forceRegisterCommandsAsConsole) { - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName())); + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), + command.replace("%p", player.getName())); } } @@ -58,20 +56,21 @@ public class ProcessSyncronousPasswordRegister implements Runnable { * * @param player Player */ - protected void forceLogin(Player player) { + private void forceLogin(Player player) { Utils.teleportToSpawn(player); - if (LimboCache.getInstance().hasLimboPlayer(name)) - LimboCache.getInstance().deleteLimboPlayer(name); - LimboCache.getInstance().addLimboPlayer(player); + LimboCache cache = LimboCache.getInstance(); + cache.updateLimboPlayer(player); int delay = Settings.getRegistrationTimeout * 20; int interval = Settings.getWarnMessageInterval; BukkitScheduler sched = plugin.getServer().getScheduler(); + BukkitTask task; if (delay != 0) { - BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); - LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); + task = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); + cache.getLimboPlayer(name).setTimeoutTaskId(task); } - BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.retrieve(MessageKey.LOGIN_MESSAGE), interval)); - LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); + task = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, + m.retrieve(MessageKey.LOGIN_MESSAGE), interval)); + cache.getLimboPlayer(name).setMessageTaskId(task); if (player.isInsideVehicle() && player.getVehicle() != null) { player.getVehicle().eject(); } @@ -97,33 +96,39 @@ public class ProcessSyncronousPasswordRegister implements Runnable { } } - limbo.getTimeoutTaskId().cancel(); - limbo.getMessageTaskId().cancel(); LimboCache.getInstance().deleteLimboPlayer(name); } if (!Settings.getRegisteredGroup.isEmpty()) { Utils.setGroup(player, Utils.GroupType.REGISTERED); } + m.send(player, MessageKey.REGISTER_SUCCESS); - if (!Settings.getmailAccount.isEmpty()) + + if (!Settings.getmailAccount.isEmpty()) { m.send(player, MessageKey.ADD_EMAIL_MESSAGE); + } if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { player.setAllowFlight(false); player.setFlying(false); } - if (Settings.applyBlindEffect) + + if (Settings.applyBlindEffect) { player.removePotionEffect(PotionEffectType.BLINDNESS); + } + if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) { player.setWalkSpeed(0.2f); player.setFlySpeed(0.1f); } + // The LoginEvent now fires (as intended) after everything is processed plugin.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); player.saveData(); - if (!Settings.noConsoleSpam) + if (!Settings.noConsoleSpam) { ConsoleLogger.info(player.getName() + " registered " + plugin.getIP(player)); + } // Kick Player after Registration is enabled, kick the player if (Settings.forceRegKick) { @@ -138,7 +143,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable { } // Register is finish and player is logged, display welcome message - if (Settings.useWelcomeMessage) + if (Settings.useWelcomeMessage) { if (Settings.broadcastWelcomeMessage) { for (String s : Settings.welcomeMsg) { plugin.getServer().broadcastMessage(plugin.replaceAllInfo(s, player)); @@ -148,6 +153,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable { player.sendMessage(plugin.replaceAllInfo(s, player)); } } + } // Register is now finish , we can force all commands forceCommands();