From 192a6a0922dc5f0688cb02b22f9d00f6246e7563 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 10 Jun 2025 20:27:02 +0700 Subject: [PATCH] fix: OOB error thrown on filter and ipfilter remove --- build-number.txt | 2 +- .../chomens_bot/commands/FilterCommand.java | 20 +++++++++++-------- .../chomens_bot/commands/IPFilterCommand.java | 20 +++++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/build-number.txt b/build-number.txt index c994df5e..749d1523 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -3450 \ No newline at end of file +3454 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/FilterCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/FilterCommand.java index 72cdb3f7..ad60eb6f 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/FilterCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/FilterCommand.java @@ -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); diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/IPFilterCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/IPFilterCommand.java index 4f31d499..553750d3 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/IPFilterCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/IPFilterCommand.java @@ -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);