blob: 706af17a32f578703125c93124419c601ac25deb (
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
57
58
59
60
61
62
63
64
|
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.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object GoldenGoblinHighlight {
private val config get() = SkyHanniMod.feature.mining
private val goblinPattern by RepoPattern.pattern("mining.mob.golden.goblin", "Golden Goblin|Diamond Goblin")
private fun isEnabled() = LorenzUtils.inMiningIsland() && config.highlightYourGoldenGoblin
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() {
// TODO merge the two time objects into one
if (lastChatMessage.passedSince() > timeOut || lastGoblinSpawn.passedSince() > timeOut) return
lastChatMessage = SimpleTimeMark.farPast()
lastGoblinSpawn = SimpleTimeMark.farPast()
val goblin = lastGoblin ?: return
goblin.highlight(LorenzColor.GREEN.toColor())
if (config.lineToYourGoldenGoblin) {
goblin.lineToPlayer(LorenzColor.GREEN.toColor())
}
lastGoblin = null
}
}
|