aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/utils
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-19 20:18:39 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-19 20:18:39 +0100
commiteda44cb8743c709c15a7ed03381d05e43728e647 (patch)
tree557a3bd4f096584158b46921f4826208396b4baa /src/main/kotlin/moe/nea/ledger/utils
parenta046b198645811fe1b7db129942505c379aabb03 (diff)
downloadLocalTransactionLedger-eda44cb8743c709c15a7ed03381d05e43728e647.tar.gz
LocalTransactionLedger-eda44cb8743c709c15a7ed03381d05e43728e647.tar.bz2
LocalTransactionLedger-eda44cb8743c709c15a7ed03381d05e43728e647.zip
feat: Add corpse loot detection
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/utils')
-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