aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt b/src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt
new file mode 100644
index 0000000..9e621e8
--- /dev/null
+++ b/src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt
@@ -0,0 +1,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>)
+
+} \ No newline at end of file