diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/moe/nea/ledger/mixin/MouseClickEventPatch.java | 18 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt (renamed from src/main/java/moe/nea/ledger/AuctionHouseDetection.kt) | 0 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/BazaarDetection.kt (renamed from src/main/java/moe/nea/ledger/BazaarDetection.kt) | 8 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/BazaarOrderDetection.kt (renamed from src/main/java/moe/nea/ledger/BazaarOrderDetection.kt) | 0 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/BitsDetection.kt | 48 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/BitsShop.kt | 48 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/GuiClickEvent.kt | 9 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/Ledger.kt | 27 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/LedgerLogger.kt | 1 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/NumberUtil.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ScoreboardUtil.kt | 29 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/WorldLoadEvent.kt | 5 |
12 files changed, 190 insertions, 5 deletions
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)); + } +} diff --git a/src/main/java/moe/nea/ledger/AuctionHouseDetection.kt b/src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt index a73d6b1..a73d6b1 100644 --- a/src/main/java/moe/nea/ledger/AuctionHouseDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt diff --git a/src/main/java/moe/nea/ledger/BazaarDetection.kt b/src/main/kotlin/moe/nea/ledger/BazaarDetection.kt index 9bcab30..8f7c007 100644 --- a/src/main/java/moe/nea/ledger/BazaarDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/BazaarDetection.kt @@ -6,9 +6,9 @@ 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!") + Pattern.compile("\\[Bazaar\\] Bought (?<count>$SHORT_NUMBER_PATTERN)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!") + Pattern.compile("\\[Bazaar\\] Sold (?<count>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!") @SubscribeEvent @@ -20,7 +20,7 @@ class BazaarDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) { event.timestamp, parseShortNumber(group("coins")), ids.findForName(group("what")), - group("count").toInt(), + parseShortNumber(group("count")).toInt(), ) ) } @@ -31,7 +31,7 @@ class BazaarDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) { event.timestamp, parseShortNumber(group("coins")), ids.findForName(group("what")), - group("count").toInt(), + parseShortNumber(group("count")).toInt(), ) ) } diff --git a/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt b/src/main/kotlin/moe/nea/ledger/BazaarOrderDetection.kt index 79ba65b..79ba65b 100644 --- a/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/BazaarOrderDetection.kt diff --git a/src/main/kotlin/moe/nea/ledger/BitsDetection.kt b/src/main/kotlin/moe/nea/ledger/BitsDetection.kt new file mode 100644 index 0000000..2d26b3d --- /dev/null +++ b/src/main/kotlin/moe/nea/ledger/BitsDetection.kt @@ -0,0 +1,48 @@ +package moe.nea.ledger + +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.time.Instant + +class BitsDetection(val ledger: LedgerLogger) { + + var lastBits = -1 + + val bitScoreboardRegex = "Bits: (?<purse>$SHORT_NUMBER_PATTERN)".toPattern() + + @SubscribeEvent + fun onWorldSwitch(event: LateWorldLoadEvent) { + ScoreboardUtil.getScoreboardStrings().forEach { + bitScoreboardRegex.useMatcher<Unit>(it.unformattedString()) { + val bits = parseShortNumber(group("purse")).toInt() + if (lastBits != bits) { + ledger.logEntry( + LedgerEntry( + "BITS_PURSE_STATUS", + Instant.now(), + 0.0, + null, + bits + ) + ) + lastBits = bits + } + return + } + } + } + + @SubscribeEvent + fun onEvent(event: ChatReceived) { + if (event.message.startsWith("You consumed a Booster Cookie!")) { + ledger.logEntry( + LedgerEntry( + "BOOSTER_COOKIE_ATE", + Instant.now(), + 0.0, + null, + null, + ) + ) + } + } +} 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 diff --git a/src/main/kotlin/moe/nea/ledger/GuiClickEvent.kt b/src/main/kotlin/moe/nea/ledger/GuiClickEvent.kt new file mode 100644 index 0000000..13e74f1 --- /dev/null +++ b/src/main/kotlin/moe/nea/ledger/GuiClickEvent.kt @@ -0,0 +1,9 @@ +package moe.nea.ledger + +import net.minecraft.inventory.Slot +import net.minecraftforge.fml.common.eventhandler.Event + +data class GuiClickEvent( + val slotIn: Slot?, val slotId: Int, val clickedButton: Int, val clickType: Int +) : Event() { +}
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/ledger/Ledger.kt b/src/main/kotlin/moe/nea/ledger/Ledger.kt index 0164f3b..1fc7954 100644 --- a/src/main/kotlin/moe/nea/ledger/Ledger.kt +++ b/src/main/kotlin/moe/nea/ledger/Ledger.kt @@ -1,11 +1,15 @@ package moe.nea.ledger +import net.minecraft.client.Minecraft import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent import org.apache.logging.log4j.LogManager @Mod(modid = "ledger", useMetadata = true) @@ -52,9 +56,32 @@ class Ledger { BazaarDetection(ledger, ids), BazaarOrderDetection(ledger, ids), AuctionHouseDetection(ledger, ids), + BitsDetection(ledger), + BitsShop(ledger), ).forEach(MinecraftForge.EVENT_BUS::register) } + var lastJoin = -1L + + @SubscribeEvent + fun worldSwitchEvent(event: EntityJoinWorldEvent) { + if (event.entity == Minecraft.getMinecraft().thePlayer) { + lastJoin = System.currentTimeMillis() + } + } + + @SubscribeEvent + fun tickEvent(event: ClientTickEvent) { + if (event.phase == TickEvent.Phase.END + && lastJoin > 0 + && System.currentTimeMillis() - lastJoin > 10_000 + && Minecraft.getMinecraft().thePlayer != null + ) { + lastJoin = -1 + MinecraftForge.EVENT_BUS.post(LateWorldLoadEvent()) + } + } + @SubscribeEvent(receiveCanceled = true, priority = EventPriority.HIGHEST) fun onChat(event: ClientChatReceivedEvent) { if (event.type != 2.toByte()) diff --git a/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt b/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt index 83268e7..ba7fd96 100644 --- a/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt +++ b/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt @@ -60,6 +60,7 @@ class LedgerLogger { } fun logEntry(entry: LedgerEntry) { + printToChat(entry) Ledger.logger.info("Logging entry of type ${entry.transactionType}") entries.add(entry.intoJson()) commit() diff --git a/src/main/kotlin/moe/nea/ledger/NumberUtil.kt b/src/main/kotlin/moe/nea/ledger/NumberUtil.kt index 267a8c5..d26b047 100644 --- a/src/main/kotlin/moe/nea/ledger/NumberUtil.kt +++ b/src/main/kotlin/moe/nea/ledger/NumberUtil.kt @@ -27,7 +27,7 @@ fun parseShortNumber(string: String): Double { return k.toDouble() * scalarMultiplier } -fun <T> Pattern.useMatcher(string: String, block: Matcher.() -> T): T? = +inline fun <T> Pattern.useMatcher(string: String, block: Matcher.() -> T): T? = matcher(string).takeIf { it.matches() }?.let(block) fun String.unformattedString(): String = replace("§.".toRegex(), "")
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/ledger/ScoreboardUtil.kt b/src/main/kotlin/moe/nea/ledger/ScoreboardUtil.kt new file mode 100644 index 0000000..783664b --- /dev/null +++ b/src/main/kotlin/moe/nea/ledger/ScoreboardUtil.kt @@ -0,0 +1,29 @@ +package moe.nea.ledger + +import net.minecraft.client.Minecraft +import net.minecraft.scoreboard.ScorePlayerTeam + +object ScoreboardUtil { + + val sidebarSlot = 1 + fun getScoreboardStrings(): List<String> { + val scoreboard = Minecraft.getMinecraft().theWorld.scoreboard + val objective = scoreboard.getObjectiveInDisplaySlot(sidebarSlot) + val scoreList = scoreboard.getSortedScores(objective).take(15) + .map { + ScorePlayerTeam.formatPlayerName(scoreboard.getPlayersTeam(it.playerName), it.playerName) + } + .map { stripAlien(it) } + .reversed() + return scoreList + } + + fun stripAlien(string: String): String { + val sb = StringBuilder() + for (c in string) { + if (Minecraft.getMinecraft().fontRendererObj.getCharWidth(c) > 0 || c == '§') + sb.append(c) + } + return sb.toString() + } +}
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/ledger/WorldLoadEvent.kt b/src/main/kotlin/moe/nea/ledger/WorldLoadEvent.kt new file mode 100644 index 0000000..4b7fa6d --- /dev/null +++ b/src/main/kotlin/moe/nea/ledger/WorldLoadEvent.kt @@ -0,0 +1,5 @@ +package moe.nea.ledger + +import net.minecraftforge.fml.common.eventhandler.Event + +class LateWorldLoadEvent : Event() |