diff options
author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-03-16 16:14:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-16 16:14:08 +0100 |
commit | 7d8d2dffb98d78cade5f2b8fb5223d92cf66c6c8 (patch) | |
tree | 74f981aa260797f6edd995da8d9c64be69585b3f /src/main/java/at/hannibal2/skyhanni/features | |
parent | 4f696dca502d52d77a941c0504006878d2133d1f (diff) | |
download | skyhanni-7d8d2dffb98d78cade5f2b8fb5223d92cf66c6c8.tar.gz skyhanni-7d8d2dffb98d78cade5f2b8fb5223d92cf66c6c8.tar.bz2 skyhanni-7d8d2dffb98d78cade5f2b8fb5223d92cf66c6c8.zip |
Improvement + Fix: Custom Scoreboard Part 3 (#1183)
Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
4 files changed, 84 insertions, 32 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt index e260976e0..1ee86cdb7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt @@ -20,6 +20,7 @@ package at.hannibal2.skyhanni.features.gui.customscoreboard import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.GuiPositionMovedEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzTickEvent @@ -27,6 +28,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAlignedWidth +import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.TabListData import net.minecraftforge.client.GuiIngameForge import net.minecraftforge.client.event.RenderGameOverlayEvent @@ -53,7 +55,11 @@ class CustomScoreboard { } else { display } - config.position.renderStringsAlignedWidth(render, posLabel = guiName, extraSpace = displayConfig.lineSpacing - 10) + config.position.renderStringsAlignedWidth( + render, + posLabel = guiName, + extraSpace = displayConfig.lineSpacing - 10 + ) } @SubscribeEvent @@ -135,6 +141,24 @@ class CustomScoreboard { } } + @SubscribeEvent + fun onDebugDataCollect(event: DebugDataCollectEvent) { + event.title("Custom Scoreboard") + event.addIrrelevant { + if (!config.enabled) { + add("Custom Scoreboard disabled.") + } else { + ScoreboardElement.entries.map { element -> + add( + "${element.name.firstLetterUppercase()} - " + + "${element.showWhen.invoke()} - " + + "${element.getVisiblePair().map { it.first }}" + ) + } + } + } + } + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled private fun isHideVanillaScoreboardEnabled() = isEnabled() && config.displayConfig.hideVanillaScoreboard } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt index 15ce71ed9..0b9d7b1be 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt @@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.features.gui.customscoreboard import at.hannibal2.skyhanni.config.features.gui.customscoreboard.DisplayConfig.ArrowAmountDisplay import at.hannibal2.skyhanni.data.BitsAPI import at.hannibal2.skyhanni.data.HypixelData +import at.hannibal2.skyhanni.data.HypixelData.Companion.getMaxPlayersForCurrentServer +import at.hannibal2.skyhanni.data.HypixelData.Companion.getPlayersOnCurrentServer import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.MaxwellAPI import at.hannibal2.skyhanni.data.MayorAPI @@ -39,7 +41,7 @@ internal var amountOfUnknownLines = 0 enum class ScoreboardElement( private val displayPair: Supplier<List<ScoreboardElementType>>, - private val showWhen: () -> Boolean, + val showWhen: () -> Boolean, private val configLine: String ) { TITLE( @@ -106,6 +108,11 @@ enum class ScoreboardElement( { true }, "§7⏣ §bVillage" ), + PLAYER_AMOUNT( + ::getPlayerAmountDisplayPair, + { true }, + "§7Players: §a69§7/§a80" + ), VISITING( ::getVisitDisplayPair, ::getVisitShowWhen, @@ -124,12 +131,12 @@ enum class ScoreboardElement( LOBBY_CODE( ::getLobbyDisplayPair, { true }, - "§8m77CK" + "§8mega77CK" ), POWER( ::getPowerDisplayPair, ::getPowerShowWhen, - "Power: §aSighted" + "Power: §aSighted §7(§61.263§7)" ), COOKIE( ::getCookieDisplayPair, @@ -356,7 +363,7 @@ private fun getHeatDisplayPair(): List<ScoreboardElementType> { return listOf( when { informationFilteringConfig.hideEmptyLines && heat == "§c♨ 0" -> "<hidden>" - displayConfig.displayNumbersFirst -> if (heat == "0") "§c♨ 0 Heat" else "$heat Heat" + displayConfig.displayNumbersFirst/* && heat != "§6IMMUNE" */ -> if (heat == "0") "§c♨ 0 Heat" else "$heat Heat" else -> if (heat == "0") "Heat: §c♨ 0" else "Heat: $heat" } to HorizontalAlignment.LEFT ) @@ -392,10 +399,20 @@ private fun getLocationDisplayPair() = buildList { ScoreboardData.sidebarLinesFormatted, ScoreboardPattern.locationPattern, "location" - ).trim() to HorizontalAlignment.LEFT) + ).trim() to HorizontalAlignment.LEFT + ) + + ScoreboardData.sidebarLinesFormatted.firstOrNull { ScoreboardPattern.plotPattern.matches(it) } + ?.let { add(it to HorizontalAlignment.LEFT) } +} - val plotLine = ScoreboardData.sidebarLinesFormatted.firstOrNull { ScoreboardPattern.plotPattern.matches(it) } - if (plotLine != null) add(plotLine to HorizontalAlignment.LEFT) +fun getPlayerAmountDisplayPair() = buildList { + val max = if (displayConfig.showMaxIslandPlayers) { + "§7/§a${getMaxPlayersForCurrentServer()}" + } else { + "" + } + add("§7Players: §a${getPlayersOnCurrentServer()}$max" to HorizontalAlignment.LEFT) } private fun getVisitDisplayPair() = @@ -433,17 +450,16 @@ private fun getLobbyDisplayPair(): List<ScoreboardElementType> { } private fun getPowerDisplayPair() = listOf( - when (MaxwellAPI.currentPower) { - null -> "§cOpen \"Your Bags\"!" - else -> - if (displayConfig.displayNumbersFirst) { - "§a${MaxwellAPI.currentPower?.replace("Power", "")} Power " + - "§7(§6${MaxwellAPI.magicalPower}§7)" - } else { - "Power: §a${MaxwellAPI.currentPower?.replace("Power", "")} " + - "§7(§6${MaxwellAPI.magicalPower?.addSeparators()}§7)" - } - } to HorizontalAlignment.LEFT + (MaxwellAPI.currentPower?.let { + val mp = if (displayConfig.showMagicalPower) "§7(§6${MaxwellAPI.magicalPower?.addSeparators()}§7)" else "" + val name = it.replace(" Power", "") + if (displayConfig.displayNumbersFirst) { + "§a$name Power $mp" + } else { + "Power: §a$name $mp" + } + } + ?: "§cOpen \"Your Bags\"!") to HorizontalAlignment.LEFT ) private fun getPowerShowWhen() = !inAnyIsland(IslandType.THE_RIFT) @@ -499,8 +515,8 @@ private fun getSlayerDisplayPair(): List<ScoreboardElementType> = listOf( (" §7- §e${SlayerAPI.latestSlayerProgress.trim()}" to HorizontalAlignment.LEFT) ) -// TODO: Redo the Slayer showWhen -private fun getSlayerShowWhen() = true +private fun getSlayerShowWhen() = + if (informationFilteringConfig.hideIrrelevantLines) SlayerAPI.isInCorrectArea else true private fun getQuiverDisplayPair(): List<ScoreboardElementType> { if (QuiverAPI.currentArrow == null) @@ -509,7 +525,10 @@ private fun getQuiverDisplayPair(): List<ScoreboardElementType> { return listOf("No Arrows selected" to HorizontalAlignment.LEFT) val amountString = (if (displayConfig.colorArrowAmount) { - percentageColor(QuiverAPI.currentAmount.toLong(), QuiverAPI.MAX_ARROW_AMOUNT.toLong()).getChatColor() + percentageColor( + QuiverAPI.currentAmount.toLong(), + QuiverAPI.MAX_ARROW_AMOUNT.toLong() + ).getChatColor() } else { "" }) + when (displayConfig.arrowAmountDisplay) { @@ -534,17 +553,25 @@ private fun getQuiverShowWhen(): Boolean { private fun getPowderDisplayPair() = buildList { val mithrilPowder = - getGroupFromPattern(TabListData.getTabList(), ScoreboardPattern.mithrilPowderPattern, "mithrilpowder") + getGroupFromPattern( + TabListData.getTabList(), + ScoreboardPattern.mithrilPowderPattern, + "mithrilpowder" + ) .formatNum() val gemstonePowder = - getGroupFromPattern(TabListData.getTabList(), ScoreboardPattern.gemstonePowderPattern, "gemstonepowder") + getGroupFromPattern( + TabListData.getTabList(), + ScoreboardPattern.gemstonePowderPattern, + "gemstonepowder" + ) .formatNum() - add("§9§lPowder" to HorizontalAlignment.LEFT) - if (informationFilteringConfig.hideEmptyLines && mithrilPowder == "0" && gemstonePowder == "0") { - add(0, "<hidden>" to HorizontalAlignment.LEFT) + add("<hidden>" to HorizontalAlignment.LEFT) } else { + add("§9§lPowder" to HorizontalAlignment.LEFT) + if (displayConfig.displayNumbersFirst) { add(" §7- §2$mithrilPowder Mithril" to HorizontalAlignment.LEFT) add(" §7- §d$gemstonePowder Gemstone" to HorizontalAlignment.LEFT) @@ -570,7 +597,7 @@ private fun getMayorDisplayPair() = buildList { ((MayorAPI.currentMayor?.mayorName?.let { MayorAPI.mayorNameWithColorCode(it) } ?: "<hidden>") + (if (config.mayorConfig.showTimeTillNextMayor) { - "§7 (§e${MayorAPI.timeTillNextMayor.format()}§7)" + "§7 (§e${MayorAPI.timeTillNextMayor.format(maxUnits = 2)}§7)" } else { "" })) to HorizontalAlignment.LEFT @@ -594,7 +621,7 @@ private fun getPartyDisplayPair() = val partyList = PartyAPI.partyMembers .take(config.partyConfig.maxPartyList.get()) .map { - " §7- §7$it" + " §7- §f$it" } .toTypedArray() listOf(title, *partyList).map { it to HorizontalAlignment.LEFT } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardEvents.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardEvents.kt index 8035361af..dfe5a0d3a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardEvents.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardEvents.kt @@ -129,7 +129,6 @@ enum class ScoreboardEvents(private val displayLine: Supplier<List<String>>, pri ::getRedstoneShowWhen ), - // Maybe as a default state, use tablist "Events: ..." NONE( ::getNoneLines, { false } @@ -251,7 +250,9 @@ private fun getJacobContestLines() = buildList { add(line) getSbLines().nextAfter(line)?.let { add(it) } getSbLines().nextAfter(line, 2)?.let { add(it) } - getSbLines().nextAfter(line, 3)?.let { add(it) } + getSbLines().nextAfter(line, 3)?.let { + if (!SbPattern.footerPattern.matches(it)) add(it) + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/UnknownLinesHandler.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/UnknownLinesHandler.kt index 7fdac515a..397aa713a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/UnknownLinesHandler.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/UnknownLinesHandler.kt @@ -14,7 +14,7 @@ object UnknownLinesHandler { fun handleUnknownLines() { val sidebarLines = ScoreboardData.sidebarLinesFormatted - unknownLines = sidebarLines.toMutableList().filter { it.isNotBlank() }.map { it.removeResets() } + unknownLines = sidebarLines.toMutableList().map { it.removeResets() }.filter { it.isNotBlank() } /* * remove with pattern |