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