From 5dee3f298497dae472e80235091b659e4042fd49 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 3 Aug 2023 21:55:06 +0200 Subject: Shorten the bestiary level-up message --- .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') 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, 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 MutableMap.put(pairs: Pair) { 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 -- cgit