diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger')
12 files changed, 67 insertions, 37 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/ItemId.kt b/src/main/kotlin/moe/nea/ledger/ItemId.kt index f4786cd..8211cd3 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemId.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemId.kt @@ -1,12 +1,16 @@ package moe.nea.ledger +import moe.nea.ledger.utils.NoSideEffects + data class ItemId( val string: String ) { + @NoSideEffects fun singleItem(): Pair<ItemId, Double> { return withStackSize(1) } + @NoSideEffects fun withStackSize(size: Number): Pair<ItemId, Double> { return Pair(this, size.toDouble()) } @@ -15,6 +19,7 @@ data class ItemId( companion object { @JvmStatic + @NoSideEffects fun forName(string: String) = ItemId(string) fun skill(skill: String) = ItemId("SKYBLOCK_SKILL_$skill") @@ -22,25 +27,9 @@ data class ItemId( val FARMING = skill("FARMING") - val ARCHFIEND_DYE = ItemId("DYE_ARCHFIEND") - val ARCHFIEND_HIGH_CLASS = ItemId("HIGH_CLASS_ARCHFIEND_DICE") - val ARCHFIEND_LOW_CLASS = ItemId("ARCHFIEND_DICE") - val BITS = ItemId("SKYBLOCK_BIT") - val BOOSTER_COOKIE = ItemId("BOOSTER_COOKIE") - val CAP_EYEDROPS = ItemId("CAPSAICIN_EYEDROPS_NO_CHARGES") val COINS = ItemId("SKYBLOCK_COIN") - val COPPER = ItemId("SKYBLOCK_COPPER") - val DRAGON_ESSENCE = ItemId("ESSENCE_DRAGON") - val DUNGEON_CHEST_KEY = ItemId("DUNGEON_CHEST_KEY") - val FINE_FLOUR = ItemId("FINE_FLOUR") val GEMSTONE_POWDER = ItemId("SKYBLOCK_POWDER_GEMSTONE") - val GOD_POTION = ItemId("GOD_POTION_2") - val GOLD_ESSENCE = ItemId("ESSENCE_GOLD") - val KISMET_FEATHER = ItemId("KISMET_FEATHER") val MITHRIL_POWDER = ItemId("SKYBLOCK_POWDER_MITHRIL") val NIL = ItemId("SKYBLOCK_NIL") - val PELT = ItemId("SKYBLOCK_PELT") - val SLEEPING_EYE = ItemId("SLEEPING_EYE") - val SUMMONING_EYE = ItemId("SUMMONING_EYE") } }
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt index 4d85713..0bacf32 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt @@ -4,6 +4,7 @@ import moe.nea.ledger.events.BeforeGuiAction import moe.nea.ledger.events.ExtraSupplyIdEvent import moe.nea.ledger.events.RegistrationFinishedEvent import moe.nea.ledger.events.SupplyDebugInfo +import moe.nea.ledger.gen.ItemIds import moe.nea.ledger.modules.ExternalDataProvider import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack @@ -129,15 +130,15 @@ class ItemIdProvider { } etherialRewardPattern.useMatcher(properName) { val id = when (val id = group("what")) { - "Copper" -> ItemId.COPPER - "Bits" -> ItemId.BITS + "Copper" -> ItemIds.SKYBLOCK_COPPER + "Bits" -> ItemIds.SKYBLOCK_BIT "Garden Experience" -> ItemId.GARDEN "Farming XP" -> ItemId.FARMING - "Gold Essence" -> ItemId.GOLD_ESSENCE + "Gold Essence" -> ItemIds.ESSENCE_GOLD "Gemstone Powder" -> ItemId.GEMSTONE_POWDER "Mithril Powder" -> ItemId.MITHRIL_POWDER - "Pelts" -> ItemId.PELT - "Fine Flour" -> ItemId.FINE_FLOUR + "Pelts" -> ItemIds.SKYBLOCK_PELT + "Fine Flour" -> ItemIds.FINE_FLOUR else -> { id.ifDropLast(" Experience") { ItemId.skill(generateName(it).string) diff --git a/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt b/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt index dec0727..ec5548f 100644 --- a/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt +++ b/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt @@ -1,6 +1,7 @@ package moe.nea.ledger import com.google.gson.JsonObject +import moe.nea.ledger.gen.ItemIds import java.time.Instant import java.util.UUID @@ -10,8 +11,8 @@ data class LedgerEntry( val items: List<ItemChange>, ) { fun intoJson(profileId: UUID?): JsonObject { - val coinAmount = items.find { it.itemId == ItemId.COINS || it.itemId == ItemId.BITS }?.count - val nonCoins = items.find { it.itemId != ItemId.COINS && it.itemId != ItemId.BITS } + val coinAmount = items.find { it.itemId == ItemId.COINS || it.itemId == ItemIds.SKYBLOCK_BIT }?.count + val nonCoins = items.find { it.itemId != ItemId.COINS && it.itemId != ItemIds.SKYBLOCK_BIT } return JsonObject().apply { addProperty("transactionType", transactionType.name) addProperty("timestamp", timestamp.toEpochMilli().toString()) diff --git a/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt index e4c3c98..44a0050 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt @@ -9,6 +9,7 @@ import moe.nea.ledger.LedgerLogger import moe.nea.ledger.SHORT_NUMBER_PATTERN import moe.nea.ledger.ScoreboardUtil import moe.nea.ledger.TransactionType +import moe.nea.ledger.gen.ItemIds import moe.nea.ledger.parseShortNumber import moe.nea.ledger.unformattedString import moe.nea.ledger.useMatcher @@ -33,7 +34,7 @@ class BitsDetection @Inject constructor(val ledger: LedgerLogger) { TransactionType.BITS_PURSE_STATUS, Instant.now(), listOf( - ItemChange(ItemId.BITS, bits.toDouble(), ItemChange.ChangeDirection.SYNC) + ItemChange(ItemIds.SKYBLOCK_BIT, bits.toDouble(), ItemChange.ChangeDirection.SYNC) ) ) ) @@ -52,7 +53,7 @@ class BitsDetection @Inject constructor(val ledger: LedgerLogger) { TransactionType.BOOSTER_COOKIE_ATE, Instant.now(), listOf( - ItemChange.lose(ItemId.BOOSTER_COOKIE, 1) + ItemChange.lose(ItemIds.BOOSTER_COOKIE, 1) ) ) ) diff --git a/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt index d7e0a0d..553bebf 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt @@ -8,6 +8,7 @@ import moe.nea.ledger.LedgerEntry import moe.nea.ledger.LedgerLogger import moe.nea.ledger.SHORT_NUMBER_PATTERN import moe.nea.ledger.TransactionType +import moe.nea.ledger.gen.ItemIds import moe.nea.ledger.getInternalId import moe.nea.ledger.getLore import moe.nea.ledger.parseShortNumber @@ -54,8 +55,8 @@ class BitsShopDetection @Inject constructor(val ledger: LedgerLogger) { TransactionType.COMMUNITY_SHOP_BUY, Instant.now(), listOf( - ItemChange.lose(ItemId.BITS, lastBit.bitPrice.toDouble()), - ItemChange.gain(lastBit.id, lastBit.stackSize) + ItemChange.lose(ItemIds.SKYBLOCK_BIT, lastBit.bitPrice.toDouble()), + ItemChange.gain(lastBit.id, lastBit.stackSize) ) ) ) diff --git a/src/main/kotlin/moe/nea/ledger/modules/DragonEyePlacementDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/DragonEyePlacementDetection.kt index b9f70c4..e389ffb 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/DragonEyePlacementDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/DragonEyePlacementDetection.kt @@ -7,6 +7,7 @@ import moe.nea.ledger.LedgerLogger import moe.nea.ledger.TransactionType import moe.nea.ledger.events.ChatReceived import moe.nea.ledger.events.WorldSwitchEvent +import moe.nea.ledger.gen.ItemIds import moe.nea.ledger.useMatcher import moe.nea.ledger.utils.di.Inject import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -34,7 +35,7 @@ class DragonEyePlacementDetection { TransactionType.WYRM_EVOKED, event.timestamp, listOf( - ItemChange.lose(ItemId.SUMMONING_EYE, eyeCount) + ItemChange.lose(ItemIds.SUMMONING_EYE, eyeCount) ) )) eyeCount = 0 diff --git a/src/main/kotlin/moe/nea/ledger/modules/DragonSacrificeDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/DragonSacrificeDetection.kt index 20934d2..574cfcf 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/DragonSacrificeDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/DragonSacrificeDetection.kt @@ -9,6 +9,7 @@ import moe.nea.ledger.LedgerLogger import moe.nea.ledger.SHORT_NUMBER_PATTERN import moe.nea.ledger.TransactionType import moe.nea.ledger.events.ChatReceived +import moe.nea.ledger.gen.ItemIds import moe.nea.ledger.parseShortNumber import moe.nea.ledger.useMatcher import moe.nea.ledger.utils.di.Inject @@ -43,7 +44,7 @@ class DragonSacrificeDetection { event.timestamp, listOf( ItemChange.lose(sacrifice, 1), - ItemChange.gain(ItemId.DRAGON_ESSENCE, lootEssence) + ItemChange.gain(ItemIds.ESSENCE_DRAGON, lootEssence) ) )) } diff --git a/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt index feb452e..e747be9 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt @@ -2,19 +2,20 @@ package moe.nea.ledger.modules import moe.nea.ledger.ExpiringValue import moe.nea.ledger.ItemChange -import moe.nea.ledger.ItemId import moe.nea.ledger.LedgerEntry import moe.nea.ledger.LedgerLogger import moe.nea.ledger.TransactionType import moe.nea.ledger.events.ChatReceived import moe.nea.ledger.events.ExtraSupplyIdEvent import moe.nea.ledger.events.GuiClickEvent +import moe.nea.ledger.gen.ItemIds import moe.nea.ledger.getDisplayNameU import moe.nea.ledger.unformattedString import moe.nea.ledger.useMatcher import moe.nea.ledger.utils.di.Inject import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.time.Instant +import java.util.concurrent.locks.ReentrantLock import kotlin.time.Duration.Companion.seconds class DungeonChestDetection @Inject constructor(val logger: LedgerLogger) : ChestDetection() { @@ -30,7 +31,7 @@ class DungeonChestDetection @Inject constructor(val logger: LedgerLogger) : Ches TransactionType.KISMET_REROLL, Instant.now(), listOf( - ItemChange.lose(ItemId.KISMET_FEATHER, 1) + ItemChange.lose(ItemIds.KISMET_FEATHER, 1) ) ) ) @@ -42,8 +43,8 @@ class DungeonChestDetection @Inject constructor(val logger: LedgerLogger) : Ches @SubscribeEvent fun supplyExtraIds(event: ExtraSupplyIdEvent) { - event.store("Dungeon Chest Key", ItemId("DUNGEON_CHEST_KEY")) - event.store("Kismet Feather", ItemId("KISMET_FEATHER")) + event.store("Dungeon Chest Key", ItemIds.DUNGEON_CHEST_KEY) + event.store("Kismet Feather", ItemIds.KISMET_FEATHER) } @SubscribeEvent @@ -51,7 +52,31 @@ class DungeonChestDetection @Inject constructor(val logger: LedgerLogger) : Ches lastOpenedChest = ExpiringValue(scrapeChestReward(event.slotIn ?: return) ?: return) } - val rewardMessage = " .* CHEST REWARDS".toPattern() + class Mutex<T>(defaultValue: T) { + private var value: T = defaultValue + val lock = ReentrantLock() + + fun getUnsafeLockedValue(): T { + if (!lock.isHeldByCurrentThread) + error("Accessed unsafe locked value, without holding the lock.") + return value + } + + fun <R> withLock(func: (T) -> R): R { + lock.lockInterruptibly() + try { + val ret = func(value) + if (ret === value) { + error("Please don't smuggle out the locked value. If this is unintentional, please append a `Unit` instruction to the end of your `withLock` call: `.withLock { /* your existing code */; Unit }`.") + } + return ret + } finally { + lock.unlock() + } + } + } + + val rewardMessage = " (WOOD|GOLD|DIAMOND|EMERALD|OBSIDIAN|BEDROCK) CHEST REWARDS".toPattern() @SubscribeEvent fun onChatMessage(event: ChatReceived) { diff --git a/src/main/kotlin/moe/nea/ledger/modules/EyedropsDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/EyedropsDetection.kt index 2b1a8cd..04dbe80 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/EyedropsDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/EyedropsDetection.kt @@ -6,6 +6,7 @@ import moe.nea.ledger.LedgerEntry import moe.nea.ledger.LedgerLogger import moe.nea.ledger.TransactionType import moe.nea.ledger.events.ChatReceived +import moe.nea.ledger.gen.ItemIds import moe.nea.ledger.useMatcher import moe.nea.ledger.utils.di.Inject import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -25,7 +26,7 @@ class EyedropsDetection { TransactionType.CAPSAICIN_EYEDROPS_USED, event.timestamp, listOf( - ItemChange.lose(ItemId.CAP_EYEDROPS, 1) + ItemChange.lose(ItemIds.CAPSAICIN_EYEDROPS_NO_CHARGES, 1) ) ) ) diff --git a/src/main/kotlin/moe/nea/ledger/modules/GambleDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/GambleDetection.kt index 0ef43a2..a8f79c1 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/GambleDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/GambleDetection.kt @@ -24,7 +24,7 @@ class GambleDetection { fun onChat(event: ChatReceived) { dieRolled.useMatcher(event.message) { val isLowClass = group("isHighClass").isNullOrBlank() - val item = if (isLowClass) ItemId.ARCHFIEND_LOW_CLASS else ItemId.ARCHFIEND_HIGH_CLASS + val item = if (isLowClass) ItemIds.ARCHFIEND_DICE else ItemIds.HIGH_CLASS_ARCHFIEND_DICE val face = group("face") val rollCost = if (isLowClass) 666_000.0 else 6_600_000.0 if (face == "7") { diff --git a/src/main/kotlin/moe/nea/ledger/modules/GodPotionDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/GodPotionDetection.kt index 806feb0..ae86519 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/GodPotionDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/GodPotionDetection.kt @@ -6,6 +6,7 @@ import moe.nea.ledger.LedgerEntry import moe.nea.ledger.LedgerLogger import moe.nea.ledger.TransactionType import moe.nea.ledger.events.ChatReceived +import moe.nea.ledger.gen.ItemIds import moe.nea.ledger.useMatcher import moe.nea.ledger.utils.di.Inject import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -25,7 +26,7 @@ class GodPotionDetection { TransactionType.GOD_POTION_DRANK, event.timestamp, listOf( - ItemChange.lose(ItemId.GOD_POTION, 1) + ItemChange.lose(ItemIds.GOD_POTION_2, 1) ) ) ) diff --git a/src/main/kotlin/moe/nea/ledger/utils/NoSideEffects.java b/src/main/kotlin/moe/nea/ledger/utils/NoSideEffects.java new file mode 100644 index 0000000..f432130 --- /dev/null +++ b/src/main/kotlin/moe/nea/ledger/utils/NoSideEffects.java @@ -0,0 +1,8 @@ +package moe.nea.ledger.utils; + +import kotlin.annotation.AnnotationRetention; +import kotlin.annotation.Retention; + +@Retention(AnnotationRetention.BINARY) +public @interface NoSideEffects { +} |