diff options
Diffstat (limited to 'src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java')
-rw-r--r-- | src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java b/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java index 2b97143..bf30f92 100644 --- a/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java +++ b/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java @@ -17,19 +17,17 @@ package net.elytrium.limboauth.command; -import com.google.common.collect.ImmutableList; import com.j256.ormlite.dao.Dao; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.SimpleCommand; -import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import java.sql.SQLException; import java.text.MessageFormat; import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; import net.elytrium.limboauth.LimboAuth; import net.elytrium.limboauth.Settings; +import net.elytrium.limboauth.utils.SuggestUtils; import net.elytrium.limboauth.model.RegisteredPlayer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -58,20 +56,7 @@ public class ForceUnregisterCommand implements SimpleCommand { @Override public List<String> suggest(SimpleCommand.Invocation invocation) { - String[] args = invocation.arguments(); - - if (args.length == 0) { - return this.server.getAllPlayers().stream() - .map(Player::getUsername) - .collect(Collectors.toList()); - } else if (args.length == 1) { - return this.server.getAllPlayers().stream() - .map(Player::getUsername) - .filter(str -> str.regionMatches(true, 0, args[0], 0, args[0].length())) - .collect(Collectors.toList()); - } - - return ImmutableList.of(); + return SuggestUtils.suggestPlayers(invocation.arguments(), this.server); } @Override @@ -81,12 +66,11 @@ public class ForceUnregisterCommand implements SimpleCommand { if (args.length == 1) { String playerNick = args[0]; + try { this.playerDao.deleteById(playerNick.toLowerCase(Locale.ROOT)); this.plugin.removePlayerFromCache(playerNick); - this.server.getPlayer(playerNick).ifPresent(player -> { - player.disconnect(this.kick); - }); + this.server.getPlayer(playerNick).ifPresent(player -> player.disconnect(this.kick)); source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MessageFormat.format(this.successful, playerNick))); } catch (SQLException e) { source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MessageFormat.format(this.notSuccessful, playerNick))); |