diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-03 21:55:06 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-03 21:55:06 +0200 |
commit | 5dee3f298497dae472e80235091b659e4042fd49 (patch) | |
tree | 1f56f4f292d81c0fb8a3605cb50268d2bd8c6662 /src/main/java/at/hannibal2/skyhanni/features | |
parent | d28deb42cf69ba3a56e1117e373a0a3514a45e31 (diff) | |
download | skyhanni-5dee3f298497dae472e80235091b659e4042fd49.tar.gz skyhanni-5dee3f298497dae472e80235091b659e4042fd49.tar.bz2 skyhanni-5dee3f298497dae472e80235091b659e4042fd49.zip |
Shorten the bestiary level-up message
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/chat/CompactBestiaryChatMessage.kt | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/CompactBestiaryChatMessage.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactBestiaryChatMessage.kt new file mode 100644 index 000000000..7b893afcf --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactBestiaryChatMessage.kt @@ -0,0 +1,87 @@ +package at.hannibal2.skyhanni.features.chat + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.ChatLine +import net.minecraft.util.IChatComponent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.relauncher.ReflectionHelper + +class CompactBestiaryChatMessage { + + var inBestiary = false + var bestiaryDescription = mutableListOf<String>() + var acceptMoreDescription = true + var command = "" + + var lastBorder: IChatComponent? = null + var lastEmpty: IChatComponent? = null + + var milestoneMessage: String? = null + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!SkyHanniMod.feature.chat.compactBestiaryMessage) return + + val titleMessage = " §6§lBESTIARY" + val border = "§3§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬" + + val message = event.message + + if (message == border) { + lastBorder = event.chatComponent + } + if (message == " ") { + lastEmpty = event.chatComponent + } + + if (message == titleMessage) { + event.blockedReason = "bestiary" + val chatGUI = Minecraft.getMinecraft().ingameGUI.chatGUI + val chatLinesField = ReflectionHelper.findField(chatGUI.javaClass, "chatLines") + val chatLines = chatLinesField.makeAccessible().get(chatGUI) as MutableList<ChatLine> + + lastBorder?.let { chat -> chatLines.removeIf { it.chatComponent === chat } } + lastEmpty?.let { chat -> chatLines.removeIf { it.chatComponent === chat } } + chatGUI.refreshChat() + + lastBorder = null + lastEmpty = null + + for (sibling in event.chatComponent.siblings) { + sibling.chatStyle?.chatClickEvent?.let { + command = it.value + } + } + inBestiary = true + bestiaryDescription.add(message.trim()) + } else if (inBestiary) { + event.blockedReason = "bestiary" + if (message == border) { + inBestiary = false + + val title = bestiaryDescription[1] + LorenzUtils.hoverableChat("§6§lBESTIARY §r$title", bestiaryDescription.dropLast(1), command) + bestiaryDescription.clear() + acceptMoreDescription = true + + } else { + milestoneMessage?.let { + LorenzUtils.chat("§6§lBESTIARY MILESTONE $it") + milestoneMessage = null + } + if (message.endsWith("§6§lBESTIARY MILESTONE")) { + acceptMoreDescription = false + milestoneMessage = message + } + if (acceptMoreDescription) { + bestiaryDescription.add(message.trim()) + } + } + } + } +} |