refactor: make whitelist remove by index like in the usage
This commit is contained in:
parent
66dc3b97ec
commit
627b18ebf9
2 changed files with 11 additions and 17 deletions
|
@ -57,18 +57,18 @@ public class WhitelistCommand extends Command {
|
|||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "remove" -> {
|
||||
final String player = context.getString(true, true);
|
||||
try {
|
||||
final int index = context.getInteger(true);
|
||||
|
||||
if (!bot.whitelist.list.contains(player)) throw new CommandException(Component.text("Player doesn't exist in the list"));
|
||||
final String player = bot.whitelist.remove(index);
|
||||
|
||||
if (player.equals(bot.profile.getName())) throw new CommandException(Component.text("Cannot remove the bot"));
|
||||
|
||||
bot.whitelist.remove(player);
|
||||
|
||||
return Component.translatable(
|
||||
"Removed %s from the whitelist",
|
||||
Component.text(player).color(ColorUtilities.getColorByString(bot.config.colorPalette.username))
|
||||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
return Component.translatable(
|
||||
"Removed %s from the whitelist",
|
||||
Component.text(player).color(ColorUtilities.getColorByString(bot.config.colorPalette.username))
|
||||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
} catch (IndexOutOfBoundsException | IllegalArgumentException | NullPointerException ignored) {
|
||||
throw new CommandException(Component.text("Invalid index"));
|
||||
}
|
||||
}
|
||||
case "clear" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
|
|
@ -51,13 +51,7 @@ public class WhitelistPlugin extends PlayersPlugin.Listener {
|
|||
}
|
||||
|
||||
public void add (String player) { list.add(player); }
|
||||
public void remove (String player) {
|
||||
list.removeIf(eachPlayer -> eachPlayer.equals(player));
|
||||
|
||||
final PlayerEntry entry = bot.players.getEntry(player);
|
||||
|
||||
if (entry != null) handle(entry);
|
||||
}
|
||||
public String remove (int index) { return list.remove(index); }
|
||||
public void clear () {
|
||||
list.removeIf(eachPlayer -> !eachPlayer.equals(bot.profile.getName()));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue