aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/moe/nea/ledger/AuctionHouseDetection.kt88
-rw-r--r--src/main/java/moe/nea/ledger/BazaarDetection.kt39
-rw-r--r--src/main/java/moe/nea/ledger/BazaarOrderDetection.kt70
-rw-r--r--src/main/java/moe/nea/ledger/mixin/MouseClickEventPatch.java18
4 files changed, 18 insertions, 197 deletions
diff --git a/src/main/java/moe/nea/ledger/AuctionHouseDetection.kt b/src/main/java/moe/nea/ledger/AuctionHouseDetection.kt
deleted file mode 100644
index a73d6b1..0000000
--- a/src/main/java/moe/nea/ledger/AuctionHouseDetection.kt
+++ /dev/null
@@ -1,88 +0,0 @@
-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.util.regex.Pattern
-
-class AuctionHouseDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) {
- data class LastViewedItem(
- val count: Int,
- val id: String,
- )
- /*
- You collected 8,712,000 coins from selling Ultimate Carrot Candy Upgrade to [VIP] kodokush in an auction!
- You collected 60,000 coins from selling Walnut to [MVP++] Alea1337 in an auction!
- You purchased 2x Walnut for 69 coins!
- You purchased ◆ Ice Rune I for 4,000 coins!
- */
-
- val collectSold =
- Pattern.compile("You collected (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<what>.*) to (?<buyer>.*) in an auction!")
- val purchased =
- Pattern.compile("You purchased (?:(?<amount>[0-9]+)x )?(?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
- var lastViewedItems: MutableList<LastViewedItem> = mutableListOf()
-
- @SubscribeEvent
- fun onEvent(event: ChatReceived) {
- collectSold.useMatcher(event.message) {
- val lastViewedItem = lastViewedItems.removeLastOrNull()
- ledger.logEntry(
- LedgerEntry(
- "AUCTION_SOLD",
- event.timestamp,
- parseShortNumber(group("coins")),
- lastViewedItem?.id,
- lastViewedItem?.count
- )
- )
- }
- purchased.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- "AUCTION_BOUGHT",
- event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- group("amount")?.toInt() ?: 1
- )
- )
- }
- }
-
- @SubscribeEvent
- fun onBeforeAuctionCollected(event: BeforeGuiAction) {
- val chest = (event.gui as? GuiChest) ?: return
- val slots = chest.inventorySlots as ContainerChest
- val name = slots.lowerChestInventory.displayName.unformattedText.unformattedString()
-
- if (name == "BIN Auction View" || name == "Auction View") {
- handleCollectSingleAuctionView(slots)
- }
- if (name == "Manage Auctions") {
- handleCollectMultipleAuctionsView(slots)
- }
- }
-
- private fun handleCollectMultipleAuctionsView(slots: ContainerChest) {
- lastViewedItems =
- (0 until slots.lowerChestInventory.sizeInventory)
- .mapNotNull { slots.lowerChestInventory.getStackInSlot(it) }
- .filter {
- it.getLore().contains("§7Status: §aSold!") // BINs
- || it.getLore().contains("§7Status: §aEnded!") // Auctions
- }
- .mapNotNull { LastViewedItem(it.stackSize, it.getInternalId() ?: return@mapNotNull null) }
- .toMutableList()
- }
-
-
- fun handleCollectSingleAuctionView(slots: ContainerChest) {
- val soldItem = slots.lowerChestInventory.getStackInSlot(9 + 4) ?: return
- val id = soldItem.getInternalId() ?: return
- val count = soldItem.stackSize
- lastViewedItems = mutableListOf(LastViewedItem(count, id))
- }
-
-
-}
diff --git a/src/main/java/moe/nea/ledger/BazaarDetection.kt b/src/main/java/moe/nea/ledger/BazaarDetection.kt
deleted file mode 100644
index 9bcab30..0000000
--- a/src/main/java/moe/nea/ledger/BazaarDetection.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package moe.nea.ledger
-
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.regex.Pattern
-
-class BazaarDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) {
-
- val instaBuyPattern =
- Pattern.compile("\\[Bazaar\\] Bought (?<count>[0-9]+)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
- val instaSellPattern =
- Pattern.compile("\\[Bazaar\\] Sold (?<count>[0-9]+)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
-
-
- @SubscribeEvent
- fun onInstSellChat(event: ChatReceived) {
- instaBuyPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- "BAZAAR_BUY_INSTANT",
- event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- group("count").toInt(),
- )
- )
- }
- instaSellPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- "BAZAAR_SELL_INSTANT",
- event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- group("count").toInt(),
- )
- )
- }
- }
-}
diff --git a/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt b/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt
deleted file mode 100644
index 79ba65b..0000000
--- a/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt
+++ /dev/null
@@ -1,70 +0,0 @@
-package moe.nea.ledger
-
-import moe.nea.ledger.mixin.AccessorGuiEditSign
-import net.minecraft.client.gui.inventory.GuiEditSign
-import net.minecraftforge.client.event.GuiScreenEvent
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.regex.Pattern
-
-class BazaarOrderDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) {
-
- 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!")
- val orderFlipped =
- Pattern.compile("\\[Bazaar] Order Flipped! (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins? of total expected profit.")
- val previousPricePattern =
- Pattern.compile("(?<price>$SHORT_NUMBER_PATTERN)/u")
- var lastFlippedPreviousPrice = 0.0
-
- @SubscribeEvent
- fun detectSignFlip(event: GuiScreenEvent.InitGuiEvent) {
- val gui = event.gui
- if (gui !is GuiEditSign) return
- gui as AccessorGuiEditSign
- val text = gui.tileEntity_ledger.signText
- if (text[2].unformattedText != "Previous price:") return
- previousPricePattern.useMatcher(text[3].unformattedText) {
- lastFlippedPreviousPrice = parseShortNumber(group("price"))
- }
- }
-
- @SubscribeEvent
- fun detectBuyOrders(event: ChatReceived) {
- orderFlipped.useMatcher(event.message) {
- val amount = parseShortNumber(group("amount")).toInt()
- ledger.logEntry(
- LedgerEntry(
- "BAZAAR_BUY_ORDER",
- event.timestamp,
- lastFlippedPreviousPrice * amount,
- ids.findForName(group("what")),
- amount,
- )
- )
- }
- 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/java/moe/nea/ledger/mixin/MouseClickEventPatch.java b/src/main/java/moe/nea/ledger/mixin/MouseClickEventPatch.java
new file mode 100644
index 0000000..9b109c4
--- /dev/null
+++ b/src/main/java/moe/nea/ledger/mixin/MouseClickEventPatch.java
@@ -0,0 +1,18 @@
+package moe.nea.ledger.mixin;
+
+import moe.nea.ledger.GuiClickEvent;
+import net.minecraft.client.gui.inventory.GuiContainer;
+import net.minecraft.inventory.Slot;
+import net.minecraftforge.common.MinecraftForge;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(GuiContainer.class)
+public class MouseClickEventPatch {
+ @Inject(method = "handleMouseClick", at = @At("HEAD"))
+ private void onHandleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType, CallbackInfo ci) {
+ MinecraftForge.EVENT_BUS.post(new GuiClickEvent(slotIn, slotId, clickedButton, clickType));
+ }
+}