From a8138b0aa20d2b2fd266b1352eaf075999365bb6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:16:49 +0100 Subject: Backend: ChatClickActionManager (#1128) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt | 15 +++++++++++++++ src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt | 2 ++ 2 files changed, 17 insertions(+) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt index ae04b4535..d2f12b1d0 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ChatClickActionManager import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -127,6 +128,20 @@ object ChatUtils { Minecraft.getMinecraft().thePlayer.addChatMessage(text) } + /** + * Sends a message to the user that they can click and run an action + * @param message The message to be sent + * @param onClick The runnable to be executed when the message is clicked + * @param prefix Whether to prefix the message with the chat prefix, default true + * @param prefixColor Color that the prefix should be, default yellow (§e) + * + * @see CHAT_PREFIX + */ + fun clickableChat(message: String, onClick: () -> Any, prefix: Boolean = true, prefixColor: String = "§e") { + val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else "" + ChatClickActionManager.oneTimeClick(msgPrefix + message, onClick) + } + /** * Sends a message to the user that they can click and run a command * @param message The message to be sent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index a937b6f12..bcb185f60 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -299,4 +299,6 @@ object StringUtils { fun String.isRoman(): Boolean = UtilsPatterns.isRomanPattern.matches(this) fun isEmpty(message: String): Boolean = message.removeColor().trimWhiteSpaceAndResets().isEmpty() + + fun generateRandomId() = UUID.randomUUID().toString() } -- cgit