diff options
author | Linnea Gräf <nea@nea.moe> | 2024-02-15 20:42:19 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-02-15 20:42:19 +0100 |
commit | b7aa6cddd2a4134ff3ee53c8c1bc707dc1cab89c (patch) | |
tree | 3bb7db321605507aa3e8025c0dd7c64ea3edca3a | |
parent | edc72af6ec6055822d0deed8efe3c952cbf65026 (diff) | |
download | LocalTransactionLedger-b7aa6cddd2a4134ff3ee53c8c1bc707dc1cab89c.tar.gz LocalTransactionLedger-b7aa6cddd2a4134ff3ee53c8c1bc707dc1cab89c.tar.bz2 LocalTransactionLedger-b7aa6cddd2a4134ff3ee53c8c1bc707dc1cab89c.zip |
Add bazaar order support
-rw-r--r-- | src/main/java/moe/nea/ledger/BazaarOrderDetection.kt | 45 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | 5 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/Ledger.kt | 1 |
3 files changed, 50 insertions, 1 deletions
diff --git a/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt b/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt new file mode 100644 index 0000000..99a4213 --- /dev/null +++ b/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt @@ -0,0 +1,45 @@ +package moe.nea.ledger + +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +class BazaarOrderDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) { + /* + [Bazaar] Buy Order Setup! 160x Wheat for 720.0 coins. + [Bazaar] Claimed 160x Wheat worth 720.0 coins bought for 4.5 each! + + [Bazaar] Sell Offer Setup! 160x Wheat for 933.4 coins. + [Bazaar] Claimed 34,236,799 coins from selling 176x Hyper Catalyst at 196,741 each! + */ + + val buyOrderClaimed = + Pattern.compile("\\[Bazaar] Claimed (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) worth (?<coins>$SHORT_NUMBER_PATTERN) coins? bought for $SHORT_NUMBER_PATTERN each!") + val sellOrderClaimed = + Pattern.compile("\\[Bazaar] Claimed (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) at $SHORT_NUMBER_PATTERN each!") + + @SubscribeEvent + fun detectBuyOrders(event: ChatReceived) { + buyOrderClaimed.useMatcher(event.message) { + ledger.logEntry( + LedgerEntry( + "BAZAAR_BUY_ORDER", + event.timestamp, + parseShortNumber(group("coins")), + ids.findForName(group("what")), + parseShortNumber(group("amount")).toInt(), + ) + ) + } + sellOrderClaimed.useMatcher(event.message) { + ledger.logEntry( + LedgerEntry( + "BAZAAR_SELL_ORDER", + event.timestamp, + parseShortNumber(group("coins")), + ids.findForName(group("what")), + parseShortNumber(group("amount")).toInt(), + ) + ) + } + } +} diff --git a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt index 988e317..b1d953e 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt @@ -25,11 +25,14 @@ class ItemIdProvider { fun saveInventoryIds(event: BeforeGuiAction) { val chest = (event.gui as? GuiChest) ?: return val slots = chest.inventorySlots as ContainerChest + val isOrderMenu = slots.lowerChestInventory.name.unformattedString() == "Your Bazaar Orders" slots.inventorySlots.forEach { val stack = it.stack ?: return@forEach val nbt = stack.tagCompound ?: NBTTagCompound() val display = nbt.getCompoundTag("display") - val name = display.getString("Name").unformattedString() + var name = display.getString("Name").unformattedString() + if (isOrderMenu) + name = name.removePrefix("BUY ").removePrefix("SELL ") val id = stack.getInternalId() if (id != null && name.isNotBlank()) { knownNames[name] = id diff --git a/src/main/kotlin/moe/nea/ledger/Ledger.kt b/src/main/kotlin/moe/nea/ledger/Ledger.kt index d1fc57d..e9f5efc 100644 --- a/src/main/kotlin/moe/nea/ledger/Ledger.kt +++ b/src/main/kotlin/moe/nea/ledger/Ledger.kt @@ -43,6 +43,7 @@ class Ledger { ids, BankDetection(ledger), BazaarDetection(ledger, ids), + BazaarOrderDetection(ledger, ids), AuctionHouseDetection(ledger, ids), ).forEach(MinecraftForge.EVENT_BUS::register) } |