aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/moe/nea/ledger/AuctionHouseDetection.kt23
-rw-r--r--src/main/kotlin/moe/nea/ledger/ItemUtil.kt8
2 files changed, 27 insertions, 4 deletions
diff --git a/src/main/java/moe/nea/ledger/AuctionHouseDetection.kt b/src/main/java/moe/nea/ledger/AuctionHouseDetection.kt
index b9d76c5..a73d6b1 100644
--- a/src/main/java/moe/nea/ledger/AuctionHouseDetection.kt
+++ b/src/main/java/moe/nea/ledger/AuctionHouseDetection.kt
@@ -21,11 +21,12 @@ class AuctionHouseDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) {
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 lastViewedItem: LastViewedItem? = null
+ var lastViewedItems: MutableList<LastViewedItem> = mutableListOf()
@SubscribeEvent
fun onEvent(event: ChatReceived) {
collectSold.useMatcher(event.message) {
+ val lastViewedItem = lastViewedItems.removeLastOrNull()
ledger.logEntry(
LedgerEntry(
"AUCTION_SOLD",
@@ -43,7 +44,7 @@ class AuctionHouseDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) {
event.timestamp,
parseShortNumber(group("coins")),
ids.findForName(group("what")),
- group("amount")?.let { it.toInt() } ?: 1
+ group("amount")?.toInt() ?: 1
)
)
}
@@ -51,7 +52,6 @@ class AuctionHouseDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) {
@SubscribeEvent
fun onBeforeAuctionCollected(event: BeforeGuiAction) {
- // TODO: collect all support
val chest = (event.gui as? GuiChest) ?: return
val slots = chest.inventorySlots as ContainerChest
val name = slots.lowerChestInventory.displayName.unformattedText.unformattedString()
@@ -59,6 +59,21 @@ class AuctionHouseDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) {
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()
}
@@ -66,7 +81,7 @@ class AuctionHouseDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) {
val soldItem = slots.lowerChestInventory.getStackInSlot(9 + 4) ?: return
val id = soldItem.getInternalId() ?: return
val count = soldItem.stackSize
- lastViewedItem = LastViewedItem(count, id)
+ lastViewedItems = mutableListOf(LastViewedItem(count, id))
}
diff --git a/src/main/kotlin/moe/nea/ledger/ItemUtil.kt b/src/main/kotlin/moe/nea/ledger/ItemUtil.kt
index 365c37e..7157386 100644
--- a/src/main/kotlin/moe/nea/ledger/ItemUtil.kt
+++ b/src/main/kotlin/moe/nea/ledger/ItemUtil.kt
@@ -11,3 +11,11 @@ fun ItemStack.getInternalId(): String? {
return id.takeIf { it.isNotBlank() }
}
+
+fun ItemStack.getLore(): List<String> {
+ val nbt = this.tagCompound ?: NBTTagCompound()
+ val extraAttributes = nbt.getCompoundTag("display")
+ val lore = extraAttributes.getTagList("Lore", 8)
+ return (0 until lore.tagCount()).map { lore.getStringTagAt(it) }
+}
+