aboutsummaryrefslogtreecommitdiff
path: root/mod/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'mod/src/main/kotlin')
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/ConfigCommand.kt31
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/DebouncedValue.kt38
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/DebugDataCommand.kt34
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/DevUtil.kt7
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/ExpiringValue.kt30
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/ItemChange.kt84
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/ItemId.kt35
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt188
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/ItemUtil.kt90
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/Ledger.kt205
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt29
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt136
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/LogChatCommand.kt27
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/MCUUIDUtil.kt22
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/NumberUtil.kt117
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/QueryCommand.kt197
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/ScoreboardUtil.kt29
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt66
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/TransactionType.kt35
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/TriggerCommand.kt34
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/config/DebugOptions.kt13
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/config/LedgerConfig.kt35
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/config/MainOptions.kt27
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/config/SynchronizationOptions.kt11
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/config/UpdateUi.kt17
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/config/UpdateUiMarker.kt6
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/database/DBLogEntry.kt24
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/database/DBUpgrade.kt68
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/database/Database.kt57
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/database/Upgrades.kt20
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/database/schema.dot23
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt11
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/ChatReceived.kt15
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/ExtraSupplyIdEvent.kt12
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/GuiClickEvent.kt9
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/InitializationComplete.kt6
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/RegistrationFinishedEvent.kt7
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/SupplyDebugInfo.kt10
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/TriggerEvent.kt7
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/WorldLoadEvent.kt5
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/events/WorldSwitchEvent.kt6
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/AccessorySwapperDetection.kt34
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/AllowanceDetection.kt37
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt143
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt49
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt58
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt95
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt62
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt66
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/ChestDetection.kt48
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/DragonEyePlacementDetection.kt47
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/DragonSacrificeDetection.kt72
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt95
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/ExternalDataProvider.kt43
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/EyedropsDetection.kt35
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/ForgeDetection.kt48
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/GambleDetection.kt62
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/GodPotionDetection.kt35
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/GodPotionMixinDetection.kt38
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt95
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/KuudraChestDetection.kt45
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/MineshaftCorpseDetection.kt81
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt61
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt111
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/UpdateChecker.kt167
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/modules/VisitorDetection.kt87
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt41
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt52
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/GsonUtil.kt10
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/MinecraftExecutor.kt10
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/NoSideEffects.kt4
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/network/Request.kt40
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/network/RequestUtil.kt63
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/network/Response.kt19
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/BooleanContext.kt10
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/CommonKeys.kt9
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/Context.kt57
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/ContextValue.kt70
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/EventRecorder.kt9
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt39
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/JsonElementContext.kt9
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/LoggingEventRecorder.kt25
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/RecordedEvent.kt5
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/Severity.kt8
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt146
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/StringContext.kt11
86 files changed, 4174 insertions, 0 deletions
diff --git a/mod/src/main/kotlin/moe/nea/ledger/ConfigCommand.kt b/mod/src/main/kotlin/moe/nea/ledger/ConfigCommand.kt
new file mode 100644
index 0000000..5b964c8
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/ConfigCommand.kt
@@ -0,0 +1,31 @@
+package moe.nea.ledger
+
+import io.github.notenoughupdates.moulconfig.common.IMinecraft
+import net.minecraft.command.CommandBase
+import net.minecraft.command.ICommandSender
+
+class ConfigCommand : CommandBase() {
+ override fun canCommandSenderUseCommand(sender: ICommandSender?): Boolean {
+ return true
+ }
+
+ override fun getCommandName(): String {
+ return "ledgerconfig"
+ }
+
+ override fun getCommandUsage(sender: ICommandSender?): String {
+ return ""
+ }
+
+ override fun processCommand(sender: ICommandSender?, args: Array<out String>) {
+ val editor = Ledger.managedConfig.getEditor()
+ editor.search(args.joinToString(" "))
+ Ledger.runLater {
+ IMinecraft.instance.openWrappedScreen(editor)
+ }
+ }
+
+ override fun getCommandAliases(): List<String> {
+ return listOf("moneyledger")
+ }
+} \ No newline at end of file
diff --git a/mod/src/main/kotlin/moe/nea/ledger/DebouncedValue.kt b/mod/src/main/kotlin/moe/nea/ledger/DebouncedValue.kt
new file mode 100644
index 0000000..66fba8d
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/DebouncedValue.kt
@@ -0,0 +1,38 @@
+package moe.nea.ledger
+
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.nanoseconds
+import kotlin.time.Duration.Companion.seconds
+
+class DebouncedValue<T>(private val value: T) {
+ companion object {
+ fun <T> farFuture(): DebouncedValue<T> {
+ val value = DebouncedValue(Unit)
+ value.take()
+ @Suppress("UNCHECKED_CAST")
+ return value as DebouncedValue<T>
+ }
+ }
+
+ val lastSeenAt = System.nanoTime()
+ val age get() = (System.nanoTime() - lastSeenAt).nanoseconds
+ var taken = false
+ private set
+
+ fun get(debounce: Duration): T? {
+ return if (!taken && age >= debounce) value
+ else null
+ }
+
+ fun replace(): T? {
+ return consume(0.seconds)
+ }
+
+ fun consume(debounce: Duration): T? {
+ return get(debounce)?.also { take() }
+ }
+
+ fun take() {
+ taken = true
+ }
+} \ No newline at end of file
diff --git a/mod/src/main/kotlin/moe/nea/ledger/DebugDataCommand.kt b/mod/src/main/kotlin/moe/nea/ledger/DebugDataCommand.kt
new file mode 100644
index 0000000..bab0a78
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/DebugDataCommand.kt
@@ -0,0 +1,34 @@
+package moe.nea.ledger
+
+import moe.nea.ledger.events.SupplyDebugInfo
+import moe.nea.ledger.utils.di.Inject
+import net.minecraft.command.CommandBase
+import net.minecraft.command.ICommandSender
+import net.minecraftforge.common.MinecraftForge
+
+class DebugDataCommand : CommandBase() {
+
+ override fun canCommandSenderUseCommand(sender: ICommandSender?): Boolean {
+ return true
+ }
+
+ override fun getCommandName(): String {
+ return "ledgerdebug"
+ }
+
+ override fun getCommandUsage(sender: ICommandSender?): String {
+ return ""
+ }
+
+ @Inject
+ lateinit var logger: LedgerLogger
+
+ override fun processCommand(sender: ICommandSender?, args: Array<out String>?) {
+ val debugInfo = SupplyDebugInfo()
+ MinecraftForge.EVENT_BUS.post(debugInfo)
+ logger.printOut("Collected debug info:")
+ debugInfo.data.forEach {
+ logger.printOut("${it.first}: ${it.second}")
+ }
+ }
+} \ No newline at end of file
diff --git a/mod/src/main/kotlin/moe/nea/ledger/DevUtil.kt b/mod/src/main/kotlin/moe/nea/ledger/DevUtil.kt
new file mode 100644
index 0000000..d0dd653
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/DevUtil.kt
@@ -0,0 +1,7 @@
+package moe.nea.ledger
+
+import net.minecraft.launchwrapper.Launch
+
+object DevUtil {
+ val isDevEnv = Launch.blackboard["fml.deobfuscatedEnvironment"] as Boolean
+} \ No newline at end of file
diff --git a/mod/src/main/kotlin/moe/nea/ledger/ExpiringValue.kt b/mod/src/main/kotlin/moe/nea/ledger/ExpiringValue.kt
new file mode 100644
index 0000000..b50b14e
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/ExpiringValue.kt
@@ -0,0 +1,30 @@
+package moe.nea.ledger
+
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.nanoseconds
+
+class ExpiringValue<T>(private val value: T) {
+ val lastSeenAt: Long = System.nanoTime()
+ val age get() = (System.nanoTime() - lastSeenAt).nanoseconds
+ var taken = false
+ private set
+
+ fun get(expiry: Duration): T? {
+ return if (!taken && age < expiry) value
+ else null
+ }
+
+ companion object {
+ fun <T> empty(): ExpiringValue<T> {
+ val value = ExpiringValue(Unit)
+ value.take()
+ @Suppress("UNCHECKED_CAST")
+ return value as ExpiringValue<T>
+ }
+ }
+
+ fun consume(expiry: Duration): T? = get(expiry)?.also { take() }
+ fun take() {
+ taken = true
+ }
+} \ No newline at end of file
diff --git a/mod/src/main/kotlin/moe/nea/ledger/ItemChange.kt b/mod/src/main/kotlin/moe/nea/ledger/ItemChange.kt
new file mode 100644
index 0000000..fda709c
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/ItemChange.kt
@@ -0,0 +1,84 @@
+package moe.nea.ledger
+
+import moe.nea.ledger.database.DBItemEntry
+import moe.nea.ledger.database.ResultRow
+import net.minecraft.event.HoverEvent
+import net.minecraft.util.ChatComponentText
+import net.minecraft.util.ChatStyle
+import net.minecraft.util.EnumChatFormatting
+import net.minecraft.util.IChatComponent
+
+data class ItemChange(
+ val itemId: ItemId,
+ val count: Double,
+ val direction: ChangeDirection,
+) {
+ fun formatChat(): IChatComponent {
+ return ChatComponentText(" ")
+ .appendSibling(direction.chatFormat)
+ .appendText(" ")
+ .appendSibling(ChatComponentText("$count").setChatStyle(ChatStyle().setColor(EnumChatFormatting.WHITE)))
+ .appendSibling(ChatComponentText("x").setChatStyle(ChatStyle().setColor(EnumChatFormatting.DARK_GRAY)))
+ .appendText(" ")
+ .appendSibling(ChatComponentText(itemId.string).setChatStyle(ChatStyle().setParentStyle(ChatStyle().setColor(
+ EnumChatFormatting.WHITE))))
+ }
+
+ enum class ChangeDirection {
+ GAINED,
+ TRANSFORM,
+ SYNC,
+ CATALYST,
+ LOST;
+
+ val chatFormat by lazy { formatChat0() }
+ private fun formatChat0(): IChatComponent {
+ val (text, color) = when (this) {
+ GAINED -> "+" to EnumChatFormatting.GREEN
+ TRANSFORM -> "~" to EnumChatFormatting.YELLOW
+ SYNC -> "=" to EnumChatFormatting.BLUE
+ CATALYST -> "*" to EnumChatFormatting.DARK_PURPLE
+ LOST -> "-" to EnumChatFormatting.RED
+ }
+ return ChatComponentText(text)
+ .setChatStyle(
+ ChatStyle()
+ .setColor(color)
+ .setChatHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT,
+ ChatComponentText(name).setChatStyle(ChatStyle().setColor(color)))))
+ }
+ }
+
+ companion object {
+ fun gainCoins(number: Double): ItemChange {
+ return gain(ItemId.COINS, number)
+ }
+
+ fun unpair(direction: ChangeDirection, pair: Pair<ItemId, Double>): ItemChange {
+ return ItemChange(pair.first, pair.second, direction)
+ }
+
+ fun unpairGain(pair: Pair<ItemId, Double>) = unpair(ChangeDirection.GAINED, pair)
+ fun unpairLose(pair: Pair<ItemId, Double>) = unpair(ChangeDirection.LOST, pair)
+
+ fun gain(itemId: ItemId, amount: Number): ItemChange {
+ return ItemChange(itemId, amount.toDouble(), ChangeDirection.GAINED)
+ }
+
+ fun lose(itemId: ItemId, amount: Number): ItemChange {
+ return ItemChange(itemId, amount.toDouble(), ChangeDirection.LOST)
+ }
+
+ fun loseCoins(number: Double): ItemChange {
+ return lose(ItemId.COINS, number)
+ }
+
+ fun from(result: ResultRow): ItemChange {
+ return ItemChange(
+ result[DBItemEntry.itemId],
+ result[DBItemEntry.size],
+ result[DBItemEntry.mode],
+ )
+ }
+ }
+} \ No newline at end of file
diff --git a/mod/src/main/kotlin/moe/nea/ledger/ItemId.kt b/mod/src/main/kotlin/moe/nea/ledger/ItemId.kt
new file mode 100644
index 0000000..8211cd3
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/ItemId.kt
@@ -0,0 +1,35 @@
+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())
+ }
+
+
+ companion object {
+
+ @JvmStatic
+ @NoSideEffects
+ fun forName(string: String) = ItemId(string)
+ fun skill(skill: String) = ItemId("SKYBLOCK_SKILL_$skill")
+
+ val GARDEN = skill("GARDEN")
+ val FARMING = skill("FARMING")
+
+
+ val COINS = ItemId("SKYBLOCK_COIN")
+ val GEMSTONE_POWDER = ItemId("SKYBLOCK_POWDER_GEMSTONE")
+ val MITHRIL_POWDER = ItemId("SKYBLOCK_POWDER_MITHRIL")
+ val NIL = ItemId("SKYBLOCK_NIL")
+ }
+} \ No newline at end of file
diff --git a/mod/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/mod/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
new file mode 100644
index 0000000..0bacf32
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
@@ -0,0 +1,188 @@
+package moe.nea.ledger
+
+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.It