aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/MinionDetection.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-10-05 12:06:23 +0200
committerLinnea Gräf <nea@nea.moe>2024-10-05 12:06:23 +0200
commit977620f1b5218cc8a041742f970974a4bfff29cc (patch)
tree214dad2ae3f9e59304dc20e5891278d01d301629 /src/main/kotlin/moe/nea/ledger/MinionDetection.kt
parentc689c21f3757faaa43afa2402e9e49a06c1e894f (diff)
downloadmoney-ledger-977620f1b5218cc8a041742f970974a4bfff29cc.tar.gz
money-ledger-977620f1b5218cc8a041742f970974a4bfff29cc.tar.bz2
money-ledger-977620f1b5218cc8a041742f970974a4bfff29cc.zip
Add minion hopper trackerHEADmaster
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/MinionDetection.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/MinionDetection.kt42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/MinionDetection.kt b/src/main/kotlin/moe/nea/ledger/MinionDetection.kt
new file mode 100644
index 0000000..bb2a187
--- /dev/null
+++ b/src/main/kotlin/moe/nea/ledger/MinionDetection.kt
@@ -0,0 +1,42 @@
+package moe.nea.ledger
+
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraft.inventory.ContainerChest
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.time.Instant
+import kotlin.time.Duration.Companion.seconds
+
+class MinionDetection(val ledger: LedgerLogger) {
+ // §aYou received §r§6367,516.8 coins§r§a!
+ val hopperCollectPattern = "You received (?<amount>$SHORT_NUMBER_PATTERN) coins?!".toPattern()
+ val minionNamePattern = "(?<name>.*) Minion (?<level>$ROMAN_NUMBER_PATTERN)".toPattern()
+
+ var lastOpenedMinion = ExpiringValue.empty<String>()
+
+ @SubscribeEvent
+ fun onBeforeClaim(event: BeforeGuiAction) {
+ val container = event.gui as? GuiChest ?: return
+ val inv = (container.inventorySlots as ContainerChest).lowerChestInventory
+ val invName = inv.displayName.unformattedText.unformattedString()
+ minionNamePattern.useMatcher(invName) {
+ val name = group("name")
+ val level = parseRomanNumber(group("level"))
+ lastOpenedMinion = ExpiringValue(name.uppercase().replace(" ", "_") + "_" + level)
+ }
+ }
+
+
+ @SubscribeEvent
+ fun onChat(event: ChatReceived) {
+ hopperCollectPattern.useMatcher(event.message) {
+ val minionName = lastOpenedMinion.consume(3.seconds)
+ ledger.logEntry(LedgerEntry(
+ "AUTOMERCHANT_PROFIT_COLLECT",
+ Instant.now(),
+ parseShortNumber(group("amount")),
+ minionName, // TODO: switch to its own column idk
+ ))
+ }
+ }
+
+} \ No newline at end of file