diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BetterChat.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BetterChat.java index 7cf9815e3c..46c0dc533b 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BetterChat.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BetterChat.java @@ -208,7 +208,7 @@ public class BetterChat extends Module { .build() ); - private static final Pattern antiSpamRegex = Pattern.compile(".*(\\([0-9]+\\)$)"); + private static final Pattern antiSpamRegex = Pattern.compile(" \\(([0-9]+)\\)$"); private static final Pattern timestampRegex = Pattern.compile("^(<[0-9]{2}:[0-9]{2}>\\s)"); private final Char2CharMap SMALL_CAPS = new Char2CharOpenHashMap(); @@ -229,8 +229,9 @@ private void onMessageReceive(ReceiveMessageEvent event) { Text message = event.getMessage(); if (filterRegex.get()) { + String messageString = message.getString(); for (Pattern pattern : filterRegexList) { - if (pattern.matcher(message.getString()).find()) { + if (pattern.matcher(messageString).find()) { event.cancel(); return; } @@ -250,12 +251,9 @@ private void onMessageReceive(ReceiveMessageEvent event) { } if (timestamps.get()) { - Matcher matcher = timestampRegex.matcher(message.getString()); - if (matcher.matches()) message.getSiblings().subList(0, 8).clear(); - Text timestamp = Text.literal("<" + dateFormat.format(new Date()) + "> ").formatted(Formatting.GRAY); - message = Text.literal("").append(timestamp).append(message); + message = Text.empty().append(timestamp).append(message); } event.setMessage(message); @@ -263,6 +261,7 @@ private void onMessageReceive(ReceiveMessageEvent event) { private Text appendAntiSpam(Text text) { + String textString = text.getString(); Text returnText = null; int messageIndex = -1; @@ -277,21 +276,18 @@ private Text appendAntiSpam(Text text) { stringToCheck = stringToCheck.substring(8); } - if (text.getString().equals(stringToCheck)) { + if (textString.equals(stringToCheck)) { messageIndex = i; returnText = text.copy().append(Text.literal(" (2)").formatted(Formatting.GRAY)); break; - } - else { + } else { Matcher matcher = antiSpamRegex.matcher(stringToCheck); - if (!matcher.matches() && !matcher.find()) continue; + if (!matcher.find()) continue; String group = matcher.group(matcher.groupCount()); - int number = Integer.parseInt(group.substring(1, group.length() - 1)); - - String counter = " (" + number + ")"; + int number = Integer.parseInt(group); - if (stringToCheck.substring(0, stringToCheck.length() - counter.length()).equals(text.getString())) { + if (stringToCheck.substring(0, matcher.start()).equals(textString)) { messageIndex = i; returnText = text.copy().append(Text.literal(" (" + (number + 1) + ")").formatted(Formatting.GRAY)); break;