From fca7c2d26fc33c513e60ee9784a1f93686ccbb65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Sun, 20 Nov 2022 03:52:15 +0100 Subject: [PATCH] Fix command registration --- .../hidekobot/utils/SlashCommandsUtil.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/wtf/beatrice/hidekobot/utils/SlashCommandsUtil.java b/src/main/java/wtf/beatrice/hidekobot/utils/SlashCommandsUtil.java index 5515c25..d666898 100644 --- a/src/main/java/wtf/beatrice/hidekobot/utils/SlashCommandsUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/utils/SlashCommandsUtil.java @@ -39,6 +39,7 @@ public class SlashCommandsUtil // for each command that we have already registered... for(Command currRegCmd : registeredCommands) { + boolean found = false; // iterate through all "recognized" commands for(CommandData cmdData : allCommands) @@ -47,13 +48,20 @@ public class SlashCommandsUtil if(cmdData.getName().equals(currRegCmd.getName())) { // quit the loop since we found it. + found = true; break; } } // if no match was found, we need to send an updated command list because // an old command was probably removed. - update = true; + if(!found) + { + update = true; + + // quit the loop since we only need to trigger this once. + break; + } } // if an update is not already queued... @@ -62,6 +70,7 @@ public class SlashCommandsUtil // for each "recognized" valid command for(CommandData currCmdData : allCommands) { + boolean found = false; // iterate through all already registered commands. for(Command cmd : registeredCommands) @@ -70,16 +79,23 @@ public class SlashCommandsUtil if(cmd.getName().equals(currCmdData.getName())) { // quit the loop since we found a match. + found = true; break; } } // if no match was found, we need to send an updated command list because // a new command was probably added. - update = true; + if(!found) + { + update = true; + + // quit the loop since we only need to trigger this once. + break; + } } } - + logger.log("Found " + registeredCommands.size() + " commands."); if(update)