From 2f42179fa466f7d185ef29501562d84b1bfde24b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:22:54 +0200 Subject: added replaceSameMessage support to normal chat messages --- .../java/at/hannibal2/skyhanni/utils/ChatUtils.kt | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt index d600cc403..c923d1dee 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt @@ -68,19 +68,36 @@ object ChatUtils { * @param message The message to be sent * @param prefix Whether to prefix the message with the chat prefix, default true * @param prefixColor Color that the prefix should be, default yellow (§e) + * @param replaceSameMessage Replace the old message with this new message if they are identical * * @see CHAT_PREFIX */ - fun chat(message: String, prefix: Boolean = true, prefixColor: String = "§e") { + fun chat( + message: String, + prefix: Boolean = true, + prefixColor: String = "§e", + replaceSameMessage: Boolean = false, + ) { + if (prefix) { - internalChat(prefixColor + CHAT_PREFIX + message) + internalChat(prefixColor + CHAT_PREFIX + message, replaceSameMessage) } else { - internalChat(message) + internalChat(message, replaceSameMessage) } } - private fun internalChat(message: String): Boolean { - return chat(ChatComponentText(message)) + private fun internalChat( + message: String, + replaceSameMessage: Boolean = false, + ): Boolean { + val text = ChatComponentText(message) + + if (replaceSameMessage) { + text.send(getUniqueMessageIdForString(message)) + } else { + chat(text) + } + return chat(text) } fun chat(message: IChatComponent): Boolean { @@ -129,9 +146,9 @@ object ChatUtils { val rawText = msgPrefix + message val text = Text.text(rawText) { - this.onClick(expireAt, oneTimeClick, onClick) - this.hover = hover.asComponent() - } + this.onClick(expireAt, oneTimeClick, onClick) + this.hover = hover.asComponent() + } if (replaceSameMessage) { text.send(getUniqueMessageIdForString(rawText)) } else { -- cgit