From f7507f384459b57460af899bf9ceae4f52f1ea21 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 6 Dec 2024 19:27:07 +0100 Subject: refactor: Add DI and packages --- .../moe/nea/ledger/modules/MinionDetection.kt | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt (limited to 'src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt') diff --git a/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt new file mode 100644 index 0000000..73d06fa --- /dev/null +++ b/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt @@ -0,0 +1,54 @@ +package moe.nea.ledger.modules + +import moe.nea.ledger.events.BeforeGuiAction +import moe.nea.ledger.events.ChatReceived +import moe.nea.ledger.ExpiringValue +import moe.nea.ledger.LedgerEntry +import moe.nea.ledger.LedgerLogger +import moe.nea.ledger.ROMAN_NUMBER_PATTERN +import moe.nea.ledger.SHORT_NUMBER_PATTERN +import moe.nea.ledger.parseRomanNumber +import moe.nea.ledger.parseShortNumber +import moe.nea.ledger.unformattedString +import moe.nea.ledger.useMatcher +import moe.nea.ledger.utils.Inject +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 @Inject constructor(val ledger: LedgerLogger) { + // §aYou received §r§6367,516.8 coins§r§a! + val hopperCollectPattern = "You received (?$SHORT_NUMBER_PATTERN) coins?!".toPattern() + val minionNamePattern = "(?.*) Minion (?$ROMAN_NUMBER_PATTERN)".toPattern() + + var lastOpenedMinion = ExpiringValue.empty() + + @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 -- cgit