From f053b128970fb1107ba59fffc11d0452fe48368f Mon Sep 17 00:00:00 2001 From: ImPot8o <84033814+ImPot8o@users.noreply.github.com> Date: Thu, 5 Sep 2024 07:49:02 -0600 Subject: [PATCH] Update AutoGG.java (bug fix) (#108) --- .../chat/modules/triggers/AutoGG.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/polyfrost/hytils/handlers/chat/modules/triggers/AutoGG.java b/src/main/java/org/polyfrost/hytils/handlers/chat/modules/triggers/AutoGG.java index 9912752..ccbbf29 100644 --- a/src/main/java/org/polyfrost/hytils/handlers/chat/modules/triggers/AutoGG.java +++ b/src/main/java/org/polyfrost/hytils/handlers/chat/modules/triggers/AutoGG.java @@ -40,17 +40,25 @@ public class AutoGG implements ChatReceiveModule { @Override public void onMessageReceived(@NotNull ClientChatReceivedEvent event) { String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText()); - if (!hasGameEnded(message)) return; - Multithreading.schedule(() -> UChat.say("/ac " + HytilsConfig.ggMessage), (long) (HytilsConfig.autoGGFirstPhraseDelay * 1000), TimeUnit.MILLISECONDS); - if (HytilsConfig.autoGGSecondMessage) - Multithreading.schedule(() -> UChat.say("/ac " + HytilsConfig.ggMessage2), (long) ((HytilsConfig.autoGGSecondPhraseDelay + HytilsConfig.autoGGFirstPhraseDelay) * 1000), TimeUnit.MILLISECONDS); + if (!hasGameEnded(message)) { + return; + } + + if (!matchFound) { + matchFound = true; + Multithreading.schedule(() -> UChat.say("/ac " + HytilsConfig.ggMessage), (long) (HytilsConfig.autoGGFirstPhraseDelay * 1000), TimeUnit.MILLISECONDS); + if (HytilsConfig.autoGGSecondMessage) { + Multithreading.schedule(() -> UChat.say("/ac " + HytilsConfig.ggMessage2), (long) ((HytilsConfig.autoGGSecondPhraseDelay + HytilsConfig.autoGGFirstPhraseDelay) * 1000), TimeUnit.MILLISECONDS); + } + // Schedule the reset of matchFound after the second message has been sent + Multithreading.schedule(() -> matchFound = false, (long) ((HytilsConfig.autoGGSecondPhraseDelay + HytilsConfig.autoGGFirstPhraseDelay) * 1000) + 5000, TimeUnit.MILLISECONDS); + } } private boolean hasGameEnded(String message) { if (!matchFound && !PatternHandler.INSTANCE.gameEnd.isEmpty()) { for (Pattern triggers : PatternHandler.INSTANCE.gameEnd) { if (triggers.matcher(message).matches()) { - matchFound = true; return true; } } @@ -75,3 +83,4 @@ public int getPriority() { return 3; } } +