use of net.elytrium.limboauth.event.AuthUnregisterEvent in project LimboAuth by Elytrium.
the class UnregisterCommand method execute.
@Override
public void execute(SimpleCommand.Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (!(source instanceof Player)) {
source.sendMessage(this.notPlayer);
return;
}
if (args.length == 2) {
if (args[1].equalsIgnoreCase("confirm")) {
String username = ((Player) source).getUsername();
RegisteredPlayer player = AuthSessionHandler.fetchInfo(this.playerDao, username);
if (player == null) {
source.sendMessage(this.notRegistered);
} else if (player.getHash().isEmpty()) {
source.sendMessage(this.crackedCommand);
} else if (AuthSessionHandler.checkPassword(args[0], player, this.playerDao)) {
try {
this.plugin.getServer().getEventManager().fireAndForget(new AuthUnregisterEvent(username));
this.playerDao.deleteById(username.toLowerCase(Locale.ROOT));
this.plugin.removePlayerFromCache(username);
((Player) source).disconnect(this.successful);
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
e.printStackTrace();
}
} else {
source.sendMessage(this.wrongPassword);
}
return;
}
}
source.sendMessage(this.usage);
}
Aggregations