unregister asynchronously

This commit is contained in:
DNx5 2015-09-19 12:51:59 +07:00
parent b5546c07b4
commit a00deb0e0f

View File

@ -1,18 +1,5 @@
package fr.xephi.authme.commands;
import java.security.NoSuchAlgorithmException;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.Utils;
@ -26,6 +13,18 @@ import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import java.security.NoSuchAlgorithmException;
public class UnregisterCommand implements CommandExecutor {
@ -39,8 +38,8 @@ public class UnregisterCommand 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;
}
@ -50,8 +49,8 @@ public class UnregisterCommand 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");
@ -62,11 +61,14 @@ public class UnregisterCommand implements CommandExecutor {
m.send(player, "usage_unreg");
return true;
}
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
if (PasswordSecurity.comparePasswordWithHash(args[0], PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) {
if (!plugin.database.removeAuth(name)) {
player.sendMessage("error");
return true;
return;
}
if (Settings.isForcedRegistrationEnabled) {
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
@ -94,7 +96,7 @@ public class UnregisterCommand implements CommandExecutor {
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval)));
m.send(player, "unregistered");
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
return true;
return;
}
if (!Settings.unRegisteredGroup.isEmpty()) {
Utils.getInstance().setGroup(player, Utils.GroupType.UNREGISTERED);
@ -120,7 +122,7 @@ public class UnregisterCommand implements CommandExecutor {
player.teleport(tpEvent.getTo());
}
}
return true;
return;
} else {
m.send(player, "wrong_pwd");
}
@ -128,6 +130,8 @@ public class UnregisterCommand implements CommandExecutor {
ConsoleLogger.showError(ex.getMessage());
sender.sendMessage("Internal Error please read the server log");
}
}
});
return true;
}
}