Search in sources :

Example 1 with AuthUnregisterEvent

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);
}
Also used : Player(com.velocitypowered.api.proxy.Player) RegisteredPlayer(net.elytrium.limboauth.model.RegisteredPlayer) SQLException(java.sql.SQLException) CommandSource(com.velocitypowered.api.command.CommandSource) AuthUnregisterEvent(net.elytrium.limboauth.event.AuthUnregisterEvent) RegisteredPlayer(net.elytrium.limboauth.model.RegisteredPlayer)

Aggregations

CommandSource (com.velocitypowered.api.command.CommandSource)1 Player (com.velocitypowered.api.proxy.Player)1 SQLException (java.sql.SQLException)1 AuthUnregisterEvent (net.elytrium.limboauth.event.AuthUnregisterEvent)1 RegisteredPlayer (net.elytrium.limboauth.model.RegisteredPlayer)1