From d8f1a2417cc48b9bfd3c9e75eff0bfc1c0d33a30 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Sat, 4 May 2024 03:35:38 +0200 Subject: Improvement: Add Incoming Tablist Event to Custom Scoreboard (#1666) --- .../gui/customscoreboard/ScoreboardEvents.kt | 36 +++++++++++++++++----- .../gui/customscoreboard/ScoreboardPattern.kt | 4 +++ 2 files changed, 33 insertions(+), 7 deletions(-) (limited to 'src/main/java') 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 a6e3ca165..4da038695 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 @@ -158,7 +158,12 @@ enum class ScoreboardEvents( ACTIVE_TABLIST_EVENTS( ::getActiveEventLine, ::getActiveEventShowWhen, - "§7(All Active Tablist Events)" + "§7(All Active Tablist Events)\n§dHoppity's Hunt\n §fEnds in: §e26h" + ), + STARTING_SOON_TABLIST_EVENTS( + ::getSoonEventLine, + ::getSoonEventShowWhen, + "§7(All Starting Soon Tablist Events)\n§6Mining Fiesta\n §fStarts in: §e52min" ), REDSTONE( ::getRedstoneLines, @@ -369,26 +374,43 @@ private fun getSpookyLines() = buildList { private fun getSpookyShowWhen(): Boolean = getSbLines().any { ScoreboardPattern.spookyPattern.matches(it) } -private fun getActiveEventLine(): List { - val currentActiveEvent = TabListData.getTabList().firstOrNull { SbPattern.eventNamePattern.matches(it) } +private fun getTablistEvent(): String? = + TabListData.getTabList().firstOrNull { SbPattern.eventNamePattern.matches(it) } ?.let { SbPattern.eventNamePattern.matchMatcher(it) { group("name") } } - val currentActiveEventEndsIn = TabListData.getTabList().firstOrNull { SbPattern.eventTimeEndsPattern.matches(it) } + +private fun getActiveEventLine(): List { + val currentActiveEvent = getTablistEvent() ?: return emptyList() + val currentActiveEventTime = TabListData.getTabList().firstOrNull { SbPattern.eventTimeEndsPattern.matches(it) } ?.let { SbPattern.eventTimeEndsPattern.matchMatcher(it) { group("time") } } - return listOf("$currentActiveEvent $currentActiveEventEndsIn") + return listOf(currentActiveEvent, " Ends in: §e$currentActiveEventTime") } private fun getActiveEventShowWhen(): Boolean = - TabListData.getTabList().any { SbPattern.eventNamePattern.matches(it) } && - TabListData.getTabList().any { SbPattern.eventTimeEndsPattern.matches(it) } + getTablistEvent() != null && TabListData.getTabList().any { SbPattern.eventTimeEndsPattern.matches(it) } + +private fun getSoonEventLine(): List { + val soonActiveEvent = getTablistEvent() ?: return emptyList() + val soonActiveEventTime = TabListData.getTabList().firstOrNull { SbPattern.eventTimeEndsPattern.matches(it) } + ?.let { + SbPattern.eventTimeStartsPattern.matchMatcher(it) { + group("time") + } + } + + return listOf(soonActiveEvent, " Starts in: §e$soonActiveEventTime") +} + +private fun getSoonEventShowWhen(): Boolean = + getTablistEvent() != null && TabListData.getTabList().any { SbPattern.eventTimeStartsPattern.matches(it) } private fun getBroodmotherLines(): List = listOf(getSbLines().first { SbPattern.broodmotherPattern.matches(it) }) 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 fd15e2131..d73525fc3 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 @@ -446,4 +446,8 @@ object ScoreboardPattern { "eventtime", "^\\s+Ends In: §r§e(?