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 --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 3 +- .../at/hannibal2/skyhanni/config/Features.java | 27 +++- .../hannibal2/skyhanni/config/features/Chat.java | 136 ------------------- .../skyhanni/config/features/ChatConfig.java | 145 +++++++++++++++++++++ .../features/chat/CompactBestiaryChatMessage.kt | 87 +++++++++++++ .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 22 +++- 6 files changed, 279 insertions(+), 141 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/Chat.java create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/chat/CompactBestiaryChatMessage.kt (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index e19b4b49b..14650eff9 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -15,6 +15,7 @@ import at.hannibal2.skyhanni.features.bazaar.BazaarOrderHelper import at.hannibal2.skyhanni.features.bingo.* import at.hannibal2.skyhanni.features.chat.ArachneChatMessageHider import at.hannibal2.skyhanni.features.chat.ChatFilter +import at.hannibal2.skyhanni.features.chat.CompactBestiaryChatMessage import at.hannibal2.skyhanni.features.chat.PlayerDeathMessages import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFilter import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatModifier @@ -373,7 +374,7 @@ class SkyHanniMod { loadModule(KingTalismanHelper()) loadModule(HarpKeybinds()) loadModule(EnderNodeTracker()) - // + loadModule(CompactBestiaryChatMessage()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index c8bfc3d1f..2f2de9fc5 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -1,7 +1,30 @@ package at.hannibal2.skyhanni.config; import at.hannibal2.skyhanni.SkyHanniMod; -import at.hannibal2.skyhanni.config.features.*; +import at.hannibal2.skyhanni.config.features.About; +import at.hannibal2.skyhanni.config.features.Ashfang; +import at.hannibal2.skyhanni.config.features.Bazaar; +import at.hannibal2.skyhanni.config.features.Bingo; +import at.hannibal2.skyhanni.config.features.ChatConfig; +import at.hannibal2.skyhanni.config.features.CommandsFeatures; +import at.hannibal2.skyhanni.config.features.DamageIndicatorConfig; +import at.hannibal2.skyhanni.config.features.DevConfig; +import at.hannibal2.skyhanni.config.features.DianaConfig; +import at.hannibal2.skyhanni.config.features.Dungeon; +import at.hannibal2.skyhanni.config.features.Fishing; +import at.hannibal2.skyhanni.config.features.GUI; +import at.hannibal2.skyhanni.config.features.Garden; +import at.hannibal2.skyhanni.config.features.GhostCounterConfig; +import at.hannibal2.skyhanni.config.features.Inventory; +import at.hannibal2.skyhanni.config.features.ItemAbilities; +import at.hannibal2.skyhanni.config.features.MarkedPlayers; +import at.hannibal2.skyhanni.config.features.Minions; +import at.hannibal2.skyhanni.config.features.MiscConfig; +import at.hannibal2.skyhanni.config.features.Mobs; +import at.hannibal2.skyhanni.config.features.OldHidden; +import at.hannibal2.skyhanni.config.features.RiftConfig; +import at.hannibal2.skyhanni.config.features.SlayerConfig; +import at.hannibal2.skyhanni.config.features.Summonings; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.Config; import io.github.moulberry.moulconfig.Social; @@ -49,7 +72,7 @@ public class Features extends Config { @Expose @Category(name = "Chat", desc = "Change how the chat looks.") - public Chat chat = new Chat(); + public ChatConfig chat = new ChatConfig(); @Expose @Category(name = "Dungeon", desc = "Features that change the dungeon experience in catacombs.") diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java b/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java deleted file mode 100644 index f149fc624..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java +++ /dev/null @@ -1,136 +0,0 @@ -package at.hannibal2.skyhanni.config.features; - -import com.google.gson.annotations.Expose; -import io.github.moulberry.moulconfig.annotations.*; -import org.lwjgl.input.Keyboard; - -public class Chat { - - @Expose - @ConfigOption(name = "Peek Chat", desc = "Hold this key to keep the chat open.") - @ConfigEditorKeybind(defaultKey = Keyboard.KEY_Z) - public int peekChat = Keyboard.KEY_Z; - - @Expose - @ConfigOption(name = "Chat Filter Types", desc = "") - @ConfigEditorAccordion(id = 0) - public boolean filterTypes = false; - - @Expose - @ConfigOption(name = "Hypixel Hub", desc = "Block messages outside SkyBlock in the Hypixel lobby: player joins, loot boxes, prototype lobby messages, radiating generosity and Hypixel tournaments.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean hypixelHub = true; - - @Expose - @ConfigOption(name = "Empty", desc = "Hide all the empty messages from the chat.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean empty = true; - - @Expose - @ConfigOption(name = "Warping", desc = "Block 'sending request to join...' and 'warping...' messages.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean warping = true; - - @Expose - @ConfigOption(name = "Welcome", desc = "Hide the 'welcome to SkyBlock' message.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean welcome = true; - - @Expose - @ConfigOption(name = "Guild Exp", desc = "Hide guild exp messages.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean guildExp = true; - - @Expose - @ConfigOption(name = "Friend Join Left", desc = "Hide friend join/left messages.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean friendJoinLeft = false; - - @Expose - @ConfigOption(name = "Winter Gifts", desc = "Hide useless winter gift messages.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean winterGift = false; - - @Expose - @ConfigOption(name = "Powder Mining", desc = "Hide messages while opening chests in crystal hollows. " + - "(Except powder numbers over 1k, Prehistoric Egg and Automaton Parts)") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean powderMining = true; - - @Expose - @ConfigOption(name = "Kill Combo", desc = "Hide messages about the current kill combo from the Grandma Wolf Pet.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean killCombo = false; - - @Expose - @ConfigOption(name = "Watchdog", desc = "Hide the message where Hypixel is flexing how many players they have banned over the last week.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean watchDog = true; - - @Expose - @ConfigOption(name = "Profile Join", desc = "Hide 'You are playing on profile' and 'Profile ID' chat messages") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean profileJoin = true; - - //TODO remove - @Expose - @ConfigOption(name = "Others", desc = "Hide other annoying messages.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 0) - public boolean others = false; - - @Expose - @ConfigOption(name = "Player Messages", desc = "") - @ConfigEditorAccordion(id = 1) - public boolean playerMessages = false; - - @Expose - @ConfigOption(name = "Player Rank Hider", desc = "Hide player ranks in all chat messages.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 1) - public boolean playerRankHider = false; - - @Expose - @ConfigOption(name = "Chat Filter", desc = "Scan messages sent by players for blacklisted words and grey out the message if any are found.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 1) - public boolean chatFilter = false; - - @Expose - @ConfigOption(name = "Dungeon Filter", desc = "Hide annoying messages in dungeons.") - @ConfigEditorBoolean - public boolean dungeonMessages = true; - - @Expose - @ConfigOption(name = "Dungeon Boss Messages", desc = "Hide messages from the watcher and bosses in the dungeon.") - @ConfigEditorBoolean - public boolean dungeonBossMessages = false; - - @Expose - @ConfigOption(name = "Hide Far Deaths", desc = "Hide other players' death messages, " + - "except for players who are nearby or during dungeons/a Kuudra fight.") - @ConfigEditorBoolean - public boolean hideFarDeathMessages = false; - //TODO jawbus + thunder - - @Expose - @ConfigOption(name = "Compact Potion Message", desc = "Shorten chat messages about player potion effects.") - @ConfigEditorBoolean - public boolean compactPotionMessage = true; - - @Expose - @ConfigOption(name = "Arachne Hider", desc = "Hide chat messages about the Arachne Fight while outside of §eArachne's Sanctuary§7.") - @ConfigEditorBoolean - public boolean hideArachneMessages = false; -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java new file mode 100644 index 000000000..1723db1be --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java @@ -0,0 +1,145 @@ +package at.hannibal2.skyhanni.config.features; + +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigAccordionId; +import io.github.moulberry.moulconfig.annotations.ConfigEditorAccordion; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind; +import io.github.moulberry.moulconfig.annotations.ConfigOption; +import org.lwjgl.input.Keyboard; + +public class ChatConfig { + + @Expose + @ConfigOption(name = "Peek Chat", desc = "Hold this key to keep the chat open.") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_Z) + public int peekChat = Keyboard.KEY_Z; + + @Expose + @ConfigOption(name = "Chat Filter Types", desc = "") + @ConfigEditorAccordion(id = 0) + public boolean filterTypes = false; + + @Expose + @ConfigOption(name = "Hypixel Hub", desc = "Block messages outside SkyBlock in the Hypixel lobby: player joins, loot boxes, prototype lobby messages, radiating generosity and Hypixel tournaments.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean hypixelHub = true; + + @Expose + @ConfigOption(name = "Empty", desc = "Hide all the empty messages from the chat.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean empty = true; + + @Expose + @ConfigOption(name = "Warping", desc = "Block 'sending request to join...' and 'warping...' messages.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean warping = true; + + @Expose + @ConfigOption(name = "Welcome", desc = "Hide the 'welcome to SkyBlock' message.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean welcome = true; + + @Expose + @ConfigOption(name = "Guild Exp", desc = "Hide guild exp messages.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean guildExp = true; + + @Expose + @ConfigOption(name = "Friend Join Left", desc = "Hide friend join/left messages.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean friendJoinLeft = false; + + @Expose + @ConfigOption(name = "Winter Gifts", desc = "Hide useless winter gift messages.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean winterGift = false; + + @Expose + @ConfigOption(name = "Powder Mining", desc = "Hide messages while opening chests in crystal hollows. " + + "(Except powder numbers over 1k, Prehistoric Egg and Automaton Parts)") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean powderMining = true; + + @Expose + @ConfigOption(name = "Kill Combo", desc = "Hide messages about the current kill combo from the Grandma Wolf Pet.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean killCombo = false; + + @Expose + @ConfigOption(name = "Watchdog", desc = "Hide the message where Hypixel is flexing how many players they have banned over the last week.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean watchDog = true; + + @Expose + @ConfigOption(name = "Profile Join", desc = "Hide 'You are playing on profile' and 'Profile ID' chat messages") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean profileJoin = true; + + //TODO remove + @Expose + @ConfigOption(name = "Others", desc = "Hide other annoying messages.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean others = false; + + @Expose + @ConfigOption(name = "Player Messages", desc = "") + @ConfigEditorAccordion(id = 1) + public boolean playerMessages = false; + + @Expose + @ConfigOption(name = "Player Rank Hider", desc = "Hide player ranks in all chat messages.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean playerRankHider = false; + + @Expose + @ConfigOption(name = "Chat Filter", desc = "Scan messages sent by players for blacklisted words and grey out the message if any are found.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean chatFilter = false; + + @Expose + @ConfigOption(name = "Dungeon Filter", desc = "Hide annoying messages in dungeons.") + @ConfigEditorBoolean + public boolean dungeonMessages = true; + + @Expose + @ConfigOption(name = "Dungeon Boss Messages", desc = "Hide messages from the watcher and bosses in the dungeon.") + @ConfigEditorBoolean + public boolean dungeonBossMessages = false; + + @Expose + @ConfigOption(name = "Hide Far Deaths", desc = "Hide other players' death messages, " + + "except for players who are nearby or during dungeons/a Kuudra fight.") + @ConfigEditorBoolean + public boolean hideFarDeathMessages = false; + //TODO jawbus + thunder + + @Expose + @ConfigOption(name = "Compact Potion Message", desc = "Shorten chat messages about player potion effects.") + @ConfigEditorBoolean + public boolean compactPotionMessage = true; + + @Expose + @ConfigOption(name = "Compact Bestiary Message", desc = "Shorten the bestiary level up message, showing additional information when hovering.") + @ConfigEditorBoolean + public boolean compactBestiaryMessage = true; + + @Expose + @ConfigOption(name = "Arachne Hider", desc = "Hide chat messages about the Arachne Fight while outside of §eArachne's Sanctuary§7.") + @ConfigEditorBoolean + public boolean hideArachneMessages = false; +} 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() + 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 + + 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()) + } + } + } + } +} 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