summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 9ee2c42e8..9c4116da4 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -369,6 +369,33 @@ object LorenzUtils {
Minecraft.getMinecraft().thePlayer.addChatMessage(text)
}
+ /**
+ * Sends a message to the user that they can click and run a command
+ * @param message The message to be sent
+ * @param url The url to be opened
+ * @param autoOpen Automatically opens the url as well as sending the clickable link message
+ * @param hover The message to be shown when the message is hovered
+ * @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 clickableLinkChat(
+ message: String,
+ url: String,
+ hover: String = "§eOpen $url",
+ autoOpen: Boolean = false,
+ prefix: Boolean = true,
+ prefixColor: String = "§e"
+ ) {
+ val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else ""
+ val text = ChatComponentText(msgPrefix + message)
+ text.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.OPEN_URL, url)
+ text.chatStyle.chatHoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("$prefixColor$hover"))
+ Minecraft.getMinecraft().thePlayer.addChatMessage(text)
+ if (autoOpen) OSUtils.openBrowser(url)
+ }
+
fun <K, V> Map<K, V>.moveEntryToTop(matcher: (Map.Entry<K, V>) -> Boolean): Map<K, V> {
val entry = entries.find(matcher)
if (entry != null) {