blob: f471bb2823828daefa8caff7a91097fce9b88ce8 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package at.hannibal2.skyhanni.features.mining
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.mob.Mob
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.MobEvent
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
class GoldenGoblinHighlight {
private val config get() = SkyHanniMod.feature.mining.highlightYourGoldenGoblin
private val goblinPattern by RepoPattern.pattern("mining.mob.golden.goblin", "Golden Goblin|Diamond Goblin")
private fun isEnabled() = LorenzUtils.inMiningIsland() && config
private val timeOut = 10.seconds
private var lastChatMessage = SimpleTimeMark.farPast()
private var lastGoblinSpawn = SimpleTimeMark.farPast()
private var lastGoblin: Mob? = null
@SubscribeEvent
fun onChatEvent(event: LorenzChatEvent) {
if (!isEnabled()) return
if (!MiningNotifications.goldenGoblinSpawn.matches(event.message) &&
!MiningNotifications.diamondGoblinSpawn.matches(event.message)
) return
lastChatMessage = SimpleTimeMark.now()
handle()
}
@SubscribeEvent
fun onMobEvent(event: MobEvent.Spawn.SkyblockMob) {
if (!isEnabled()) return
if (!goblinPattern.matches(event.mob.name)) return
lastGoblin = event.mob
lastGoblinSpawn = SimpleTimeMark.now()
handle()
}
private fun handle() {
if (lastChatMessage.passedSince() > timeOut || lastGoblinSpawn.passedSince() > timeOut) return
lastChatMessage = SimpleTimeMark.farPast()
lastGoblinSpawn = SimpleTimeMark.farPast()
lastGoblin?.highlight(LorenzColor.GREEN.toColor())
lastGoblin = null
}
}
|