diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-10-13 22:22:54 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-10-13 22:22:54 +0200 |
commit | 2f42179fa466f7d185ef29501562d84b1bfde24b (patch) | |
tree | 530b125662868a833a8808c30d859b726a16769d /src/main | |
parent | 78c293ef181e0d7f08e8426e5043e3d8bc078514 (diff) | |
download | skyhanni-2f42179fa466f7d185ef29501562d84b1bfde24b.tar.gz skyhanni-2f42179fa466f7d185ef29501562d84b1bfde24b.tar.bz2 skyhanni-2f42179fa466f7d185ef29501562d84b1bfde24b.zip |
added replaceSameMessage support to normal chat messages
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt | 33 |
1 files 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 { |