blob: 75ad8df9bc5135e69381ab13d4126d6d4e78ec6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.BossbarUpdateEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import net.minecraft.entity.boss.BossStatus
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object BossbarData {
private var bossbar: String? = null
private var previousServerBossbar = ""
fun getBossbar() = bossbar ?: ""
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
val oldBossbar = bossbar ?: return
previousServerBossbar = oldBossbar
bossbar = null
}
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
val bossbarLine = BossStatus.bossName ?: return
if (bossbarLine.isBlank() || bossbarLine.isEmpty()) return
if (bossbarLine == bossbar) return
if (bossbarLine == previousServerBossbar) return
if (previousServerBossbar.isNotEmpty()) previousServerBossbar = ""
bossbar = bossbarLine
BossbarUpdateEvent(bossbarLine).postAndCatch()
}
}
|