|
1 | 1 | package me.owdding.customscoreboard.feature.customscoreboard.events |
2 | 2 |
|
3 | 3 | import me.owdding.customscoreboard.AutoElement |
4 | | -import me.owdding.customscoreboard.utils.TextUtils.anyMatch |
| 4 | +import me.owdding.customscoreboard.utils.NumberUtils.format |
5 | 5 | import net.minecraft.network.chat.Component |
| 6 | +import tech.thatgravyboat.skyblockapi.api.area.hub.SpookyFestivalAPI |
6 | 7 | import tech.thatgravyboat.skyblockapi.api.events.info.ScoreboardUpdateEvent |
7 | | -import tech.thatgravyboat.skyblockapi.api.location.SkyBlockIsland |
8 | | -import tech.thatgravyboat.skyblockapi.utils.regex.component.ComponentRegex |
9 | | -import tech.thatgravyboat.skyblockapi.utils.regex.component.anyMatch |
| 8 | +import tech.thatgravyboat.skyblockapi.utils.text.Text |
| 9 | +import tech.thatgravyboat.skyblockapi.utils.text.TextBuilder.append |
| 10 | +import tech.thatgravyboat.skyblockapi.utils.text.TextColor |
| 11 | +import tech.thatgravyboat.skyblockapi.utils.text.TextStyle.color |
10 | 12 |
|
11 | 13 | @AutoElement |
12 | 14 | object EventSpooky : Event() { |
13 | | - override fun getDisplay() = formattedLine |
14 | | - |
15 | | - override fun showIsland() = SkyBlockIsland.inAnyIsland(SkyBlockIsland.PRIVATE_ISLAND, SkyBlockIsland.GARDEN) |
| 15 | + override fun getDisplay() = formattedLines |
16 | 16 |
|
17 | 17 | override val configLine = "Spooky" |
18 | 18 |
|
19 | 19 |
|
20 | | - private var formattedLine: Component? = null |
21 | | - |
22 | | - private val festivalRegex = ComponentRegex("Spooky Festival [\\d.,:]+") |
| 20 | + private var formattedLines: List<Component> = emptyList() |
23 | 21 |
|
24 | 22 | override fun onScoreboardUpdate(event: ScoreboardUpdateEvent) { |
25 | | - formattedLine = event.components.find(festivalRegex::matches) |
| 23 | + if (SpookyFestivalAPI.onGoing) { |
| 24 | + formattedLines = listOf( |
| 25 | + Text.of("Spooky Festival ") { |
| 26 | + color = TextColor.ORANGE |
| 27 | + append(getTime(), TextColor.WHITE) |
| 28 | + }, |
| 29 | + Text.of("Your Candy:", TextColor.GRAY), |
| 30 | + getCandy(), |
| 31 | + ) |
| 32 | + } else formattedLines = emptyList() |
| 33 | + } |
| 34 | + |
| 35 | + private fun getTime(): String { |
| 36 | + val totalSeconds = SpookyFestivalAPI.duration.inWholeSeconds |
| 37 | + val minutes = totalSeconds / 60 |
| 38 | + val seconds = totalSeconds % 60 |
| 39 | + return "%02d:%02d".format(minutes, seconds) |
| 40 | + } |
| 41 | + |
| 42 | + private fun getCandy() = Text.of { |
| 43 | + color = TextColor.GRAY |
| 44 | + append("${SpookyFestivalAPI.greenCandy.format()} Green", TextColor.GREEN) |
| 45 | + append(", ") |
| 46 | + append("${SpookyFestivalAPI.purpleCandy.format()} Purple", TextColor.DARK_PURPLE) |
| 47 | + append(" (") |
| 48 | + append(SpookyFestivalAPI.points.format(), TextColor.ORANGE) |
| 49 | + append(" pts.)") |
26 | 50 | } |
27 | 51 | } |
0 commit comments