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.kt22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 4528f7ee5..8ef5433e0 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -22,6 +22,7 @@ import net.minecraft.util.ChatComponentText
import org.lwjgl.input.Keyboard
import java.awt.Color
import java.lang.reflect.Field
+import java.lang.reflect.Modifier
import java.text.DecimalFormat
import java.text.NumberFormat
import java.text.SimpleDateFormat
@@ -222,9 +223,21 @@ object LorenzUtils {
fun clickableChat(message: String, command: String) {
val text = ChatComponentText(message)
- text.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/$command")
+ text.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/${command.removePrefix("/")}")
text.chatStyle.chatHoverEvent =
- HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("§eExecute /$command"))
+ HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("§eExecute /${command.removePrefix("/")}"))
+ Minecraft.getMinecraft().thePlayer.addChatMessage(text)
+ }
+
+ fun hoverableChat(message: String, hover: List<String>, command: String? = null) {
+ val text = ChatComponentText(message)
+ text.chatStyle.chatHoverEvent =
+ HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText(hover.joinToString("\n")))
+
+ if (command != null) {
+ text.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/${command.removePrefix("/")}")
+ }
+
Minecraft.getMinecraft().thePlayer.addChatMessage(text)
}
@@ -432,4 +445,9 @@ object LorenzUtils {
infix fun <K, V> MutableMap<K, V>.put(pairs: Pair<K, V>) {
this[pairs.first] = pairs.second
}
+
+ fun Field.removeFinal(): Field {
+ javaClass.getDeclaredField("modifiers").makeAccessible().set(this, modifiers and (Modifier.FINAL.inv()))
+ return this
+ }
} \ No newline at end of file