diff options
author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-04-30 13:15:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 13:15:29 +0200 |
commit | c56134c0237aeaeebaf6133394f1c9547b8765fa (patch) | |
tree | 0294f993bc344d7b147c7ed71ffecf637a22a55a /src/main/java/at/hannibal2 | |
parent | 66f589488363e2dd84e3f611382a5705a8e8b2fc (diff) | |
download | skyhanni-c56134c0237aeaeebaf6133394f1c9547b8765fa.tar.gz skyhanni-c56134c0237aeaeebaf6133394f1c9547b8765fa.tar.bz2 skyhanni-c56134c0237aeaeebaf6133394f1c9547b8765fa.zip |
Backend: Cleanup Custom Scoreboard code (#1486)
Diffstat (limited to 'src/main/java/at/hannibal2')
3 files changed, 55 insertions, 124 deletions
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 e3569a856..ddd823990 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 @@ -251,9 +251,7 @@ enum class ScoreboardElement( ), ; - override fun toString(): String { - return configLine - } + override fun toString() = configLine fun getVisiblePair() = if (isVisible()) getPair() else listOf("<hidden>" to HorizontalAlignment.LEFT) @@ -619,11 +617,11 @@ private fun getObjectiveDisplayPair() = buildList { private fun getObjectiveShowWhen(): Boolean = ScoreboardPattern.objectivePattern.anyMatches(ScoreboardData.sidebarLinesFormatted) -private fun getSlayerDisplayPair(): List<ScoreboardElementType> = listOf( - (if (SlayerAPI.hasActiveSlayerQuest()) "Slayer Quest" else "<hidden>") to HorizontalAlignment.LEFT, - (" §7- §e${SlayerAPI.latestSlayerCategory.trim()}" to HorizontalAlignment.LEFT), - (" §7- §e${SlayerAPI.latestSlayerProgress.trim()}" to HorizontalAlignment.LEFT) -) +private fun getSlayerDisplayPair(): List<ScoreboardElementType> = buildList { + add((if (SlayerAPI.hasActiveSlayerQuest()) "Slayer Quest" else "<hidden>") to HorizontalAlignment.LEFT) + add(" §7- §e${SlayerAPI.latestSlayerCategory.trim()}" to HorizontalAlignment.LEFT) + add(" §7- §e${SlayerAPI.latestSlayerProgress.trim()}" to HorizontalAlignment.LEFT) +} private fun getSlayerShowWhen() = if (informationFilteringConfig.hideIrrelevantLines) SlayerAPI.isInCorrectArea else true 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 f9b862e59..78f73cc13 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 @@ -122,7 +122,7 @@ enum class ScoreboardEvents( ), MINING_EVENTS( ::getMiningEventsLines, - ::getMiningEventsShowWhen, + { inAdvancedMiningIsland() }, "§7(All Mining Event Lines)" ), DAMAGE( @@ -167,13 +167,9 @@ enum class ScoreboardEvents( ), ; - override fun toString(): String { - return configLine - } + override fun toString() = configLine - fun getLines(): List<String> { - return displayLine.get() - } + fun getLines(): List<String> = displayLine.get() companion object { fun getEvent() = buildList<ScoreboardEvents?> { @@ -232,18 +228,14 @@ private fun getVotingLines() = buildList { } } -private fun getVotingShowWhen(): Boolean { - return SbPattern.yearVotesPattern.anyMatches(getSbLines()) -} +private fun getVotingShowWhen(): Boolean = SbPattern.yearVotesPattern.anyMatches(getSbLines()) private fun getServerCloseLines() = buildList { val matchingLine = getSbLines().first { ServerRestartTitle.restartingGreedyPattern.matches(it) } add(matchingLine.split("§8")[0]) } -private fun getServerCloseShowWhen(): Boolean { - return ServerRestartTitle.restartingGreedyPattern.anyMatches(getSbLines()) -} +private fun getServerCloseShowWhen(): Boolean = ServerRestartTitle.restartingGreedyPattern.anyMatches(getSbLines()) private fun getDungeonsLines() = listOf( SbPattern.m7dragonsPattern, @@ -256,7 +248,7 @@ private fun getDungeonsLines() = listOf( SbPattern.teammatesPattern, SbPattern.floor3GuardiansPattern ).let { patterns -> - // BetterMap adds a random §r at the start, making it go black + // BetterMap adds a random §r at the start, making the line go black getSbLines().filter { line -> patterns.any { it.matches(line) } }.map { it.removePrefix("§r") } } @@ -275,9 +267,7 @@ private fun getKuudraLines() = listOf( getSbLines().firstOrNull { pattern.matches(it) } } -private fun getKuudraShowWhen(): Boolean { - return IslandType.KUUDRA_ARENA.isInIsland() -} +private fun getKuudraShowWhen(): Boolean = IslandType.KUUDRA_ARENA.isInIsland() private fun getDojoLines() = listOf( SbPattern.dojoChallengePattern, @@ -289,9 +279,7 @@ private fun getDojoLines() = listOf( getSbLines().firstOrNull { pattern.matches(it) } } -private fun getDojoShowWhen(): Boolean { - return SbPattern.dojoChallengePattern.anyMatches(getSbLines()) -} +private fun getDojoShowWhen(): Boolean = SbPattern.dojoChallengePattern.anyMatches(getSbLines()) private fun getDarkAuctionLines() = buildList { getSbLines().firstOrNull { SbPattern.startingInPattern.matches(it) }?.let { add(it) } @@ -305,9 +293,7 @@ private fun getDarkAuctionLines() = buildList { } } -private fun getDarkAuctionShowWhen(): Boolean { - return IslandType.DARK_AUCTION.isInIsland() -} +private fun getDarkAuctionShowWhen(): Boolean = IslandType.DARK_AUCTION.isInIsland() private fun getJacobContestLines() = buildList { getSbLines().firstOrNull { SbPattern.jacobsContestPattern.matches(it) }?.let { line -> @@ -320,17 +306,11 @@ private fun getJacobContestLines() = buildList { } } -private fun getJacobContestShowWhen(): Boolean { - return SbPattern.jacobsContestPattern.anyMatches(getSbLines()) -} +private fun getJacobContestShowWhen(): Boolean = SbPattern.jacobsContestPattern.anyMatches(getSbLines()) -private fun getJacobMedalsLines(): List<String> { - return getSbLines().filter { SbPattern.medalsPattern.matches(it) } -} +private fun getJacobMedalsLines(): List<String> = getSbLines().filter { SbPattern.medalsPattern.matches(it) } -private fun getJacobMedalsShowWhen(): Boolean { - return SbPattern.medalsPattern.anyMatches(getSbLines()) -} +private fun getJacobMedalsShowWhen(): Boolean = SbPattern.medalsPattern.anyMatches(getSbLines()) private fun getTrapperLines() = buildList { getSbLines().firstOrNull { SbPattern.peltsPattern.matches(it) }?.let { add(it) } @@ -342,35 +322,23 @@ private fun getTrapperLines() = buildList { } } -private fun getTrapperShowWhen(): Boolean { - return getSbLines().any { - ScoreboardPattern.peltsPattern.matches(it) || ScoreboardPattern.mobLocationPattern.matches(it) - } -} +private fun getTrapperShowWhen(): Boolean = + getSbLines().any { ScoreboardPattern.peltsPattern.matches(it) || ScoreboardPattern.mobLocationPattern.matches(it) } -private fun getGardenCleanUpLines(): List<String> { - return listOf(getSbLines().first { SbPattern.cleanUpPattern.matches(it) }.trim()) -} +private fun getGardenCleanUpLines(): List<String> = + listOf(getSbLines().first { SbPattern.cleanUpPattern.matches(it) }.trim()) -private fun getGardenCleanUpShowWhen(): Boolean { - return SbPattern.cleanUpPattern.anyMatches(getSbLines()) -} +private fun getGardenCleanUpShowWhen(): Boolean = SbPattern.cleanUpPattern.anyMatches(getSbLines()) -private fun getGardenPastingLines(): List<String> { - return listOf(getSbLines().first { SbPattern.pastingPattern.matches(it) }.trim()) -} +private fun getGardenPastingLines(): List<String> = + listOf(getSbLines().first { SbPattern.pastingPattern.matches(it) }.trim()) -private fun getGardenPastingShowWhen(): Boolean { - return SbPattern.pastingPattern.anyMatches(getSbLines()) -} +private fun getGardenPastingShowWhen(): Boolean = SbPattern.pastingPattern.anyMatches(getSbLines()) -private fun getFlightDurationLines(): List<String> { - return listOf(getSbLines().first { SbPattern.flightDurationPattern.matches(it) }.trim()) -} +private fun getFlightDurationLines(): List<String> = + listOf(getSbLines().first { SbPattern.flightDurationPattern.matches(it) }.trim()) -private fun getFlightDurationShowWhen(): Boolean { - return SbPattern.flightDurationPattern.anyMatches(getSbLines()) -} +private fun getFlightDurationShowWhen(): Boolean = SbPattern.flightDurationPattern.anyMatches(getSbLines()) private fun getWinterLines() = buildList { getSbLines().firstOrNull { SbPattern.winterEventStartPattern.matches(it) }?.let { add(it) } @@ -381,13 +349,11 @@ private fun getWinterLines() = buildList { getSbLines().firstOrNull { SbPattern.winterCubeDmgPattern.matches(it) }?.let { add(it) } } -private fun getWinterShowWhen(): Boolean { - return getSbLines().any { +private fun getWinterShowWhen(): Boolean = getSbLines().any { ScoreboardPattern.winterEventStartPattern.matches(it) || (ScoreboardPattern.winterNextWavePattern.matches(it) && !it.endsWith("Soon!")) || ScoreboardPattern.winterWavePattern.matches(it) } -} private fun getSpookyLines() = buildList { getSbLines().firstOrNull { SbPattern.spookyPattern.matches(it) }?.let { add(it) } // Time @@ -401,9 +367,7 @@ private fun getSpookyLines() = buildList { ) // Candy } -private fun getSpookyShowWhen(): Boolean { - return getSbLines().any { ScoreboardPattern.spookyPattern.matches(it) } -} +private fun getSpookyShowWhen(): Boolean = getSbLines().any { ScoreboardPattern.spookyPattern.matches(it) } private fun getActiveEventLine(): List<String> { val currentActiveEvent = TabListData.getTabList().firstOrNull { SbPattern.eventNamePattern.matches(it) } @@ -422,18 +386,14 @@ private fun getActiveEventLine(): List<String> { return listOf("$currentActiveEvent $currentActiveEventEndsIn") } -private fun getActiveEventShowWhen(): Boolean { - return TabListData.getTabList().any { SbPattern.eventNamePattern.matches(it) } && +private fun getActiveEventShowWhen(): Boolean = + TabListData.getTabList().any { SbPattern.eventNamePattern.matches(it) } && TabListData.getTabList().any { SbPattern.eventTimeEndsPattern.matches(it) } -} -private fun getBroodmotherLines(): List<String> { - return listOf(getSbLines().first { SbPattern.broodmotherPattern.matches(it) }) -} +private fun getBroodmotherLines(): List<String> = + listOf(getSbLines().first { SbPattern.broodmotherPattern.matches(it) }) -private fun getBroodmotherShowWhen(): Boolean { - return getSbLines().any { SbPattern.broodmotherPattern.matches(it) } -} +private fun getBroodmotherShowWhen(): Boolean = getSbLines().any { SbPattern.broodmotherPattern.matches(it) } private fun getMiningEventsLines() = buildList { // Wind @@ -495,19 +455,13 @@ private fun getMiningEventsLines() = buildList { } } -private fun getMiningEventsShowWhen(): Boolean { - return inAdvancedMiningIsland() -} - -private fun getDamageLines(): List<String> { - return listOf(getSbLines().first { SbPattern.bossHPPattern.matches(it) }) + +private fun getDamageLines(): List<String> = + listOf(getSbLines().first { SbPattern.bossHPPattern.matches(it) }) + (getSbLines().first { SbPattern.bossDamagePattern.matches(it) }) -} -private fun getDamageShowWhen(): Boolean { - return getSbLines().any { SbPattern.bossHPPattern.matches(it) } +private fun getDamageShowWhen(): Boolean = + getSbLines().any { SbPattern.bossHPPattern.matches(it) } && getSbLines().any { SbPattern.bossDamagePattern.matches(it) } -} private fun getMagmaBossLines() = getSbLines().filter { line -> SbPattern.magmaBossPattern.matches(line) @@ -519,47 +473,26 @@ private fun getMagmaBossLines() = getSbLines().filter { line -> || SbPattern.bossHealthBarPattern.matches(line) } -private fun getMagmaBossShowWhen(): Boolean { - return SbPattern.magmaChamberPattern.matches(HypixelData.skyBlockArea) -} - -private fun getRiftLines() = buildList { - if (SbPattern.riftHotdogTitlePattern.anyMatches(getSbLines())) { - add(getSbLines().first { SbPattern.riftHotdogTitlePattern.matches(it) }) - add(getSbLines().first { SbPattern.timeLeftPattern.matches(it) }) - add(getSbLines().first { SbPattern.riftHotdogEatenPattern.matches(it) }) - } +private fun getMagmaBossShowWhen(): Boolean = SbPattern.magmaChamberPattern.matches(HypixelData.skyBlockArea) - if (RiftBloodEffigies.heartsPattern.anyMatches(getSbLines())) { - add(getSbLines().first { RiftBloodEffigies.heartsPattern.matches(it) }) - } - - if (SbPattern.riftAveikxPattern.anyMatches(getSbLines())) { - addAll(getSbLines().filter { SbPattern.riftAveikxPattern.matches(it) }) - } +private fun getRiftLines() = getSbLines().filter { line -> + RiftBloodEffigies.heartsPattern.matches(line) + || SbPattern.riftHotdogTitlePattern.matches(line) + || SbPattern.timeLeftPattern.matches(line) + || SbPattern.riftHotdogEatenPattern.matches(line) + || SbPattern.riftAveikxPattern.matches(line) } -private fun getEssenceLines(): List<String> { - return listOf(getSbLines().first { SbPattern.essencePattern.matches(it) }) -} +private fun getEssenceLines(): List<String> = listOf(getSbLines().first { SbPattern.essencePattern.matches(it) }) -private fun getEssenceShowWhen(): Boolean { - return SbPattern.essencePattern.anyMatches(getSbLines()) -} +private fun getEssenceShowWhen(): Boolean = SbPattern.essencePattern.anyMatches(getSbLines()) -private fun getQueueLines(): List<String> { - return listOf(getSbLines().first { SbPattern.queuePattern.matches(it) }) + +private fun getQueueLines(): List<String> = + listOf(getSbLines().first { SbPattern.queuePattern.matches(it) }) + (getSbLines().first { SbPattern.queuePositionPattern.matches(it) }) -} -private fun getQueueShowWhen(): Boolean { - return SbPattern.queuePattern.anyMatches(getSbLines()) -} +private fun getQueueShowWhen(): Boolean = SbPattern.queuePattern.anyMatches(getSbLines()) -private fun getRedstoneLines(): List<String> { - return listOf(getSbLines().first { SbPattern.redstonePattern.matches(it) }) -} +private fun getRedstoneLines(): List<String> = listOf(getSbLines().first { SbPattern.redstonePattern.matches(it) }) -private fun getRedstoneShowWhen(): Boolean { - return SbPattern.redstonePattern.anyMatches(getSbLines()) -} +private fun getRedstoneShowWhen(): Boolean = SbPattern.redstonePattern.anyMatches(getSbLines()) 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 25eb68073..1af663c7a 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 @@ -20,7 +20,7 @@ object UnknownLinesHandler { .filter { it.trim().length > 3 } /* - * remove with pattern + * Remove known lines with patterns */ val patternsToExclude = listOf( PurseAPI.coinsPattern, |