Compare commits

..

No commits in common. "159cb8ce11fb3234915bc12002f416a5f7f13384" and "66dc3b97ec6d28e0bd4e1d3fc453ecec66c4fde6" have entirely different histories.

4 changed files with 24 additions and 17 deletions

View file

@ -52,12 +52,11 @@ public class CloopCommand extends Command {
try {
final int index = context.getInteger(true);
final CommandLoop cloop = bot.cloop.remove(index);
bot.cloop.remove(index);
return Component.translatable(
"Removed cloop %s",
Component.text(cloop.command()).color(ColorUtilities.getColorByString(bot.config.colorPalette.number))
Component.text(index).color(ColorUtilities.getColorByString(bot.config.colorPalette.number))
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
} catch (IndexOutOfBoundsException | IllegalArgumentException | NullPointerException ignored) {
throw new CommandException(Component.text("Invalid index"));
@ -97,7 +96,9 @@ public class CloopCommand extends Command {
Component.join(JoinConfiguration.newlines(), cloopsComponent)
);
}
default -> throw new CommandException(Component.text("Invalid action"));
default -> {
throw new CommandException(Component.text("Invalid action"));
}
}
}
}

View file

@ -57,18 +57,18 @@ public class WhitelistCommand extends Command {
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
}
case "remove" -> {
try {
final int index = context.getInteger(true);
final String player = context.getString(true, true);
final String player = bot.whitelist.remove(index);
if (!bot.whitelist.list.contains(player)) throw new CommandException(Component.text("Player doesn't exist in the list"));
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"));
}
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));
}
case "clear" -> {
context.checkOverloadArgs(1);

View file

@ -26,14 +26,14 @@ public class CloopPlugin {
loopTasks.add(bot.executor.scheduleAtFixedRate(loopTask, 0, interval, TimeUnit.MILLISECONDS));
}
public CommandLoop remove (int index) {
public void remove (int index) {
ScheduledFuture<?> loopTask = loopTasks.remove(index);
if (loopTask != null) {
loopTask.cancel(true);
}
return loops.remove(index);
loops.remove(index);
}
public void clear () {

View file

@ -51,7 +51,13 @@ public class WhitelistPlugin extends PlayersPlugin.Listener {
}
public void add (String player) { list.add(player); }
public String remove (int index) { return list.remove(index); }
public void remove (String player) {
list.removeIf(eachPlayer -> eachPlayer.equals(player));
final PlayerEntry entry = bot.players.getEntry(player);
if (entry != null) handle(entry);
}
public void clear () {
list.removeIf(eachPlayer -> !eachPlayer.equals(bot.profile.getName()));
}