aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-06 19:27:07 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-06 19:28:23 +0100
commitf7507f384459b57460af899bf9ceae4f52f1ea21 (patch)
tree410d70c0a35de852278b03ac9243080d7e0a0490 /src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt
parent2c9132d0c755964800b710ce43c8feebd44f1299 (diff)
downloadLocalTransactionLedger-f7507f384459b57460af899bf9ceae4f52f1ea21.tar.gz
LocalTransactionLedger-f7507f384459b57460af899bf9ceae4f52f1ea21.tar.bz2
LocalTransactionLedger-f7507f384459b57460af899bf9ceae4f52f1ea21.zip
refactor: Add DI and packages
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt
new file mode 100644
index 0000000..22b5392
--- /dev/null
+++ b/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt
@@ -0,0 +1,58 @@
+package moe.nea.ledger.modules
+
+import moe.nea.ledger.events.ChatReceived
+import moe.nea.ledger.events.LateWorldLoadEvent
+import moe.nea.ledger.LedgerEntry
+import moe.nea.ledger.LedgerLogger
+import moe.nea.ledger.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.ScoreboardUtil
+import moe.nea.ledger.parseShortNumber
+import moe.nea.ledger.unformattedString
+import moe.nea.ledger.useMatcher
+import moe.nea.ledger.utils.Inject
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.time.Instant
+
+class BitsDetection @Inject constructor(val ledger: LedgerLogger) {
+
+ var lastBits = -1
+
+ val bitScoreboardRegex = "Bits: (?<purse>$SHORT_NUMBER_PATTERN)".toPattern()
+
+ @SubscribeEvent
+ fun onWorldSwitch(event: LateWorldLoadEvent) {
+ ScoreboardUtil.getScoreboardStrings().forEach {
+ bitScoreboardRegex.useMatcher<Unit>(it.unformattedString()) {
+ val bits = parseShortNumber(group("purse")).toInt()
+ if (lastBits != bits) {
+ ledger.logEntry(
+ LedgerEntry(
+ "BITS_PURSE_STATUS",
+ Instant.now(),
+ 0.0,
+ null,
+ bits
+ )
+ )
+ lastBits = bits
+ }
+ return
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onEvent(event: ChatReceived) {
+ if (event.message.startsWith("You consumed a Booster Cookie!")) {
+ ledger.logEntry(
+ LedgerEntry(
+ "BOOSTER_COOKIE_ATE",
+ Instant.now(),
+ 0.0,
+ null,
+ null,
+ )
+ )
+ }
+ }
+}