diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-04-18 00:59:11 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 16:59:11 +0200 |
commit | 05fd8b3dbe18ac8e23f2adc4a0a792d6435095d6 (patch) | |
tree | edc31e53302e96162e9ee8b00c63de8332bfb060 /src/main/java/at/hannibal2 | |
parent | 7c85b30db375d968b4a969fd19301b399001dbc2 (diff) | |
download | skyhanni-05fd8b3dbe18ac8e23f2adc4a0a792d6435095d6.tar.gz skyhanni-05fd8b3dbe18ac8e23f2adc4a0a792d6435095d6.tar.bz2 skyhanni-05fd8b3dbe18ac8e23f2adc4a0a792d6435095d6.zip |
Backend: Make TablistFooterUpdateEvent and cleanup TabListData (#1355)
Diffstat (limited to 'src/main/java/at/hannibal2')
7 files changed, 127 insertions, 122 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index bce2dec95..4ef7c0563 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -475,7 +475,7 @@ class SkyHanniMod { loadModule(RenderLivingEntityHelper()) loadModule(SkillExperience()) loadModule(OtherInventoryData) - loadModule(TabListData()) + loadModule(TabListData) loadModule(RenderData()) loadModule(GardenCropMilestones) loadModule(GardenCropMilestonesCommunityFix) diff --git a/src/main/java/at/hannibal2/skyhanni/events/TablistFooterUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/TablistFooterUpdateEvent.kt new file mode 100644 index 000000000..6f12e99bc --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/TablistFooterUpdateEvent.kt @@ -0,0 +1,3 @@ +package at.hannibal2.skyhanni.events + +class TablistFooterUpdateEvent(val footer: String) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardUtils.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardUtils.kt index d93e40503..36774faa5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboardUtils.kt @@ -35,9 +35,7 @@ object CustomScoreboardUtils { } fun getTablistFooter(): String { - val tabList = TabListData.getPlayerTabOverlay() - if (tabList.footer_skyhanni == null) return "" - return tabList.footer_skyhanni.formattedText.replace("§r", "") + return TabListData.getFooter().removeResets() } internal fun Number.formatNum(): String = when (displayConfig.numberFormat) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt index 88ac4bc1b..5c037eecb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt @@ -5,6 +5,8 @@ import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.utils.ConditionalUtils import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.findMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeResets import at.hannibal2.skyhanni.utils.StringUtils.removeSFormattingCode import at.hannibal2.skyhanni.utils.StringUtils.trimWhiteSpaceAndResets @@ -46,6 +48,10 @@ object TabListReader { "upgrades", "(?<firstPart>§e[A-Za-z ]+)(?<secondPart> §f[\\w ]+)" ) + private val winterPowerUpsPattern by patternGroup.pattern( + "winterpowerups", + "Active Power Ups(?:§.)*(?:\\n(§.)*§7.+)*" + ) var hypixelAdvertisingString = "HYPIXEL.NET" @@ -103,53 +109,51 @@ object TabListReader { } private fun parseFooterAsColumn(): TabColumn? { - val tabList = TabListData.getPlayerTabOverlay() - - if (tabList.footer_skyhanni == null) { - return null + var footer = TabListData.getFooter().removeSFormattingCode() + if (footer.isEmpty()) return null + + footer = godPotPattern.findMatcher(footer) { + activeEffectPattern.matcher(footer) + .replaceAll("Active Effects:\n§cGod Potion§r: ${group("timer")}") + } ?: run { + effectCountPattern.findMatcher(footer) { + activeEffectPattern.matcher(footer).replaceAll("Active Effects: §r§e" + group("effectCount")) + } ?: activeEffectPattern.matcher(footer).replaceAll("Active Effects: §r§e0") } - val column = TabColumn("§2§lOther") - - var footer = tabList.footer_skyhanni.formattedText.removeSFormattingCode() - - var matcher = godPotPattern.matcher(tabList.footer_skyhanni.unformattedText) - if (matcher.find()) { - footer = activeEffectPattern.matcher(footer) - .replaceAll("Active Effects:\n§cGod Potion§r: ${matcher.group("timer")}") - } else { - matcher = effectCountPattern.matcher(tabList.footer_skyhanni.unformattedText) - footer = if (matcher.find()) { - activeEffectPattern.matcher(footer).replaceAll("Active Effects: §r§e" + matcher.group("effectCount")) - } else { - activeEffectPattern.matcher(footer).replaceAll("Active Effects: §r§e0") + cookiePattern.findMatcher(footer) { + if (group().contains("Not active!")) { + footer = this.replaceAll("Cookie Buff \n§r§7Not Active") } } - matcher = cookiePattern.matcher(footer) - if (matcher.find() && matcher.group().contains("Not active!")) { - footer = matcher.replaceAll("Cookie Buff \n§r§7Not Active") + dungeonBuffPattern.findMatcher(footer) { + if (group().contains("No Buffs active.")) { + footer = this.replaceAll("Dungeon Buffs \n§r§7None Found") + } } - matcher = dungeonBuffPattern.matcher(footer) - if (matcher.find() && matcher.group().contains("No Buffs active.")) { - footer = matcher.replaceAll("Dungeon Buffs \n§r§7None Found") + winterPowerUpsPattern.findMatcher(footer) { + if (group().contains("No Power Ups active.")) { + footer = this.replaceAll("Active Power Ups \n§r§7None") + } } + val column = TabColumn("§2§lOther") + for (line in footer.split("\n")) { if (line.contains(hypixelAdvertisingString)) continue var newLine = line - matcher = upgradesPattern.matcher(newLine.removeResets()) - if (matcher.matches()) { - var firstPart = matcher.group("firstPart").trimWhiteSpaceAndResets() + upgradesPattern.matchMatcher(newLine.removeResets()) { + var firstPart = group("firstPart").trimWhiteSpaceAndResets() if (!firstPart.contains("§l")) { firstPart = " $firstPart" } column.addLine(firstPart) - newLine = matcher.group("secondPart") + newLine = group("secondPart") } newLine = newLine.trimWhiteSpaceAndResets() @@ -205,8 +209,8 @@ object TabListReader { var currentCount = firstColumnCopy.size() - if (sectionSize >= TabListRenderer.maxLines / 2) { - if (currentCount >= TabListRenderer.maxLines) { + if (sectionSize >= TabListRenderer.MAX_LINES / 2) { + if (currentCount >= TabListRenderer.MAX_LINES) { renderColumns.add(RenderColumn().also { firstColumnCopy = it }) currentCount = 1 } else { @@ -222,7 +226,7 @@ object TabListReader { } for (line in section.lines) { - if (currentCount >= TabListRenderer.maxLines) { + if (currentCount >= TabListRenderer.MAX_LINES) { renderColumns.add(RenderColumn().also { firstColumnCopy = it }) currentCount = 1 } @@ -231,7 +235,7 @@ object TabListReader { currentCount++ } } else { - if (currentCount + sectionSize > TabListRenderer.maxLines) { + if (currentCount + sectionSize > TabListRenderer.MAX_LINES) { renderColumns.add(RenderColumn().also { firstColumnCopy = it }) } else { if (firstColumnCopy.size() > 0) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListRenderer.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListRenderer.kt index 8bd2bfefe..dfeabe5ed 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListRenderer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListRenderer.kt @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.filterToMutable import at.hannibal2.skyhanni.utils.KeyboardManager.isActive import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.matches -import at.hannibal2.skyhanni.utils.TabListData.Companion.getPlayerTabOverlay +import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraft.client.gui.Gui @@ -22,10 +22,11 @@ object TabListRenderer { private val config get() = SkyHanniMod.feature.gui.compactTabList - const val maxLines = 22 - private const val lineHeight = 8 + 1 - private const val padding = 3 - private const val columnSpacing = 6 + const val MAX_LINES = 22 + private const val LINE_HEIGHT = 8 + 1 + private const val TAB_PADDING = 3 + private const val COLUMN_SPACING = 6 + private const val TAB_Z_OFFSET = 10f @SubscribeEvent fun onRenderOverlay(event: RenderGameOverlayEvent.Pre) { @@ -63,46 +64,37 @@ object TabListRenderer { } } - private val tabZOffest = 10f - private fun drawTabList() { val columns = TabListReader.renderColumns if (columns.isEmpty()) return - GlStateManager.translate(0f, 0f, tabZOffest) + GlStateManager.translate(0f, 0f, TAB_Z_OFFSET) var maxLines = 0 - var totalWidth = 0 - columnSpacing + var totalWidth = 0 - COLUMN_SPACING for (column in columns) { maxLines = maxLines.coerceAtLeast(column.size()) - totalWidth += column.getMaxWidth() + columnSpacing + totalWidth += column.getMaxWidth() + COLUMN_SPACING } - var totalHeight = maxLines * lineHeight - val tabList = getPlayerTabOverlay() + var totalHeight = maxLines * LINE_HEIGHT var header = listOf<String>() - if (tabList.header_skyhanni != null) { - header = tabList.header_skyhanni.formattedText.split("\n").toMutableList() + + if (!config.hideAdverts) { + header = TabListData.getHeader().split("\n").toMutableList() header.removeIf { line -> !line.contains(TabListReader.hypixelAdvertisingString) } - if (config.hideAdverts) { - header = listOf() - } else { - totalHeight += header.size * lineHeight + padding - } + totalHeight += header.size * LINE_HEIGHT + TAB_PADDING } var footer = listOf<String>() - if (tabList.footer_skyhanni != null) { - footer = tabList.footer_skyhanni.formattedText.split("\n").toMutableList() + + if (!config.hideAdverts) { + footer = TabListData.getFooter().split("\n").toMutableList() footer.removeIf { line -> !line.contains(TabListReader.hypixelAdvertisingString) } - if (config.hideAdverts) { - footer = listOf() - } else { - totalHeight += footer.size * lineHeight + padding - } + totalHeight += footer.size * LINE_HEIGHT + TAB_PADDING } val minecraft = Minecraft.getMinecraft() @@ -112,10 +104,10 @@ object TabListRenderer { val y = 10 Gui.drawRect( - x - columnSpacing, - y - padding, - screenWidth + totalWidth / 2 + columnSpacing, - 10 + totalHeight + padding, + x - COLUMN_SPACING, + y - TAB_PADDING, + screenWidth + totalWidth / 2 + COLUMN_SPACING, + 10 + totalHeight + TAB_PADDING, -0x80000000 ) @@ -136,7 +128,7 @@ object TabListRenderer { var lastTitle: TabLine? = null var lastSubTitle: TabLine? = null for (originalColumn in columns) { - var middleY = if (config.hideAdverts) headerY else headerY + padding + 2 + var middleY = if (config.hideAdverts) headerY else headerY + TAB_PADDING + 2 val column = originalColumn.lines.filterToMutable { tabLine -> if (tabLine.type == TabStringType.TITLE) { @@ -150,10 +142,10 @@ object TabListRenderer { }.let(::RenderColumn) Gui.drawRect( - middleX - padding + 1, - middleY - padding + 1, - middleX + column.getMaxWidth() + padding - 2, - middleY + column.size() * lineHeight + padding - 2, + middleX - TAB_PADDING + 1, + middleY - TAB_PADDING + 1, + middleX + column.getMaxWidth() + TAB_PADDING - 2, + middleY + column.size() * LINE_HEIGHT + TAB_PADDING - 2, 0x20AAAAAA ) @@ -193,14 +185,14 @@ object TabListRenderer { 0xFFFFFF ) } - middleY += lineHeight + middleY += LINE_HEIGHT middleX = savedX } - middleX += column.getMaxWidth() + columnSpacing + middleX += column.getMaxWidth() + COLUMN_SPACING } if (footer.isNotEmpty()) { - var footerY = y + totalHeight - footer.size * lineHeight + padding / 2 + 1 + var footerY = y + totalHeight - footer.size * LINE_HEIGHT + TAB_PADDING / 2 + 1 for (line in footer) { minecraft.fontRendererObj.drawStringWithShadow( line, @@ -208,15 +200,15 @@ object TabListRenderer { footerY.toFloat(), -0x1 ) - footerY += lineHeight + footerY += LINE_HEIGHT } } - GlStateManager.translate(0f, 0f, -tabZOffest) + GlStateManager.translate(0f, 0f, -TAB_Z_OFFSET) } private val fireSalePattern by RepoPattern.pattern( "tablist.firesaletitle", - "§b§lFire Sales: §r§f\\([0-9]+\\)" + "§.§lFire Sales: §r§f\\([0-9]+\\)" ) @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt index 46a6f5ba4..d6debfa4a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt @@ -21,7 +21,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.utils.TabListData.Companion.getTabList +import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.TimeUtils.formatted import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay.getCurrentPet @@ -40,7 +40,7 @@ val motesRegex = Regex("""Motes: ([\d,]+)""") val bitsRegex = Regex("""Bits: ([\d|,]+)[\d|.]*""") private fun getVisitingName(): String { - val tabData = getTabList() + val tabData = TabListData.getTabList() val ownerRegex = Regex(".*Owner: (\\w+).*") for (line in tabData) { val colorlessLine = line.removeColor() @@ -146,7 +146,7 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) PROFILE({ val player = LorenzUtils.getPlayerName() - val tabData = getTabList() + val tabData = TabListData.getTabList() val levelRegex = Regex("""\[(\d{1,3})] $player""") var sbLevel = "" // SkyBlock Level: [999] on Lemon diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt index a2d275123..e37dda613 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.events.TablistFooterUpdateEvent import at.hannibal2.skyhanni.mixins.hooks.tabListGuard import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiPlayerTabOverlay import at.hannibal2.skyhanni.utils.ConditionalUtils.conditionalTransform @@ -18,55 +19,53 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -class TabListData { +object TabListData { + private var tablistCache = emptyList<String>() + private var debugCache: List<String>? = null - companion object { + private var header = "" + private var footer = "" - private var cache = emptyList<String>() - private var debugCache: List<String>? = null - var fullyLoaded = false + var fullyLoaded = false - // TODO replace with TabListUpdateEvent - fun getTabList() = debugCache ?: cache + // TODO replace with TabListUpdateEvent + fun getTabList() = debugCache ?: tablistCache + fun getHeader() = header + fun getFooter() = footer - fun toggleDebugCommand() { - if (debugCache != null) { - ChatUtils.chat("Disabled tab list debug.") - debugCache = null - return - } - SkyHanniMod.coroutineScope.launch { - val clipboard = OSUtils.readFromClipboard() ?: return@launch - debugCache = clipboard.lines() - ChatUtils.chat("Enabled tab list debug with your clipboard.") - } + fun toggleDebugCommand() { + if (debugCache != null) { + ChatUtils.chat("Disabled tab list debug.") + debugCache = null + return } + SkyHanniMod.coroutineScope.launch { + val clipboard = OSUtils.readFromClipboard() ?: return@launch + debugCache = clipboard.lines() + ChatUtils.chat("Enabled tab list debug with your clipboard.") + } + } - fun copyCommand(args: Array<String>) { - if (debugCache != null) { - ChatUtils.clickableChat("Tab list debug is enabled!", "shdebugtablist") - return - } - - val resultList = mutableListOf<String>() - val noColor = args.size == 1 && args[0] == "true" - for (line in getTabList()) { - val tabListLine = line.transformIf({ noColor }) { removeColor() } - if (tabListLine != "") resultList.add("'$tabListLine'") - } - val tabList = getPlayerTabOverlay() - val tabHeader = - tabList.header_skyhanni.conditionalTransform(noColor, { unformattedText }, { formattedText }) - val tabFooter = - tabList.footer_skyhanni.conditionalTransform(noColor, { unformattedText }, { formattedText }) - val string = "Header:\n\n$tabHeader\n\nBody:\n\n${resultList.joinToString("\n")}\n\nFooter:\n\n$tabFooter" - OSUtils.copyToClipboard(string) - ChatUtils.chat("Tab list copied into the clipboard!") + fun copyCommand(args: Array<String>) { + if (debugCache != null) { + ChatUtils.clickableChat("Tab list debug is enabled!", "shdebugtablist") + return } - fun getPlayerTabOverlay(): AccessorGuiPlayerTabOverlay { - return Minecraft.getMinecraft().ingameGUI.tabList as AccessorGuiPlayerTabOverlay + val resultList = mutableListOf<String>() + val noColor = args.size == 1 && args[0] == "true" + for (line in getTabList()) { + val tabListLine = line.transformIf({ noColor }) { removeColor() } + if (tabListLine != "") resultList.add("'$tabListLine'") } + + val tabHeader = header.conditionalTransform(noColor, { this.removeColor() }, { this }) + val tabFooter = footer.conditionalTransform(noColor, { this.removeColor() }, { this }) + + val string = "Header:\n\n$tabHeader\n\nBody:\n\n${resultList.joinToString("\n")}\n\nFooter:\n\n$tabFooter" + + OSUtils.copyToClipboard(string) + ChatUtils.chat("Tab list copied into the clipboard!") } private val playerOrdering = Ordering.from(PlayerComparator()) @@ -107,9 +106,18 @@ class TabListData { if (!event.isMod(2)) return val tabList = readTabList() ?: return - if (cache != tabList) { - cache = tabList + if (tablistCache != tabList) { + tablistCache = tabList TabListUpdateEvent(getTabList()).postAndCatch() } + + val tabListOverlay = Minecraft.getMinecraft().ingameGUI.tabList as AccessorGuiPlayerTabOverlay + header = tabListOverlay.header_skyhanni?.formattedText ?: "" + + val tabFooter = tabListOverlay.footer_skyhanni?.formattedText ?: "" + if (tabFooter != footer && tabFooter != "") { + TablistFooterUpdateEvent(tabFooter).postAndCatch() + } + footer = tabFooter } } |