|
23 | 23 | import meteordevelopment.meteorclient.utils.Utils;
|
24 | 24 | import meteordevelopment.meteorclient.utils.misc.MeteorIdentifier;
|
25 | 25 | import meteordevelopment.meteorclient.utils.misc.text.MeteorClickEvent;
|
| 26 | +import meteordevelopment.meteorclient.utils.misc.text.TextVisitor; |
26 | 27 | import meteordevelopment.meteorclient.utils.player.ChatUtils;
|
27 | 28 | import meteordevelopment.meteorclient.utils.render.color.Color;
|
28 | 29 | import meteordevelopment.orbit.EventHandler;
|
29 | 30 | import net.minecraft.client.gui.DrawContext;
|
30 | 31 | import net.minecraft.client.gui.hud.ChatHudLine;
|
31 | 32 | import net.minecraft.client.network.PlayerListEntry;
|
32 |
| -import net.minecraft.text.ClickEvent; |
33 |
| -import net.minecraft.text.HoverEvent; |
34 |
| -import net.minecraft.text.MutableText; |
35 |
| -import net.minecraft.text.Text; |
| 33 | +import net.minecraft.text.*; |
36 | 34 | import net.minecraft.util.Formatting;
|
37 | 35 | import net.minecraft.util.Identifier;
|
38 | 36 |
|
39 | 37 | import java.text.SimpleDateFormat;
|
40 | 38 | import java.util.ArrayList;
|
41 | 39 | import java.util.Date;
|
42 | 40 | import java.util.List;
|
| 41 | +import java.util.Optional; |
43 | 42 | import java.util.regex.Matcher;
|
44 | 43 | import java.util.regex.Pattern;
|
45 | 44 | import java.util.regex.PatternSyntaxException;
|
@@ -226,7 +225,7 @@ public class BetterChat extends Module {
|
226 | 225 | );
|
227 | 226 |
|
228 | 227 | private static final Pattern antiSpamRegex = Pattern.compile(" \\(([0-9]+)\\)$");
|
229 |
| - private static final Pattern antiClearRegex = Pattern.compile("\\\\n(\\\\n|\\s)*\\\\n"); |
| 228 | + private static final Pattern antiClearRegex = Pattern.compile("\\\\n(\\\\n|\\s)+\\\\n"); |
230 | 229 | private static final Pattern timestampRegex = Pattern.compile("^(<[0-9]{2}:[0-9]{2}>\\s)");
|
231 | 230 | private static final Pattern usernameRegex = Pattern.compile("^(?:<[0-9]{2}:[0-9]{2}>\\s)?<(.*?)>.*");
|
232 | 231 |
|
@@ -258,13 +257,22 @@ private void onMessageReceive(ReceiveMessageEvent event) {
|
258 | 257 | }
|
259 | 258 |
|
260 | 259 | if (antiClear.get()) {
|
261 |
| - // more than two \n behind each other will be reduced to only two \n |
262 |
| - String jsonString = Text.Serialization.toJsonString(message, mc.player.getRegistryManager()); |
263 |
| - |
264 |
| - Matcher antiClearMatcher = antiClearRegex.matcher(jsonString); |
265 |
| - String replacedString = antiClearMatcher.replaceAll("\n\n"); |
266 |
| - |
267 |
| - message = (Text) Text.Serialization.fromJson(replacedString, mc.player.getRegistryManager()); |
| 260 | + String messageString = message.getString(); |
| 261 | + if (antiClearRegex.matcher(messageString).matches()) { |
| 262 | + MutableText newMessage = Text.empty(); |
| 263 | + TextVisitor.visit(message, (text, style, string) -> { |
| 264 | + Matcher antiClearMatcher = antiClearRegex.matcher(string); |
| 265 | + if (antiClearMatcher.matches()) { |
| 266 | + // assume literal text content |
| 267 | + newMessage.append(Text.literal(antiClearMatcher.replaceAll("\n\n")).setStyle(style)); |
| 268 | + } else { |
| 269 | + newMessage.append(text.copyContentOnly().setStyle(style)); |
| 270 | + } |
| 271 | + |
| 272 | + return Optional.empty(); |
| 273 | + }, Style.EMPTY); |
| 274 | + message = newMessage; |
| 275 | + } |
268 | 276 | }
|
269 | 277 |
|
270 | 278 | if (antiSpam.get()) {
|
|
0 commit comments