blob: 9e621e8994202a5396c8723b2d35afd02dae56dc (
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
|
package moe.nea.ledger.utils
import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.utils.di.Inject
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
abstract class BorderedTextTracker {
val genericBorderExit = "▬{10,}".toPattern()
@Inject
lateinit var errorUtil: ErrorUtil
var stack: MutableList<ChatReceived>? = null
@SubscribeEvent
fun receiveText(event: ChatReceived) {
if (stack != null && shouldExit(event)) {
exit()
return
}
if (shouldEnter(event)) {
if (stack != null) {
errorUtil.reportAdHoc("Double entered a bordered message")
exit()
}
stack = mutableListOf()
}
stack?.add(event)
}
private fun exit() {
onBorderedTextFinished(stack!!)
stack = null
}
abstract fun shouldEnter(event: ChatReceived): Boolean
abstract fun shouldExit(event: ChatReceived): Boolean
abstract fun onBorderedTextFinished(enclosed: List<ChatReceived>)
}
|