From b7aa6cddd2a4134ff3ee53c8c1bc707dc1cab89c Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 15 Feb 2024 20:42:19 +0100 Subject: Add bazaar order support --- .../java/moe/nea/ledger/BazaarOrderDetection.kt | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/moe/nea/ledger/BazaarOrderDetection.kt (limited to 'src/main/java/moe/nea/ledger/BazaarOrderDetection.kt') 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 (?$SHORT_NUMBER_PATTERN)x (?.*) worth (?$SHORT_NUMBER_PATTERN) coins? bought for $SHORT_NUMBER_PATTERN each!") + val sellOrderClaimed = + Pattern.compile("\\[Bazaar] Claimed (?$SHORT_NUMBER_PATTERN) coins? from selling (?$SHORT_NUMBER_PATTERN)x (?.*) 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(), + ) + ) + } + } +} -- cgit