Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for custom messages. #31

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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<ChatLine> injected(GuiNewChat instance) {
List<ChatLine> chatTabMessages = ChatSearchingManager.filterChatTabMessages(ChatSearchingManager.INSTANCE.getLastSearch());
if (chatTabMessages != null) {
return chatTabMessages;
}
return ChatSearchingManager.filterMessages(ChatSearchingManager.INSTANCE.getLastSearch(), drawnChatLines);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,4 +41,17 @@ object ChatSearchingManager {
cache.getIfPresent(text)
}
}

@JvmStatic
fun filterChatTabMessages(text: String): List<ChatLine>? {
val currentTabs = currentTabs.firstOrNull()
if (currentTabs?.messages?.isEmpty() == false) {
val list: MutableList<ChatLine> = ArrayList()
for (message in currentTabs.messages?: emptyList()) {
list.add(ChatLine(0, ChatComponentText(message), 0))
}
return filterMessages(text, list)
}
return null
}
}
15 changes: 14 additions & 1 deletion src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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<String>? = ArrayList()

//Ugly hack to make GSON not make button / regex null
fun initialize() {
Expand All @@ -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 {
Expand Down
Loading