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 fe3757a136..8323516eeb 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BetterChat.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BetterChat.java @@ -22,7 +22,6 @@ import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.misc.text.MeteorClickEvent; -import meteordevelopment.meteorclient.utils.misc.text.TextVisitor; import meteordevelopment.meteorclient.utils.player.ChatUtils; import meteordevelopment.orbit.EventHandler; import net.minecraft.client.gl.RenderPipelines; @@ -271,14 +270,11 @@ private void onMessageReceive(ReceiveMessageEvent event) { String messageString = message.getString(); if (antiClearRegex.matcher(messageString).find()) { MutableText newMessage = Text.empty(); - TextVisitor.visit(message, (text, style, string) -> { + message.visit((style, string) -> { Matcher antiClearMatcher = antiClearRegex.matcher(string); - if (antiClearMatcher.find()) { - // assume literal text content - newMessage.append(Text.literal(antiClearMatcher.replaceAll("\n\n")).setStyle(style)); - } else { - newMessage.append(text.copyContentOnly().setStyle(style)); - } + newMessage.append(Text.literal( + antiClearMatcher.find() ? antiClearMatcher.replaceAll("\n\n") : string + ).setStyle(style)); return Optional.empty(); }, Style.EMPTY); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/text/TextVisitor.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/text/TextVisitor.java deleted file mode 100644 index a11cbf7ce1..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/text/TextVisitor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.misc.text; - -import net.minecraft.text.PlainTextContent; -import net.minecraft.text.StringVisitable; -import net.minecraft.text.Style; -import net.minecraft.text.Text; - -import java.util.ArrayDeque; -import java.util.Optional; -import java.util.Queue; - -/** - * An extension of {@link StringVisitable.StyledVisitor} with access to the underlying {@link Text} objects. - * @param the optional short circuit return type, to match the semantics of {@link StringVisitable.Visitor} and {@link StringVisitable.StyledVisitor}. - * @author Crosby - */ -@FunctionalInterface -public interface TextVisitor { - Optional accept(Text text, Style style, String string); - - static Optional visit(Text text, TextVisitor visitor, Style baseStyle) { - Queue queue = collectSiblings(text); - return text.visit((style, string) -> visitor.accept(queue.remove(), style, string), baseStyle); - } - - /** - * Collapses the tree of {@link Text} siblings into a one dimensional FIFO {@link Queue}. To match the behaviours of - * the {@link Text#visit(StringVisitable.Visitor)} and {@link Text#visit(StringVisitable.StyledVisitor, Style)} - * methods, texts with empty contents (created from {@link Text#empty()}) are ignored but their siblings are still - * processed. - * @param text the text - * @return the text and its siblings in the order they appear when rendered. - */ - static ArrayDeque collectSiblings(Text text) { - ArrayDeque queue = new ArrayDeque<>(); - collectSiblings(text, queue); - return queue; - } - - private static void collectSiblings(Text text, Queue queue) { - if (!(text.getContent() instanceof PlainTextContent ptc) || !ptc.string().isEmpty()) queue.add(text); - for (Text sibling : text.getSiblings()) { - collectSiblings(sibling, queue); - } - } -}