From 90c7187babc32b4f38a1a4b77c390e2aea199f66 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Mon, 7 Sep 2015 23:28:15 +0700 Subject: [PATCH] run task async, fix #200 --- .../commands/ChangePasswordCommand.java | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java index 7577a2029..0b50da50f 100644 --- a/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java +++ b/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java @@ -25,8 +25,8 @@ public class ChangePasswordCommand implements CommandExecutor { } @Override - public boolean onCommand(CommandSender sender, Command cmnd, String label, - String[] args) { + public boolean onCommand(final CommandSender sender, Command cmnd, String label, + final String[] args) { if (!(sender instanceof Player)) { return true; } @@ -36,8 +36,8 @@ public class ChangePasswordCommand implements CommandExecutor { return true; } - Player player = (Player) sender; - String name = player.getName().toLowerCase(); + final Player player = (Player) sender; + final String name = player.getName().toLowerCase(); if (!PlayerCache.getInstance().isAuthenticated(name)) { m.send(player, "not_logged_in"); return true; @@ -67,30 +67,35 @@ public class ChangePasswordCommand implements CommandExecutor { return true; } } - try { - String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, args[1], name); + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { + @Override + public void run() { + try { + String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, args[1], name); - if (PasswordSecurity.comparePasswordWithHash(args[0], PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) { - PlayerAuth auth = PlayerCache.getInstance().getAuth(name); - auth.setHash(hashnew); - if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null) - auth.setSalt(PasswordSecurity.userSalt.get(name)); - else auth.setSalt(""); - if (!plugin.database.updatePassword(auth)) { - m.send(player, "error"); - return true; + if (PasswordSecurity.comparePasswordWithHash(args[0], PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) { + PlayerAuth auth = PlayerCache.getInstance().getAuth(name); + auth.setHash(hashnew); + if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null) + auth.setSalt(PasswordSecurity.userSalt.get(name)); + else auth.setSalt(""); + if (!plugin.database.updatePassword(auth)) { + m.send(player, "error"); + return; + } + plugin.database.updateSalt(auth); + PlayerCache.getInstance().updatePlayer(auth); + m.send(player, "pwd_changed"); + ConsoleLogger.info(player.getName() + " changed his password"); + } else { + m.send(player, "wrong_pwd"); + } + } catch (NoSuchAlgorithmException ex) { + ConsoleLogger.showError(ex.getMessage()); + m.send(sender, "error"); } - plugin.database.updateSalt(auth); - PlayerCache.getInstance().updatePlayer(auth); - m.send(player, "pwd_changed"); - ConsoleLogger.info(player.getName() + " changed his password"); - } else { - m.send(player, "wrong_pwd"); } - } catch (NoSuchAlgorithmException ex) { - ConsoleLogger.showError(ex.getMessage()); - m.send(sender, "error"); - } + }); return true; } }