aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt33
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 {