fix: OOB error thrown on filter and ipfilter remove

This commit is contained in:
ChomeNS
2025-06-10 20:27:02 +07:00
parent 0ae4f32c3a
commit 192a6a0922
3 changed files with 25 additions and 17 deletions

View File

@@ -1 +1 @@
3450
3454

View File

@@ -98,17 +98,21 @@ public class FilterCommand extends Command {
final int index = context.getInteger(true);
final FilteredPlayer player = PlayerFilterPlugin.localList.get(index);
try {
final FilteredPlayer player = PlayerFilterPlugin.localList.get(index);
if (player == null) throw new CommandException(Component.translatable("commands.generic.error.invalid_index"));
if (player == null) throw new IllegalArgumentException();
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> bot.playerFilter.remove(player.playerName()));
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> bot.playerFilter.remove(player.playerName()));
return Component.translatable(
"commands.filter.remove.output",
bot.colorPalette.defaultColor,
Component.text(player.playerName(), bot.colorPalette.username)
);
return Component.translatable(
"commands.filter.remove.output",
bot.colorPalette.defaultColor,
Component.text(player.playerName(), bot.colorPalette.username)
);
} catch (final IndexOutOfBoundsException | IllegalArgumentException | NullPointerException e) {
throw new CommandException(Component.translatable("commands.generic.error.invalid_index"));
}
}
case "clear" -> {
context.checkOverloadArgs(1);

View File

@@ -73,17 +73,21 @@ public class IPFilterCommand extends Command {
final int index = context.getInteger(true);
final String targetIP = new ArrayList<>(IPFilterPlugin.localList.keySet()).get(index);
try {
final String targetIP = new ArrayList<>(IPFilterPlugin.localList.keySet()).get(index);
if (targetIP == null) throw new CommandException(Component.translatable("commands.generic.error.invalid_index"));
if (targetIP == null) throw new IllegalArgumentException();
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> bot.ipFilter.remove(targetIP));
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> bot.ipFilter.remove(targetIP));
return Component.translatable(
"commands.ipfilter.remove.output",
bot.colorPalette.defaultColor,
Component.text(targetIP, bot.colorPalette.username)
);
return Component.translatable(
"commands.ipfilter.remove.output",
bot.colorPalette.defaultColor,
Component.text(targetIP, bot.colorPalette.username)
);
} catch (final IndexOutOfBoundsException | IllegalArgumentException | NullPointerException e) {
throw new CommandException(Component.translatable("commands.generic.error.invalid_index"));
}
}
case "clear" -> {
context.checkOverloadArgs(1);