diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-10-09 10:03:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-09 10:03:43 +0200 |
commit | 4f724df118aa46f329b36e410785b9b65c018e25 (patch) | |
tree | 052ad31ebf151229a72d08d4be662e28e95140e7 | |
parent | 5fc17cd508e671a65e61df0957bf32d5dcb42455 (diff) | |
download | skyhanni-4f724df118aa46f329b36e410785b9b65c018e25.tar.gz skyhanni-4f724df118aa46f329b36e410785b9b65c018e25.tar.bz2 skyhanni-4f724df118aa46f329b36e410785b9b65c018e25.zip |
Improvement: Less spam (#2700)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt | 1 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt | 23 |
2 files changed, 22 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt index a07960231..949e33146 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt @@ -143,6 +143,7 @@ object MayorAPI { ChatUtils.clickableChat( "The Perkpocalypse Mayor is not known! Click here to update the temporary Mayor.", onClick = { HypixelCommands.calendar() }, + replaceSameMessage = true, ) } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt index 3a3ffead3..a8941c95a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.chat.Text.command import at.hannibal2.skyhanni.utils.chat.Text.hover import at.hannibal2.skyhanni.utils.chat.Text.onClick import at.hannibal2.skyhanni.utils.chat.Text.prefix +import at.hannibal2.skyhanni.utils.chat.Text.send import at.hannibal2.skyhanni.utils.chat.Text.url import at.hannibal2.skyhanni.utils.compat.getFormattedTextCompat import net.minecraft.client.Minecraft @@ -110,6 +111,7 @@ object ChatUtils { * @param expireAt When the click action should expire, default never * @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 */ @@ -121,14 +123,30 @@ object ChatUtils { prefix: Boolean = true, prefixColor: String = "§e", oneTimeClick: Boolean = false, + replaceSameMessage: Boolean = false, ) { val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else "" - chat(Text.text(msgPrefix + message) { + + val rawText = msgPrefix + message + val text = Text.text(rawText) { this.onClick(expireAt, oneTimeClick, onClick) this.hover = hover.asComponent() - }) + } + if (replaceSameMessage) { + text.send(getUniqueMessageIdForString(rawText)) + } else { + chat(text) + } } + val uniqueMessageIdStorage = mutableMapOf<String, Int>() + + fun getUniqueMessageIdForString(string: String) = uniqueMessageIdStorage.getOrPut(string) { getUniqueMessageId() } + + var lastUniqueMessageId = 123242 + + fun getUniqueMessageId() = lastUniqueMessageId++ + /** * Sends a message to the user that they can click and run a command * @param message The message to be sent @@ -271,6 +289,7 @@ object ChatUtils { }, hover = "§eClick to $actionName!\n" + "§eShift-Click or Control-Click to disable this feature!", + replaceSameMessage = true, ) } } |