Skip to content

Commit cd306b1

Browse files
committed
feat: Aland Weather Changes
Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com>
1 parent f955ec9 commit cd306b1

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

src/main/kotlin/me/owdding/customscoreboard/elements/TimeElement.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package me.owdding.customscoreboard.elements
22

33
import me.owdding.customscoreboard.config.category.LinesConfig
44
import me.owdding.customscoreboard.utils.ElementGroup
5+
import me.owdding.customscoreboard.utils.RemoteStrings
56
import me.owdding.customscoreboard.utils.ScoreboardElement
7+
import me.owdding.customscoreboard.utils.StringGroup.Companion.resolve
8+
import net.minecraft.network.chat.Component
69
import tech.thatgravyboat.skyblockapi.api.datetime.DateTimeAPI
710
import 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
913
import tech.thatgravyboat.skyblockapi.utils.text.Text
10-
import tech.thatgravyboat.skyblockapi.utils.text.TextBuilder.append
1114
import tech.thatgravyboat.skyblockapi.utils.text.TextColor
1215
import tech.thatgravyboat.skyblockapi.utils.text.TextStyle.color
1316
import 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

Comments
 (0)