From 56da75a2b9dbeaeeab3f5a89d485b6be48affec8 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Sun, 21 Jul 2024 10:46:02 +0200 Subject: Fix: Kuudra Errors (#2236) --- .../gui/customscoreboard/ScoreboardElements.kt | 22 +++++++++++++--------- .../gui/customscoreboard/ScoreboardPattern.kt | 8 ++++++-- .../gui/customscoreboard/UnknownLinesHandler.kt | 19 ++++++++++--------- 3 files changed, 29 insertions(+), 20 deletions(-) (limited to 'src') 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 a3b3652b2..6562edaf3 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 @@ -632,17 +632,21 @@ private fun getCookieShowWhen(): Boolean { } private fun getObjectiveDisplayPair() = buildList { - val objective = - ScoreboardData.sidebarLinesFormatted.first { ScoreboardPattern.objectivePattern.matches(it) } + val formattedLines = ScoreboardData.sidebarLinesFormatted + val objective = formattedLines.firstOrNull { ScoreboardPattern.objectivePattern.matches(it) } + if (objective != null) { + add(objective to HorizontalAlignment.LEFT) - add(objective to HorizontalAlignment.LEFT) - add((ScoreboardData.sidebarLinesFormatted.nextAfter(objective) ?: "") to HorizontalAlignment.LEFT) + val secondLine = formattedLines.nextAfter(objective) ?: "" + add(secondLine to HorizontalAlignment.LEFT) - if (ScoreboardData.sidebarLinesFormatted.any { ScoreboardPattern.thirdObjectiveLinePattern.matches(it) }) { - add( - (ScoreboardData.sidebarLinesFormatted.nextAfter(objective, 2) - ?: "Second objective here") to HorizontalAlignment.LEFT, - ) + formattedLines.nextAfter(objective, 2)?.let { + if (ScoreboardPattern.thirdObjectiveLinePattern.matches(it)) add(it to HorizontalAlignment.LEFT) + } + + formattedLines.nextAfter(objective, 3)?.let { + if (ScoreboardPattern.thirdObjectiveLinePattern.matches(it)) add(it to HorizontalAlignment.LEFT) + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardPattern.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardPattern.kt index 62b282b37..d9126ef44 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardPattern.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardPattern.kt @@ -153,10 +153,11 @@ object ScoreboardPattern { /** * REGEX-TEST: Submerges In: §e01m 00s + * REGEX-TEST: Submerges In: §e??? */ val submergesPattern by kuudraSb.pattern( "submerges", - "(?:§.)*Submerges In: (?:§.)*[\\w\\s]+", + "(?:§.)*Submerges In: (?:§.)*[\\w\\s?]+", ) // farming @@ -392,7 +393,10 @@ object ScoreboardPattern { "§d\\d+(?:st|nd|rd|th) Anniversary§f (?:\\d|:)+", ) - // this thirdObjectiveLinePattern includes all those weird objective lines that go into a third scoreboard line + // this thirdObjectiveLinePattern includes all those weird objective lines that go into a third (and fourth) scoreboard line + /** + * REGEX-TEST: §eProtect Elle §7(§a98%§7) + */ val thirdObjectiveLinePattern by miscSb.pattern( "thirdobjectiveline", "(\\s*§.\\(§.\\w+§./§.\\w+§.\\)|§f Mages.*|§f Barbarians.*|§edefeat Kuudra|§eand stun him)", 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 a38b52d78..bbae099d6 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 @@ -142,16 +142,17 @@ object UnknownLinesHandler { } /** - * remove known text + * Remove Known Text **/ - // remove objectives - val objectiveLine = sidebarLines.firstOrNull { SbPattern.objectivePattern.matches(it) } - ?: "Objective" - unknownLines = unknownLines.filter { sidebarLines.nextAfter(objectiveLine) != it } - // TODO create function - unknownLines = unknownLines.filter { - sidebarLines.nextAfter(objectiveLine, 2) != it && - !SbPattern.thirdObjectiveLinePattern.matches(it) + // Remove objectives + val objectiveLine = sidebarLines.firstOrNull { SbPattern.objectivePattern.matches(it) } ?: "Objective" + + unknownLines = unknownLines.filter { line -> + val nextLine = sidebarLines.nextAfter(objectiveLine) + val secondNextLine = sidebarLines.nextAfter(objectiveLine, 2) + val thirdNextLine = sidebarLines.nextAfter(objectiveLine, 3) + + line != nextLine && line != secondNextLine && line != thirdNextLine && !SbPattern.thirdObjectiveLinePattern.matches(line) } // Remove jacobs contest -- cgit