@@ -2,12 +2,15 @@ package me.owdding.customscoreboard.elements
22
33import me.owdding.customscoreboard.config.category.LinesConfig
44import me.owdding.customscoreboard.utils.ElementGroup
5+ import me.owdding.customscoreboard.utils.RemoteStrings
56import me.owdding.customscoreboard.utils.ScoreboardElement
7+ import me.owdding.customscoreboard.utils.StringGroup.Companion.resolve
8+ import net.minecraft.network.chat.Component
69import tech.thatgravyboat.skyblockapi.api.datetime.DateTimeAPI
710import tech.thatgravyboat.skyblockapi.api.datetime.SkyBlockInstant
8- import tech.thatgravyboat.skyblockapi.helpers.McLevel
11+ import tech.thatgravyboat.skyblockapi.api.events.info.ScoreboardUpdateEvent
12+ import tech.thatgravyboat.skyblockapi.utils.regex.component.anyMatch
913import tech.thatgravyboat.skyblockapi.utils.text.Text
10- import tech.thatgravyboat.skyblockapi.utils.text.TextBuilder.append
1114import tech.thatgravyboat.skyblockapi.utils.text.TextColor
1215import tech.thatgravyboat.skyblockapi.utils.text.TextStyle.color
1316import kotlin.time.Duration.Companion.seconds
@@ -39,22 +42,25 @@ object TimeElement : Element() {
3942 if (rawHour >= 12 ) append(" pm" ) else append(" am" )
4043 }
4144
42- val (symbol, color) = McLevel .selfOrNull?.let {
43- when {
44- it.isRaining -> " ☔" to TextColor .DARK_AQUA
45- it.isThundering -> " ⚡" to TextColor .YELLOW
46- DateTimeAPI .isDay -> " ☀" to TextColor .YELLOW
47- else -> " ☽" to TextColor .AQUA
48- }
49- } ? : (" ⚠" to TextColor .RED )
50-
51- append(" $symbol " , color)
45+ currentWeather?.let (::append)
5246 }
5347
5448 override val configLine = " Time"
5549 override val id = " TIME"
5650 override val group = ElementGroup .HEADER
5751
52+ private val remote = RemoteStrings .resolve()
53+ private val weatherRegex by remote.componentRegex(" \\ s*\\ d{1,2}:\\ d{2}(?:am|pm) (?<weather>.+)" )
54+
55+ private var currentWeather: Component ? = null
56+
57+ override fun onScoreboardUpdate (event : ScoreboardUpdateEvent ) {
58+ val match = weatherRegex.anyMatch(event.newComponents, " weather" ) { (weather) ->
59+ currentWeather = weather
60+ }
61+ if (! match) currentWeather = null
62+ }
63+
5864 private fun isInstantAccurate (instant : SkyBlockInstant ): Boolean {
5965 val season = DateTimeAPI .season ? : return false
6066
0 commit comments