diff options
6 files changed, 156 insertions, 42 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/DisplayConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/DisplayConfig.java index e960c5703..4f7a7c91a 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/DisplayConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/DisplayConfig.java @@ -9,6 +9,17 @@ import io.github.moulberry.moulconfig.annotations.ConfigEditorSlider; import io.github.moulberry.moulconfig.annotations.ConfigOption; public class DisplayConfig { + + @Expose + @ConfigOption(name = "Alignment Options", desc = "") + @Accordion + public AlignmentConfig alignment = new AlignmentConfig(); + + @Expose + @ConfigOption(name = "Title and Footer Options", desc = "") + @Accordion + public TitleAndFooterConfig titleAndFooter = new TitleAndFooterConfig(); + @Expose @ConfigOption(name = "Hide Vanilla Scoreboard", desc = "Hide the vanilla scoreboard." + "\n§cUsing mods that add their own scoreboard will not be affected by this setting!") @@ -32,6 +43,17 @@ public class DisplayConfig { @ConfigEditorBoolean public boolean showAllActiveEvents = false; + + @Expose + @ConfigOption(name = "Show Magical Power", desc = "Show your amount of Magical Power in the scoreboard.") + @ConfigEditorBoolean + public boolean showMagicalPower = true; + + @Expose + @ConfigOption(name = "Show Max Island Players", desc = "Show the maximum amount of players that can join your current island.") + @ConfigEditorBoolean + public boolean showMaxIslandPlayers = true; + @Expose @ConfigOption(name = "Number Format", desc = "") @ConfigEditorDropdown @@ -90,14 +112,4 @@ public class DisplayConfig { desc = "Will stop the Scoreboard from updating while switching islands.\nRemoves the shaking when loading data.") @ConfigEditorBoolean public boolean cacheScoreboardOnIslandSwitch = false; - - @Expose - @ConfigOption(name = "Alignment Options", desc = "") - @Accordion - public AlignmentConfig alignment = new AlignmentConfig(); - - @Expose - @ConfigOption(name = "Title and Footer Options", desc = "") - @Accordion - public TitleAndFooterConfig titleAndFooter = new TitleAndFooterConfig(); } diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 88c45566a..eb38187ca 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -54,6 +54,26 @@ class HypixelData { "lobbytype", "(?<lobbyType>.*lobby)\\d+" ) + private val playerAmountPattern by patternGroup.pattern( + "playeramount", + "^\\s*(?:§.)+Players (?:§.)+\\((?<amount>\\d+)\\)\\s*$" + ) + private val playerAmountCoopPattern by patternGroup.pattern( + "playeramount.coop", + "^\\s*(?:§.)*Coop (?:§.)*\\((?<amount>\\d+)\\)\\s*$" + ) + private val playerAmountGuestingPattern by patternGroup.pattern( + "playeramount.guesting", + "^\\s*(?:§.)*Guests (?:§.)*\\((?<amount>\\d+)\\)\\s*$" + ) + private val soloProfileAmountPattern by patternGroup.pattern( + "solo.profile.amount", + "^\\s*(?:§.)*Island\\s*$" + ) + private val scoreboardVisitingAmoutPattern by patternGroup.pattern( + "scoreboard.visiting.amount", + "\\s+§.✌ §.\\(§.(?<currentamount>\\d+)§.\\/(?<maxamount>\\d+)\\)" + ) private val guestPattern by patternGroup.pattern( "guesting.scoreboard", "SKYBLOCK GUEST" @@ -119,6 +139,36 @@ class HypixelData { return serverId } + fun getPlayersOnCurrentServer(): Int { + var amount = 0 + val playerPatternList = listOf( + playerAmountPattern, + playerAmountCoopPattern, + playerAmountGuestingPattern + ) + + out@for (pattern in playerPatternList) { + for (line in TabListData.getTabList()) { + pattern.matchMatcher(line) { + amount += group("amount").toInt() + continue@out + } + } + } + amount += TabListData.getTabList().count { soloProfileAmountPattern.matches(it) } + + return amount + } + + fun getMaxPlayersForCurrentServer(): Int { + for (line in ScoreboardData.sidebarLinesFormatted) { + scoreboardVisitingAmoutPattern.matchMatcher(line) { + return group("maxamount").toInt() + } + } + return if (serverId?.startsWith("mega") == true) 80 else 26 + } + // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw. private val jsonBracketPattern = "^\\{.+}".toPattern() 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 |