From b84dba55eed032f7a30f5376cbe61b13ea603061 Mon Sep 17 00:00:00 2001 From: sin ender Date: Mon, 26 Feb 2024 19:33:53 -0500 Subject: [PATCH] Allow for custom messages. --- .../mixin/GuiNewChatMixin_ChatSearching.java | 7 +++++++ .../chatting/chat/ChatSearchingManager.kt | 15 +++++++++++++++ .../kotlin/org/polyfrost/chatting/chat/ChatTab.kt | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatSearching.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatSearching.java index f1ad3a4..8e8c7f2 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatSearching.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_ChatSearching.java @@ -2,9 +2,11 @@ import net.minecraft.client.gui.ChatLine; import net.minecraft.client.gui.GuiNewChat; +import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; import org.objectweb.asm.Opcodes; import org.polyfrost.chatting.chat.ChatSearchingManager; +import org.polyfrost.chatting.chat.ChatTabs; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -13,6 +15,7 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.ArrayList; import java.util.List; @Mixin(GuiNewChat.class) @@ -26,6 +29,10 @@ private void handleSetChatLine(IChatComponent chatComponent, int chatLineId, int @Redirect(method = "drawChat", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/GuiNewChat;drawnChatLines:Ljava/util/List;", opcode = Opcodes.GETFIELD)) private List injected(GuiNewChat instance) { + List chatTabMessages = ChatSearchingManager.filterChatTabMessages(ChatSearchingManager.INSTANCE.getLastSearch()); + if (chatTabMessages != null) { + return chatTabMessages; + } return ChatSearchingManager.filterMessages(ChatSearchingManager.INSTANCE.getLastSearch(), drawnChatLines); } } diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatSearchingManager.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatSearchingManager.kt index d20a358..3682cd3 100644 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatSearchingManager.kt +++ b/src/main/kotlin/org/polyfrost/chatting/chat/ChatSearchingManager.kt @@ -4,6 +4,8 @@ import cc.polyfrost.oneconfig.libs.caffeine.cache.Cache import cc.polyfrost.oneconfig.libs.caffeine.cache.Caffeine import cc.polyfrost.oneconfig.libs.universal.wrappers.message.UTextComponent import net.minecraft.client.gui.ChatLine +import net.minecraft.util.ChatComponentText +import org.polyfrost.chatting.chat.ChatTabs.currentTabs import java.util.concurrent.LinkedBlockingQueue import java.util.concurrent.ThreadPoolExecutor import java.util.concurrent.TimeUnit @@ -39,4 +41,17 @@ object ChatSearchingManager { cache.getIfPresent(text) } } + + @JvmStatic + fun filterChatTabMessages(text: String): List? { + val currentTabs = currentTabs.firstOrNull() + if (currentTabs?.messages?.isEmpty() == false) { + val list: MutableList = ArrayList() + for (message in currentTabs.messages?: emptyList()) { + list.add(ChatLine(0, ChatComponentText(message), 0)) + } + return filterMessages(text, list) + } + return null + } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt index bd65f11..8861137 100644 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt +++ b/src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt @@ -1,10 +1,14 @@ package org.polyfrost.chatting.chat +import cc.polyfrost.oneconfig.libs.universal.ChatColor import org.polyfrost.chatting.gui.components.TabButton import com.google.gson.annotations.SerializedName import net.minecraft.client.Minecraft +import net.minecraft.client.gui.ChatLine +import net.minecraft.util.ChatComponentText import net.minecraft.util.EnumChatFormatting import net.minecraft.util.IChatComponent +import org.polyfrost.chatting.mixin.GuiNewChatAccessor import java.util.* data class ChatTab( @@ -25,11 +29,12 @@ data class ChatTab( val color: Int?, @SerializedName("hovered_color") val hoveredColor: Int?, @SerializedName("selected_color") val selectedColor: Int?, - val prefix: String?, + val prefix: String? ) { lateinit var button: TabButton lateinit var compiledRegex: ChatRegexes lateinit var compiledIgnoreRegex: ChatRegexes + @Transient var messages: List? = ArrayList() //Ugly hack to make GSON not make button / regex null fun initialize() { @@ -41,6 +46,14 @@ data class ChatTab( x += 6 + width return@run returnValue }, width + 4, 12, this) + + if (messages == null) return + messages?.forEach { + (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatAccessor).chatLines.add( + 0, + ChatLine(0, ChatComponentText(ChatColor.translateAlternateColorCodes('&', it)), 0) + ) + } } fun shouldRender(chatComponent: IChatComponent): Boolean {