blob: 96bfba678848a9b6bc3311066fde519aa0e3343a (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
package at.hannibal2.skyhanni.dungeon
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.DungeonEnterEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.utils.GuiRender.renderString
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex
import net.minecraftforge.client.event.RenderGameOverlayEvent
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.concurrent.fixedRateTimer
class DungeonMilestoneDisplay {
companion object {
private var textToRender = ""
var color = ""
var currentMilestone = 0
var timeReached = 0L
fun isMilestoneMessage(message: String): Boolean = when {
message.matchRegex("§e§l(.*) Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)") -> true
message.matchRegex("§e§lArcher Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Ranged Damage so far! §r§a(.*)") -> true
message.matchRegex("§e§lHealer Milestone §r§e.§r§7: You have healed §r§a(.*)§r§7 Damage so far! §r§a(.*)") -> true
message.matchRegex("§e§lTank Milestone §r§e.§r§7: You have tanked and dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)s") -> true
else -> false
}
}
init {
fixedRateTimer(name = "dungeon-milestone-display", period = 200) {
if (!isEnabled()) return@fixedRateTimer
checkVisibility()
}
}
private fun checkVisibility() {
if (currentMilestone >= 3) {
if (System.currentTimeMillis() > timeReached + 3_000)
if (textToRender != "") {
textToRender = textToRender.substring(1)
}
}
}
@SubscribeEvent(receiveCanceled = true)
fun onChatPacket(event: LorenzChatEvent) {
if (!isEnabled()) return
if (isMilestoneMessage(event.message)) {
event.blockedReason = "dungeon_milestone"
currentMilestone++
update()
}
}
private fun update() {
if (currentMilestone > 3) return
if (currentMilestone == 3) {
timeReached = System.currentTimeMillis()
}
color = when (currentMilestone) {
0, 1 -> "§c"
2 -> "§e"
else -> "§a"
}
textToRender = "Current Milestone: $currentMilestone"
}
@SubscribeEvent
fun onWorldChange(event: WorldEvent.Load) {
textToRender = ""
currentMilestone = 0
}
@SubscribeEvent
fun onDungeonStart(event: DungeonEnterEvent) {
currentMilestone = 0
update()
}
@SubscribeEvent
fun renderOverlay(event: RenderGameOverlayEvent.Post) {
if (!isEnabled()) return
SkyHanniMod.feature.dungeon.milestoneDisplayPos.renderString(color + textToRender)
}
private fun isEnabled(): Boolean {
return LorenzUtils.inDungeons && SkyHanniMod.feature.dungeon.showMilestoneDisplay
}
}
|