Skip to content

Commit

Permalink
Update AutoGG.java (bug fix) (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImPot8o authored Sep 5, 2024
1 parent bbd379b commit f053b12
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -75,3 +83,4 @@ public int getPriority() {
return 3;
}
}

0 comments on commit f053b12

Please sign in to comment.