aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/BitsShop.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-02 16:01:38 +0200
committerLinnea Gräf <nea@nea.moe>2024-04-02 16:01:38 +0200
commit3e0198e3a803d2dd46988ba0ac445412c7da8390 (patch)
tree6f08cebe11894769ead7ce7473b27dbdf21523d5 /src/main/kotlin/moe/nea/ledger/BitsShop.kt
parent8d26a206297071775e88b99d4b38efcc5577af0a (diff)
downloadmoney-ledger-3e0198e3a803d2dd46988ba0ac445412c7da8390.tar.gz
money-ledger-3e0198e3a803d2dd46988ba0ac445412c7da8390.tar.bz2
money-ledger-3e0198e3a803d2dd46988ba0ac445412c7da8390.zip
Add bits stuff
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/BitsShop.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/BitsShop.kt48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/BitsShop.kt b/src/main/kotlin/moe/nea/ledger/BitsShop.kt
new file mode 100644
index 0000000..ea9e4d2
--- /dev/null
+++ b/src/main/kotlin/moe/nea/ledger/BitsShop.kt
@@ -0,0 +1,48 @@
+package moe.nea.ledger
+
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.time.Instant
+
+class BitsShop(val ledger: LedgerLogger) {
+
+
+ data class BitShopEntry(
+ val id: String,
+ val bitPrice: Int,
+ val timestamp: Long = System.currentTimeMillis()
+ )
+
+ var lastClickedBitShopItem: BitShopEntry? = null
+ var bitCostPattern = "(?<cost>$SHORT_NUMBER_PATTERN) Bits".toPattern()
+
+ @SubscribeEvent
+ fun recordLastBitPrice(event: GuiClickEvent) {
+ val slot = event.slotIn ?: return
+ val name = slot.inventory.displayName.unformattedText.unformattedString()
+ if (name != "Community Shop" && !name.startsWith("Bits Shop"))
+ return
+ val stack = slot.stack ?: return
+ val id = stack.getInternalId() ?: return
+ val bitPrice = stack.getLore()
+ .firstNotNullOfOrNull { bitCostPattern.useMatcher(it.unformattedString()) { parseShortNumber(group("cost")).toInt() } }
+ ?: return
+ lastClickedBitShopItem = BitShopEntry(id, bitPrice)
+ }
+
+ @SubscribeEvent
+ fun onChat(event: ChatReceived) {
+ if (event.message.startsWith("You bought ")) {
+ val lastBit = lastClickedBitShopItem ?: return
+ if (System.currentTimeMillis() - lastBit.timestamp > 5000) return
+ ledger.logEntry(
+ LedgerEntry(
+ "COMMUNITY_SHOP_BUY", Instant.now(),
+ lastBit.bitPrice.toDouble(),
+ lastBit.id,
+ 1
+ )
+ )
+ }
+ }
+
+} \ No newline at end of file