blob: 192e51297b9f0de4a724d2fa44edee729f175673 (
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
|
package at.hannibal2.skyhanni.features.chat
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.ChatManager
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraft.util.IChatComponent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class CompactBestiaryChatMessage {
var inBestiary = false
var bestiaryDescription = mutableListOf<String>()
var acceptMoreDescription = true
var command = ""
private var blockedLines = 0
var lastBorder: IChatComponent? = null
var lastEmpty: IChatComponent? = null
var milestoneMessage: String? = null
val milestonePattern = "^.+(§8\\d{1,3}➡§e\\d{1,3})$".toRegex()
@SubscribeEvent
fun onChatMessage(event: LorenzChatEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!SkyHanniMod.feature.chat.compactBestiaryMessage) return
val titleMessage = " §6§lBESTIARY"
val border = "§3§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"
val message = event.message
if (message == border) {
lastBorder = event.chatComponent
}
if (message == " ") {
lastEmpty = event.chatComponent
}
if (message == titleMessage) {
event.blockedReason = "bestiary"
ChatManager.retractMessage(lastBorder, "bestiary")
ChatManager.retractMessage(lastEmpty, "bestiary")
lastBorder = null
lastEmpty = null
for (sibling in event.chatComponent.siblings) {
sibling.chatStyle?.chatClickEvent?.let {
command = it.value
}
}
inBestiary = true
blockedLines = 0
bestiaryDescription.add(message.trim())
} else if (inBestiary) {
event.blockedReason = "bestiary"
blockedLines++
if (blockedLines > 15) {
blockedLines = 0
inBestiary = false
}
if (message == border) {
inBestiary = false
val title = bestiaryDescription[1]
LorenzUtils.hoverableChat("§6§lBESTIARY §r$title", bestiaryDescription.dropLast(1), command)
bestiaryDescription.clear()
acceptMoreDescription = true
} else {
milestoneMessage?.let {
LorenzUtils.chat("§6§lBESTIARY MILESTONE $it")
milestoneMessage = null
}
milestonePattern.matchEntire(message)?.let {
acceptMoreDescription = false
milestoneMessage = it.groups[1]!!.value
}
if (acceptMoreDescription) {
bestiaryDescription.add(message.trim())
}
}
}
}
}
|