aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/moe/nea/ledger/events/RegistrationFinishedEvent.kt7
-rw-r--r--src/main/java/moe/nea/ledger/init/AutoDiscoveryMixinPlugin.java188
-rw-r--r--src/main/java/moe/nea/ledger/mixin/AccessorGuiEditSign.java12
-rw-r--r--src/main/java/moe/nea/ledger/mixin/MouseClickEventPatch.java18
-rw-r--r--src/main/java/moe/nea/ledger/mixin/OnInitializationCompletePatch.java18
-rw-r--r--src/main/kotlin/moe/nea/ledger/ConfigCommand.kt31
-rw-r--r--src/main/kotlin/moe/nea/ledger/DebugDataCommand.kt34
-rw-r--r--src/main/kotlin/moe/nea/ledger/DevUtil.kt7
-rw-r--r--src/main/kotlin/moe/nea/ledger/ExpiringValue.kt28
-rw-r--r--src/main/kotlin/moe/nea/ledger/ItemChange.kt84
-rw-r--r--src/main/kotlin/moe/nea/ledger/ItemId.kt37
-rw-r--r--src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt179
-rw-r--r--src/main/kotlin/moe/nea/ledger/ItemUtil.kt90
-rw-r--r--src/main/kotlin/moe/nea/ledger/Ledger.kt187
-rw-r--r--src/main/kotlin/moe/nea/ledger/LedgerEntry.kt28
-rw-r--r--src/main/kotlin/moe/nea/ledger/LedgerLogger.kt135
-rw-r--r--src/main/kotlin/moe/nea/ledger/LogChatCommand.kt27
-rw-r--r--src/main/kotlin/moe/nea/ledger/NumberUtil.kt117
-rw-r--r--src/main/kotlin/moe/nea/ledger/QueryCommand.kt196
-rw-r--r--src/main/kotlin/moe/nea/ledger/ScoreboardUtil.kt29
-rw-r--r--src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt66
-rw-r--r--src/main/kotlin/moe/nea/ledger/TransactionType.kt28
-rw-r--r--src/main/kotlin/moe/nea/ledger/TriggerCommand.kt34
-rw-r--r--src/main/kotlin/moe/nea/ledger/UUIDUtil.kt43
-rw-r--r--src/main/kotlin/moe/nea/ledger/config/DebugOptions.kt13
-rw-r--r--src/main/kotlin/moe/nea/ledger/config/LedgerConfig.kt35
-rw-r--r--src/main/kotlin/moe/nea/ledger/config/MainOptions.kt27
-rw-r--r--src/main/kotlin/moe/nea/ledger/config/SynchronizationOptions.kt11
-rw-r--r--src/main/kotlin/moe/nea/ledger/config/UpdateUi.kt17
-rw-r--r--src/main/kotlin/moe/nea/ledger/config/UpdateUiMarker.kt6
-rw-r--r--src/main/kotlin/moe/nea/ledger/database/DBLogEntry.kt19
-rw-r--r--src/main/kotlin/moe/nea/ledger/database/DBSchema.kt545
-rw-r--r--src/main/kotlin/moe/nea/ledger/database/DBUpgrade.kt68
-rw-r--r--src/main/kotlin/moe/nea/ledger/database/Database.kt54
-rw-r--r--src/main/kotlin/moe/nea/ledger/database/Upgrades.kt20
-rw-r--r--src/main/kotlin/moe/nea/ledger/database/schema.dot23
-rw-r--r--src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt11
-rw-r--r--src/main/kotlin/moe/nea/ledger/events/ChatReceived.kt15
-rw-r--r--src/main/kotlin/moe/nea/ledger/events/ExtraSupplyIdEvent.kt12
-rw-r--r--src/main/kotlin/moe/nea/ledger/events/GuiClickEvent.kt9
-rw-r--r--src/main/kotlin/moe/nea/ledger/events/InitializationComplete.kt6
-rw-r--r--src/main/kotlin/moe/nea/ledger/events/SupplyDebugInfo.kt10
-rw-r--r--src/main/kotlin/moe/nea/ledger/events/TriggerEvent.kt7
-rw-r--r--src/main/kotlin/moe/nea/ledger/events/WorldLoadEvent.kt5
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt143
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt49
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt58
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt95
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt61
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt65
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/ChestDetection.kt48
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt70
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/ExternalDataProvider.kt43
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/ForgeDetection.kt48
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/GambleDetection.kt61
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt95
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/KuudraChestDetection.kt45
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/MineshaftCorpseDetection.kt81
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt61
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt111
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/UpdateChecker.kt149
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/VisitorDetection.kt87
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt41
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt52
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/GsonUtil.kt10
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/MinecraftExecutor.kt10
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/di/DI.kt78
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt52
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt6
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/network/Request.kt40
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/network/RequestUtil.kt63
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/network/Response.kt19
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/BooleanContext.kt10
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/CommonKeys.kt9
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/Context.kt57
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/ContextValue.kt70
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/EventRecorder.kt9
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt39
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/JsonElementContext.kt9
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/LoggingEventRecorder.kt25
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/RecordedEvent.kt5
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/Severity.kt8
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt146
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/StringContext.kt11
-rw-r--r--src/main/resources/ledgerkeystore.jksbin104393 -> 0 bytes
-rw-r--r--src/main/resources/mcmod.info18
-rw-r--r--src/main/resources/mixins.moneyledger.json8
87 files changed, 0 insertions, 4701 deletions
diff --git a/src/main/java/moe/nea/ledger/events/RegistrationFinishedEvent.kt b/src/main/java/moe/nea/ledger/events/RegistrationFinishedEvent.kt
deleted file mode 100644
index d36e0c7..0000000
--- a/src/main/java/moe/nea/ledger/events/RegistrationFinishedEvent.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package moe.nea.ledger.events
-
-import net.minecraftforge.fml.common.eventhandler.Event
-
-class RegistrationFinishedEvent : Event() {
-
-}
diff --git a/src/main/java/moe/nea/ledger/init/AutoDiscoveryMixinPlugin.java b/src/main/java/moe/nea/ledger/init/AutoDiscoveryMixinPlugin.java
deleted file mode 100644
index 2c3a9c7..0000000
--- a/src/main/java/moe/nea/ledger/init/AutoDiscoveryMixinPlugin.java
+++ /dev/null
@@ -1,188 +0,0 @@
-package moe.nea.ledger.init;
-
-import org.spongepowered.asm.lib.tree.ClassNode;
-import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
-import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Stream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-/**
- * A mixin plugin to automatically discover all mixins in the current JAR.
- * <p>
- * This mixin plugin automatically scans your entire JAR (or class directory, in case of an in-IDE launch) for classes inside of your
- * mixin package and registers those. It does this recursively for sub packages of the mixin package as well. This means you will need
- * to only have mixin classes inside of your mixin package, which is good style anyway.
- *
- * @author Linnea Gräf
- */
-public class AutoDiscoveryMixinPlugin implements IMixinConfigPlugin {
- private static final List<AutoDiscoveryMixinPlugin> mixinPlugins = new ArrayList<>();
-
- public static List<AutoDiscoveryMixinPlugin> getMixinPlugins() {
- return mixinPlugins;
- }
-
- private String mixinPackage;
-
- @Override
- public void onLoad(String mixinPackage) {
- this.mixinPackage = mixinPackage;
- mixinPlugins.add(this);
- }
-
- /**
- * Resolves the base class root for a given class URL. This resolves either the JAR root, or the class file root.
- * In either case the return value of this + the class name will resolve back to the original class url, or to other
- * class urls for other classes.
- */
- public URL getBaseUrlForClassUrl(URL classUrl) {
- String string = classUrl.toString();
- if (classUrl.getProtocol().equals("jar")) {
- try {
- return new URL(string.substring(4).split("!")[0]);
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
- if (string.endsWith(".class")) {
- try {
- return new URL(string.replace("\\", "/")
- .replace(getClass().getCanonicalName()
- .replace(".", "/") + ".class", ""));
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
- return classUrl;
- }
-
- /**
- * Get the package that contains all the mixins. This value is set by mixin itself using {@link #onLoad}.
- */
- public String getMixinPackage() {
- return mixinPackage;
- }
-
- /**
- * Get the path inside the class root to the mixin package
- */
- public String getMixinBaseDir() {
- return mixinPackage.replace(".", "/");
- }
-
- /**
- * A list of all discovered mixins.
- */
- private List<String> mixins = null;
-
- /**
- * Try to add mixin class ot the mixins based on the filepath inside of the class root.
- * Removes the {@code .class} file suffix, as well as the base mixin package.
- * <p><b>This method cannot be called after mixin initialization.</p>
- *
- * @param className the name or path of a class to be registered as a mixin.
- */
- public void tryAddMixinClass(String className) {
- String norm = (className.endsWith(".class") ? className.substring(0, className.length() - ".class".length()) : className)
- .replace("\\", "/")
- .replace("/", ".");
- if (norm.startsWith(getMixinPackage() + ".") && !norm.endsWith(".")) {
- mixins.add(norm.substring(getMixinPackage().length() + 1));
- }
- }
-
- /**
- * Search through the JAR or class directory to find mixins contained in {@link #getMixinPackage()}
- */
- @Override
- public List<String> getMixins() {
- if (mixins != null) return mixins;
- System.out.println("Trying to discover mixins");
- mixins = new ArrayList<>();
- URL classUrl = getClass().getProtectionDomain().getCodeSource().getLocation();
- System.out.println("Found classes at " + classUrl);
- Path file;
- try {
- file = Paths.get(getBaseUrlForClassUrl(classUrl).toURI());
- } catch (URISyntaxException e) {
- throw new RuntimeException(e);
- }
- System.out.println("Base directory found at " + file);
- if (Files.isDirectory(file)) {
- walkDir(file);
- } else {
- walkJar(file);
- }
- System.out.println("Found mixins: " + mixins);
-
- return mixins;
- }
-
- /**
- * Search through directory for mixin classes based on {@link #getMixinBaseDir}.
- *
- * @param classRoot The root directory in which classes are stored for the default package.
- */
- private void walkDir(Path classRoot) {
- System.out.println("Trying to find mixins from directory");
- try (Stream<Path> classes = Files.walk(classRoot.resolve(getMixinBaseDir()))) {
- classes.map(it -> classRoot.relativize(it).toString())
- .forEach(this::tryAddMixinClass);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Read through a JAR file, trying to find all mixins inside.
- */
- private void walkJar(Path file) {
- System.out.println("Trying to find mixins from jar file");
- try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(file))) {
- ZipEntry next;
- while ((next = zis.getNextEntry()) != null) {
- tryAddMixinClass(next.getName());
- zis.closeEntry();
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
-
- }
-
- @Override
- public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
-
- }
-
- @Override
- public String getRefMapperConfig() {
- return null;
- }
-
- @Override
- public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
- return true;
- }
-
- @Override
- public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
-
- }
-}
diff --git a/src/main/java/moe/nea/ledger/mixin/AccessorGuiEditSign.java b/src/main/java/moe/nea/ledger/mixin/AccessorGuiEditSign.java
deleted file mode 100644
index 52b8911..0000000
--- a/src/main/java/moe/nea/ledger/mixin/AccessorGuiEditSign.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package moe.nea.ledger.mixin;
-
-import net.minecraft.client.gui.inventory.GuiEditSign;
-import net.minecraft.tileentity.TileEntitySign;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.gen.Accessor;
-
-@Mixin(GuiEditSign.class)
-public interface AccessorGuiEditSign {
- @Accessor("tileSign")
- TileEntitySign getTileEntity_ledger();
-}
diff --git a/src/main/java/moe/nea/ledger/mixin/MouseClickEventPatch.java b/src/main/java/moe/nea/ledger/mixin/MouseClickEventPatch.java
deleted file mode 100644
index 4e6e360..0000000
--- a/src/main/java/moe/nea/ledger/mixin/MouseClickEventPatch.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package moe.nea.ledger.mixin;
-
-import moe.nea.ledger.events.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/mixin/OnInitializationCompletePatch.java b/src/main/java/moe/nea/ledger/mixin/OnInitializationCompletePatch.java
deleted file mode 100644
index fc9afb7..0000000
--- a/src/main/java/moe/nea/ledger/mixin/OnInitializationCompletePatch.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package moe.nea.ledger.mixin;
-
-import moe.nea.ledger.events.InitializationComplete;
-import net.minecraft.client.Minecraft;
-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(Minecraft.class)
-public class OnInitializationCompletePatch {
-
- @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;onInitializationComplete()V"))
- private void onInitComplete(CallbackInfo ci) {
- MinecraftForge.EVENT_BUS.post(new InitializationComplete());
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/ConfigCommand.kt b/src/main/kotlin/moe/nea/ledger/ConfigCommand.kt
deleted file mode 100644
index 5b964c8..0000000
--- a/src/main/kotlin/moe/nea/ledger/ConfigCommand.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-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/src/main/kotlin/moe/nea/ledger/DebugDataCommand.kt b/src/main/kotlin/moe/nea/ledger/DebugDataCommand.kt
deleted file mode 100644
index bab0a78..0000000
--- a/src/main/kotlin/moe/nea/ledger/DebugDataCommand.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-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/src/main/kotlin/moe/nea/ledger/DevUtil.kt b/src/main/kotlin/moe/nea/ledger/DevUtil.kt
deleted file mode 100644
index d0dd653..0000000
--- a/src/main/kotlin/moe/nea/ledger/DevUtil.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-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/src/main/kotlin/moe/nea/ledger/ExpiringValue.kt b/src/main/kotlin/moe/nea/ledger/ExpiringValue.kt
deleted file mode 100644
index dac4751..0000000
--- a/src/main/kotlin/moe/nea/ledger/ExpiringValue.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-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
- fun get(expiry: Duration): T? {
- return if (!taken && expiry > age) 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/src/main/kotlin/moe/nea/ledger/ItemChange.kt b/src/main/kotlin/moe/nea/ledger/ItemChange.kt
deleted file mode 100644
index fda709c..0000000
--- a/src/main/kotlin/moe/nea/ledger/ItemChange.kt
+++ /dev/null
@@ -1,84 +0,0 @@
-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/src/main/kotlin/moe/nea/ledger/ItemId.kt b/src/main/kotlin/moe/nea/ledger/ItemId.kt
deleted file mode 100644
index 2b83357..0000000
--- a/src/main/kotlin/moe/nea/ledger/ItemId.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-package moe.nea.ledger
-
-@JvmInline
-value class ItemId(
- val string: String
-) {
- fun singleItem(): Pair<ItemId, Double> {
- return withStackSize(1)
- }
-
- fun withStackSize(size: Number): Pair<ItemId, Double> {
- return Pair(this, size.toDouble())
- }
-
-
- companion object {
- fun skill(skill: String) = ItemId("SKYBLOCK_SKILL_$skill")
-
- val GARDEN = skill("GARDEN")
- val FARMING = skill("FARMING")
- val GEMSTONE_POWDER = ItemId("SKYBLOCK_POWDER_GEMSTONE")
- val MITHRIL_POWDER = ItemId("SKYBLOCK_POWDER_MITHRIL")
- val GOLD_ESSENCE = ItemId("ESSENCE_GOLD")
- val PELT = ItemId("SKYBLOCK_PELT")
- val COINS = ItemId("SKYBLOCK_COIN")
- val FINE_FLOUR = ItemId("FINE_FLOUR")
- val BITS = ItemId("SKYBLOCK_BIT")
- val COPPER = ItemId("SKYBLOCK_COPPER")
- val NIL = ItemId("SKYBLOCK_NIL")
- val ARCHFIEND_LOW_CLASS = ItemId("ARCHFIEND_DICE")
- val ARCHFIEND_HIGH_CLASS = ItemId("HIGH_CLASS_ARCHFIEND_DICE")
- val ARCHFIEND_DYE = ItemId("DYE_ARCHFIEND")
- val DUNGEON_CHEST_KEY = ItemId("DUNGEON_CHEST_KEY")
- val BOOSTER_COOKIE = ItemId("BOOSTER_COOKIE")
- val KISMET_FEATHER = ItemId("KISMET_FEATHER")
- }
-} \ 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
deleted file mode 100644
index 7fe0206..0000000
--- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
+++ /dev/null
@@ -1,179 +0,0 @@
-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.modules.ExternalDataProvider
-import net.minecraft.client.Minecraft
-import net.minecraft.item.ItemStack
-import net.minecraft.nbt.NBTTagCompound
-import net.minecraftforge.client.event.GuiScreenEvent
-import net.minecraftforge.common.MinecraftForge
-import net.minecraftforge.fml.common.eventhandler.EventPriority
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import org.lwjgl.input.Mouse
-
-class ItemIdProvider {
-
- @SubscribeEvent
- fun onMouseInput(event: GuiScreenEvent.MouseInputEvent.Pre) {
- if (Mouse.getEventButton() == -1) return
- MinecraftForge.EVENT_BUS.post(BeforeGuiAction(event.gui))
- }
-
- @SubscribeEvent
- fun onKeyInput(event: GuiScreenEvent.KeyboardInputEvent.Pre) {
- MinecraftForge.EVENT_BUS.post(BeforeGuiAction(event.gui))
- }
-
- private val knownNames = mutableMapOf<String, ItemId>()
-
- fun createLookupTagFromDisplayName(itemName: String): String {
- return itemName.unformattedString().trim().lowercase()
- }
-
- fun saveKnownItem(itemName: String, itemId: ItemId) {
- knownNames[createLookupTagFromDisplayName(itemName)] = itemId
- }
-
- @SubscribeEvent
- fun onDataLoaded(event: ExternalDataProvider.DataLoaded) {
- event.provider.itemNames.forEach { (itemId, itemName) ->
- saveKnownItem(itemName, ItemId(itemId))
- }
- }
-
- @SubscribeEvent
- fun onRegistrationFinished(event: RegistrationFinishedEvent) {
- MinecraftForge.EVENT_BUS.post(ExtraSupplyIdEvent(::saveKnownItem))
- }
-
- @SubscribeEvent(priority = EventPriority.HIGH)
- fun savePlayerInventoryIds(event: BeforeGuiAction) {
- val player = Minecraft.getMinecraft().thePlayer ?: return
- val inventory = player.inventory ?: return
- inventory.mainInventory?.forEach { saveFromSlot(it) }
- inventory.armorInventory?.forEach { saveFromSlot(it) }
- }
-
- @SubscribeEvent
- fun onDebugData(event: SupplyDebugInfo) {
- event.record("knownItemNames", knownNames.size)
- }
-
- fun saveFromSlot(stack: ItemStack?, preprocessName: (String) -> String = { it }) {
- if (stack == null) return
- val nbt = stack.tagCompound ?: NBTTagCompound()
- val display = nbt.getCompoundTag("display")
- var name = display.getString("Name").unformattedString()
- name = preprocessName(name)
- name = name.trim()
- val id = stack.getInternalId()
- if (id != null && name.isNotBlank()) {
- saveKnownItem(name, id)
- }
- }
-
- @SubscribeEvent(priority = EventPriority.HIGH)
- fun saveChestInventoryIds(event: BeforeGuiAction) {
- val slots = event.chestSlots ?: return
- val chestName = slots.lowerChestInventory.name.unformattedString()
- val isOrderMenu = chestName == "Your Bazaar Orders" || chestName == "Co-op Bazaar Orders"
- val preprocessor: (String) -> String = if (isOrderMenu) {
- { it.removePrefix("BUY ").removePrefix("SELL ") }
- } else {
- { it }
- }
- slots.inventorySlots.forEach {
- saveFromSlot(it?.stack, preprocessor)
- }
- }
-
- // TODO: make use of colour
- fun findForName(name: String, fallbackToGenerated: Boolean = true): ItemId? {
- var id = knownNames[createLookupTagFromDisplayName(name)]
- if (id == null && fallbackToGenerated) {
- id = generateName(name)
- }
- return id
- }
-
- fun generateName(name: String): ItemId {
- return ItemId(name.uppercase().replace(" ", "_"))
- }
-
- private val coinRegex = "(?<amount>$SHORT_NUMBER_PATTERN) Coins?".toPattern()
- private val stackedItemRegex = "(?<name>.*) x(?<count>$SHORT_NUMBER_PATTERN)".toPattern()
- private val essenceRegex = "(?<essence>.*) Essence x(?<count>$SHORT_NUMBER_PATTERN)".toPattern()
- private val numberedItemRegex = "(?<count>$SHORT_NUMBER_PATTERN) (?<what>.*)".toPattern()
-
- fun findCostItemsFromSpan(lore: List<String>): List<Pair<ItemId, Double>> {
- return lore.iterator().asSequence()
- .dropWhile { it.unformattedString() != "Cost" }.drop(1)
- .takeWhile { it != "" }
- .map { findStackableItemByName(it) ?: Pair(ItemId.NIL, 1.0) }
- .toList()
- }
-
- private val etherialRewardPattern = "\\+(?<amount>${SHORT_NUMBER_PATTERN})x? (?<what>.*)".toPattern()
-
- fun findStackableItemByName(name: String, fallbackToGenerated: Boolean = false): Pair<ItemId, Double>? {
- val properName = name.unformattedString().trim()
- if (properName == "FREE" || properName == "This Chest is Free!") {
- return Pair(ItemId.COINS, 0.0)
- }
- coinRegex.useMatcher(properName) {
- return Pair(ItemId.COINS, parseShortNumber(group("amount")))
- }
- etherialRewardPattern.useMatcher(properName) {
- val id = when (val id = group("what")) {
- "Copper" -> ItemId.COPPER
- "Bits" -> ItemId.BITS
- "Garden Experience" -> ItemId.GARDEN
- "Farming XP" -> ItemId.FARMING
- "Gold Essence" -> ItemId.GOLD_ESSENCE
- "Gemstone Powder" -> ItemId.GEMSTONE_POWDER
- "Mithril Powder" -> ItemId.MITHRIL_POWDER
- "Pelts" -> ItemId.PELT
- "Fine Flour" -> ItemId.FINE_FLOUR
- else -> {
- id.ifDropLast(" Experience") {
- ItemId.skill(generateName(it).string)
- } ?: id.ifDropLast(" XP") {
- ItemId.skill(generateName(it).string)
- } ?: id.ifDropLast(" Powder") {
- ItemId("SKYBLOCK_POWDER_${generateName(it).string}")
- } ?: id.ifDropLast(" Essence") {
- ItemId("ESSENCE_${generateName(it).string}")
- } ?: generateName(id)
- }
- }
- return Pair(id, parseShortNumber(group("amount")))
- }
- essenceRegex.useMatcher(properName) {
- return Pair(ItemId("ESSENCE_${group("essence").uppercase()}"),
- parseShortNumber(group("count")))
- }
- stackedItemRegex.useMatcher(properName) {
- var item = findForName(group("name"), fallbackToGenerated)
- if (item != null) {
- val count = parseShortNumber(group("count"))
- return Pair(item, count)
- }
- }
- numberedItemRegex.useMatcher(properName) {
- val item = findForName(group("what"), fallbackToGenerated)
- if (item != null) {
- val count = parseShortNumber(group("count"))
- return Pair(item, count)
- }
- }
-
- return findForName(properName, fallbackToGenerated)?.let { Pair(it, 1.0) }
- }
-
- fun getKnownItemIds(): Collection<ItemId> {
- return knownNames.values
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/ItemUtil.kt b/src/main/kotlin/moe/nea/ledger/ItemUtil.kt
deleted file mode 100644
index a3d8162..0000000
--- a/src/main/kotlin/moe/nea/ledger/ItemUtil.kt
+++ /dev/null
@@ -1,90 +0,0 @@
-package moe.nea.ledger
-
-import net.minecraft.inventory.IInventory
-import net.minecraft.item.ItemStack
-import net.minecraft.nbt.NBTTagCompound
-
-
-fun ItemStack.getExtraAttributes(): NBTTagCompound {
- val nbt = this.tagCompound ?: return NBTTagCompound()
- return nbt.getCompoundTag("ExtraAttributes")
-}
-
-fun ItemStack?.getInternalId(): ItemId? {
- if (this == null) return null
- val extraAttributes = getExtraAttributes()
- var id = extraAttributes.getString("id")
- id = id.takeIf { it.isNotBlank() }
- if (id == "PET") {
- id = getPetId() ?: id
- }
- if (id == "ENCHANTED_BOOK") {
- id = getEnchanments().entries.singleOrNull()?.let {
- "${it.key};${it.value}".uppercase()
- }
- }
- return id?.let(::ItemId)
-}
-
-fun ItemStack.getEnchanments(): Map<String, Int> {
- val enchantments = getExtraAttributes().getCompoundTag("enchantments")
- return enchantments.keySet.associateWith { enchantments.getInteger(it) }
-}
-
-class PetInfo {
- var type: String? = null
- var tier: String? = null
-}
-
-fun ItemStack.getPetId(): String? {
- val petInfoStr = getExtraAttributes().getString("petInfo")
- val petInfo = runCatching {
- Ledger.gson.fromJson(petInfoStr,
- PetInfo::class.java)
- }.getOrNull() // TODO: error reporting to sentry
- if (petInfo?.type == null || petInfo.tier == null) return null
- return petInfo.type + ";" + rarityToIndex(petInfo.tier ?: "")
-}
-
-fun rarityToIndex(rarity: String): Int {
- return when (rarity) {
- "COMMON" -> 0
- "UNCOMMON" -> 1
- "RARE" -> 2
- "EPIC" -> 3
- "LEGENDARY" -> 4
- "MYTHIC" -> 5
- else -> -1
- }
-}
-
-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) }
-}
-
-
-fun IInventory.asIterable(): Iterable<ItemStack?> = object : Iterable<ItemStack?> {
- override fun iterator(): Iterator<ItemStack?> {
- return object : Iterator<ItemStack?> {
- var i = 0
- override fun hasNext(): Boolean {
- return i < this@asIterable.sizeInventory
- }
-
- override fun next(): ItemStack? {
- if (!hasNext()) throw NoSuchElementException("$i is out of range for inventory ${this@asIterable}")
- return this@asIterable.getStackInSlot(i++)
- }
- }
- }
-}
-
-fun ItemStack.getDisplayNameU(): String {
- val nbt = this.tagCompound ?: NBTTagCompound()
- val extraAttributes = nbt.getCompoundTag("display")
- return extraAttributes.getString("Name")
-}
-
diff --git a/src/main/kotlin/moe/nea/ledger/Ledger.kt b/src/main/kotlin/moe/nea/ledger/Ledger.kt
deleted file mode 100644
index 72bd32f..0000000
--- a/src/main/kotlin/moe/nea/ledger/Ledger.kt
+++ /dev/null
@@ -1,187 +0,0 @@
-package moe.nea.ledger
-
-import com.google.gson.Gson
-import io.github.notenoughupdates.moulconfig.managed.ManagedConfig
-import moe.nea.ledger.config.LedgerConfig
-import moe.nea.ledger.config.UpdateUi
-import moe.nea.ledger.config.UpdateUiMarker
-import moe.nea.ledger.database.Database
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.events.LateWorldLoadEvent
-import moe.nea.ledger.events.RegistrationFinishedEvent
-import moe.nea.ledger.gen.BuildConfig
-import moe.nea.ledger.modules.AuctionHouseDetection
-import moe.nea.ledger.modules.BankDetection
-import moe.nea.ledger.modules.BazaarDetection
-import moe.nea.ledger.modules.BazaarOrderDetection
-import moe.nea.ledger.modules.BitsDetection
-import moe.nea.ledger.modules.BitsShopDetection
-import moe.nea.ledger.modules.DungeonChestDetection
-import moe.nea.ledger.modules.ExternalDataProvider
-import moe.nea.ledger.modules.ForgeDetection
-import moe.nea.ledger.modules.GambleDetection
-import moe.nea.ledger.modules.KatDetection
-import moe.nea.ledger.modules.KuudraChestDetection
-import moe.nea.ledger.modules.MineshaftCorpseDetection
-import moe.nea.ledger.modules.MinionDetection
-import moe.nea.ledger.modules.NpcDetection
-import moe.nea.ledger.modules.UpdateChecker
-import moe.nea.ledger.modules.VisitorDetection
-import moe.nea.ledger.utils.ErrorUtil
-import moe.nea.ledger.utils.MinecraftExecutor
-import moe.nea.ledger.utils.di.DI
-import moe.nea.ledger.utils.di.DIProvider
-import moe.nea.ledger.utils.network.RequestUtil
-import net.minecraft.client.Minecraft
-import net.minecraft.command.ICommand
-import net.minecraftforge.client.ClientCommandHandler
-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
-import java.io.File
-import java.util.concurrent.ConcurrentLinkedQueue
-
-@Mod(modid = "ledger", useMetadata = true, version = BuildConfig.VERSION)
-class Ledger {
- /*
- You have withdrawn 1M coins! You now have 518M coins in your account!
- You have deposited 519M coins! You now have 519M coins in your account!
-
- // ORDERS:
-
- [Bazaar] Buy Order Setup! 160x Wheat for 720.0 coins.
- [Bazaar] Claimed 160x Wheat worth 720.0 coins bought for 4.5 each!
-
- [Bazaar] Sell Offer Setup! 160x Wheat for 933.4 coins.
- [Bazaar] Claimed 34,236,799 coins from selling 176x Hyper Catalyst at 196,741 each!
-
- // INSTABUY:
-
- [Bazaar] Bought 64x Wheat for 377.6 coins!
- [Bazaar] Sold 64x Wheat for 268.8 coins!
-
- // AUCTION HOUSE:
-
- You collected 8,712,000 coins from selling Ultimate Carrot Candy Upgrade to [VIP] kodokush in an auction!
- You purchased 2x Walnut for 69 coins!
- You purchased ◆ Ice Rune I for 4,000 coins!
-
- // NPC
-
- // You bought Cactus x32 for 465.6 Coins!
- // You sold Cactus x1 for 3 Coins!
- // You bought back Potato x3 for 9 Coins!
-
- TODO: TRADING, FORGE, VISITORS / COPPER, CORPSES ÖFFNEN, HIGH / LOW GAMBLES, MINION ITEMS (maybe inferno refuel)
- TODO: PET LEVELING COSTS AT FANN, SLAYER / MOB DROPS, SLAYER START COST
- */
- companion object {
- val dataFolder = File("money-ledger").apply { mkdirs() }
- val logger = LogManager.getLogger("MoneyLedger")
- val managedConfig = ManagedConfig.create(File("config/money-ledger/config.json"), LedgerConfig::class.java) {
- checkExpose = false
- customProcessor<UpdateUiMarker> { option, ann ->
- UpdateUi(option)
- }
- }
- val gson = Gson()
- private val tickQueue = ConcurrentLinkedQueue<Runnable>()
- fun runLater(runnable: Runnable) {
- tickQueue.add(runnable)
- }
-
- val di = DI()
- }
-
- @Mod.EventHandler
- fun init(event: FMLInitializationEvent) {
- logger.info("Initializing ledger")
-
- TelemetryProvider.setupFor(di)
- di.registerSingleton(this)
- di.registerSingleton(Minecraft.getMinecraft())
- di.registerSingleton(gson)
- di.register(LedgerConfig::class.java, DIProvider { managedConfig.instance })
- di.registerInjectableClasses(
- AuctionHouseDetection::class.java,
- BankDetection::class.java,
- BazaarDetection::class.java,
- BazaarOrderDetection::class.java,
- DebugDataCommand::class.java,
- BitsDetection::class.java,
- BitsShopDetection::class.java,
- ConfigCommand::class.java,
- Database::class.java,
- DungeonChestDetection::class.java,
- ErrorUtil::class.java,
- ExternalDataProvider::class.java,
- ItemIdProvider::class.java,
- KatDetection::class.java,
- KuudraChestDetection::class.java,
- LedgerLogger::class.java,
- LogChatCommand::class.java,
- MinionDetection::class.java,
- MineshaftCorpseDetection::class.java,
- ForgeDetection::class.java,
- NpcDetection::class.java,
- GambleDetection::class.java,
- MinecraftExecutor::class.java,
- UpdateChecker::class.java,
- TriggerCommand::class.java,
- QueryCommand::class.java,
- RequestUtil::class.java,
- VisitorDetection::class.java,
- )
- val errorUtil = di.provide<ErrorUtil>()
- errorUtil.catch {
- di.instantiateAll()
- di.getAllInstances().forEach(MinecraftForge.EVENT_BUS::register)
- di.getAllInstances().filterIsInstance<ICommand>()
- .forEach { ClientCommandHandler.instance.registerCommand(it) }
- }
-
- errorUtil.catch {
- di.provide<Database>().loadAndUpgrade()
- }
-
- MinecraftForge.EVENT_BUS.post(RegistrationFinishedEvent())
- }
-
- 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())
- }
- while (true) {
- val queued = tickQueue.poll() ?: break
- queued.run()
- }
- }
-
- @SubscribeEvent(receiveCanceled = true, priority = EventPriority.HIGHEST)
- fun onChat(event: ClientChatReceivedEvent) {
- if (event.type != 2.toByte())
- MinecraftForge.EVENT_BUS.post(ChatReceived(event))
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt b/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt
deleted file mode 100644
index dec0727..0000000
--- a/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package moe.nea.ledger
-
-import com.google.gson.JsonObject
-import java.time.Instant
-import java.util.UUID
-
-data class LedgerEntry(
- val transactionType: TransactionType,
- val timestamp: Instant,
- 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 }
- return JsonObject().apply {
- addProperty("transactionType", transactionType.name)
- addProperty("timestamp", timestamp.toEpochMilli().toString())
- addProperty("totalTransactionValue", coinAmount)
- addProperty("itemId", nonCoins?.itemId?.string ?: "")
- addProperty("itemAmount", nonCoins?.count ?: 0.0)
- addProperty("profileId", profileId.toString())
- addProperty(
- "playerId",
- UUIDUtil.getPlayerUUID().toString()
- )
- }
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt b/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt
deleted file mode 100644
index 913d1b5..0000000
--- a/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt
+++ /dev/null
@@ -1,135 +0,0 @@
-package moe.nea.ledger
-
-import com.google.gson.Gson
-import com.google.gson.JsonArray
-import moe.nea.ledger.database.DBItemEntry
-import moe.nea.ledger.database.DBLogEntry
-import moe.nea.ledger.database.Database
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.utils.di.Inject
-import net.minecraft.client.Minecraft
-import net.minecraft.util.ChatComponentText
-import net.minecraft.util.IChatComponent
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
-import java.io.File
-import java.text.SimpleDateFormat
-import java.util.Date
-import java.util.UUID
-
-class LedgerLogger {
- fun printOut(text: String) = printOut(ChatComponentText(text))
- fun printOut(comp: IChatComponent) {
- Minecraft.getMinecraft().ingameGUI?.chatGUI?.printChatMessage(comp)
- }
-
- val profileIdPattern =
- "Profile ID: (?<profile>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})".toPattern()
-
- var currentProfile: UUID? = null
-
- var shouldLog by Ledger.managedConfig.instance.debug::logEntries
-
- @Inject
- lateinit var database: Database
-
- @SubscribeEvent
- fun onProfileSwitch(event: ChatReceived) {
- profileIdPattern.useMatcher(event.message) {
- currentProfile = UUID.fromString(group("profile"))
- }
- }
-
-
- fun printToChat(entry: LedgerEntry) {
- val items = entry.items.joinToString("\n§e") { " - ${it.direction} ${it.count}x ${it.itemId}" }
- printOut(
- """
- §e================= TRANSACTION START
- §eTYPE: §a${entry.transactionType}
- §eTIMESTAMP: §a${entry.timestamp}
- §e%s
- §ePROFILE: §a${currentProfile}
- §e================= TRANSACTION END
- """.trimIndent().replace("%s", items)
- )
- }
-
- val entries = JsonArray()
- var hasRecentlyMerged = false
- var lastMergeTime = System.currentTimeMillis()
-
- fun doMerge() {
- val allFiles = folder.listFiles()?.toList() ?: emptyList()
- val mergedJson = allFiles
- .filter { it.name != "merged.json" && it.extension == "json" }
- .sortedDescending()
- .map { it.readText().trim().removePrefix("[").removeSuffix("]") }
- .joinToString(",", "[", "]")
- folder.resolve("merged.json").writeText(mergedJson)
- hasRecentlyMerged = true
- }
-
- init {
- Runtime.getRuntime().addShutdownHook(Thread { doMerge() })
- }
-
- @SubscribeEvent
- fun onTick(event: ClientTickEvent) {
- if (!hasRecentlyMerged && (System.currentTimeMillis() - lastMergeTime) > 60_000L) {
- lastMergeTime = System.currentTimeMillis()
- doMerge()
- }
- }
-
- fun logEntry(entry: LedgerEntry) {
- if (shouldLog)
- printToChat(entry)
- Ledger.logger.info("Logging entry of type ${entry.transactionType}")
- val transactionId = UUIDUtil.createULIDAt(entry.timestamp)
- DBLogEntry.insert(database.connection) {
- it[DBLogEntry.profileId] = currentProfile ?: UUIDUtil.NIL_UUID
- it[DBLogEntry.playerId] = UUIDUtil.getPlayerUUID()
- it[DBLogEntry.type] = entry.transactionType
- it[DBLogEntry.transactionId] = transactionId
- }
- entry.items.forEach { change ->
- DBItemEntry.insert(database.connection) {
- it[DBItemEntry.transactionId] = transactionId
- it[DBItemEntry.mode] = change.direction
- it[DBItemEntry.size] = change.count
- it[DBItemEntry.itemId] = change.itemId
- }
- }
- entries.add(entry.intoJson(currentProfile))
- commit()
- }
-
- fun commit() {
- try {
- hasRecentlyMerged = false
- file.writeText(gson.toJson(entries))
- } catch (ex: Exception) {
- Ledger.logger.error("Could not save file", ex)
- }
- }
-
- val gson = Gson()
-
- val folder = Ledger.dataFolder
- val file: File = run {
- val date = SimpleDateFormat("yyyy.MM.dd").format(Date())
-
- generateSequence(0) { it + 1 }
- .map {
- if (it == 0)
- folder.resolve("$date.json")
- else
- folder.resolve("$date-$it.json")
- }
- .filter { !it.exists() }
- .first()
- }
-}
-
-
diff --git a/src/main/kotlin/moe/nea/ledger/LogChatCommand.kt b/src/main/kotlin/moe/nea/ledger/LogChatCommand.kt
deleted file mode 100644
index 90b2545..0000000
--- a/src/main/kotlin/moe/nea/ledger/LogChatCommand.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package moe.nea.ledger
-
-import moe.nea.ledger.utils.di.Inject
-import net.minecraft.command.CommandBase
-import net.minecraft.command.ICommandSender
-
-class LogChatCommand : CommandBase() {
- @Inject
- lateinit var logger: LedgerLogger
-
- override fun getCommandName(): String {
- return "ledgerlogchat"
- }
-
- override fun canCommandSenderUseCommand(sender: ICommandSender?): Boolean {
- return true
- }
-
- override fun getCommandUsage(sender: ICommandSender?): String {
- return ""
- }
-
- override fun processCommand(sender: ICommandSender?, args: Array<out String>?) {
- logger.shouldLog = !logger.shouldLog
- logger.printOut("§eLedger logging toggled " + (if (logger.shouldLog) "§aon" else "§coff") + "§e.")
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/NumberUtil.kt b/src/main/kotlin/moe/nea/ledger/NumberUtil.kt
deleted file mode 100644
index 438f342..0000000
--- a/src/main/kotlin/moe/nea/ledger/NumberUtil.kt
+++ /dev/null
@@ -1,117 +0,0 @@
-package moe.nea.ledger
-
-import net.minecraft.event.ClickEvent
-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
-import java.time.Instant
-import java.time.LocalDateTime
-import java.time.ZoneId
-import java.time.format.DateTimeFormatter
-import java.time.format.DateTimeFormatterBuilder
-import java.time.temporal.ChronoField
-import java.util.regex.Matcher
-import java.util.regex.Pattern
-
-// language=regexp
-val SHORT_NUMBER_PATTERN = "[0-9]+(?:,[0-9]+)*(?:\\.[0-9]+)?[kKmMbB]?"
-
-// language=regexp
-val ROMAN_NUMBER_PATTERN = "[IVXLCDM]+"
-
-val romanNumbers = mapOf(
- 'I' to 1,
- 'V' to 5,
- 'X' to 10,
- 'L' to 50,
- 'C' to 100,
- 'D' to 500,
- 'M' to 1000
-)
-
-fun parseRomanNumber(string: String): Int {
- var smallestSeenSoFar = Int.MAX_VALUE
- var lastSeenOfSmallest = 0
- var amount = 0
- for (c in string) {
- val cV = romanNumbers[c]!!
- if (cV == smallestSeenSoFar) {
- lastSeenOfSmallest++
- amount += cV
- } else if (cV < smallestSeenSoFar) {
- smallestSeenSoFar = cV
- amount += cV
- lastSeenOfSmallest = 1
- } else {
- amount -= lastSeenOfSmallest * smallestSeenSoFar * 2
- smallestSeenSoFar = cV
- amount += cV
- lastSeenOfSmallest = 1
- }
- }
- return amount
-}
-
-val siScalars = mapOf(
- 'k' to 1_000.0,
- 'K' to 1_000.0,
- 'm' to 1_000_000.0,
- 'M' to 1_000_000.0,
- 'b' to 1_000_000_000.0,
- 'B' to 1_000_000_000.0,
-)
-
-fun parseShortNumber(string: String): Double {
- var k = string.replace(",", "")
- val scalar = k.last()
- var scalarMultiplier = siScalars[scalar]
- if (scalarMultiplier == null) {
- scalarMultiplier = 1.0
- } else {
- k = k.dropLast(1)
- }
- return k.toDouble() * scalarMultiplier
-}
-
-fun Pattern.matches(string: String): Boolean = matcher(string).matches()
-inline fun <T> Pattern.useMatcher(string: String, block: Matcher.() -> T): T? =
- matcher(string).takeIf { it.matches() }?.let(block)
-
-fun <T> String.ifDropLast(suffix: String, block: (String) -> T): T? {
- if (endsWith(suffix)) {
- return block(dropLast(suffix.length))
- }
- return null
-}
-
-fun String.unformattedString(): String = replace("§.".toRegex(), "")
-
-val timeFormat: DateTimeFormatter = DateTimeFormatterBuilder()
- .appendValue(ChronoField.DAY_OF_MONTH, 2)
- .appendLiteral(".")
- .appendValue(ChronoField.MONTH_OF_YEAR, 2)
- .appendLiteral(".")
- .appendValue(ChronoField.YEAR, 4)
- .appendLiteral(" ")
- .appendValue(ChronoField.HOUR_OF_DAY, 2)
- .appendLiteral(":")
- .appendValue(ChronoField.MINUTE_OF_HOUR, 2)
- .appendLiteral(":")
- .appendValue(ChronoField.SECOND_OF_MINUTE, 2)
- .toFormatter()
-
-fun Instant.formatChat(): IChatComponent {
- val text = ChatComponentText(
- LocalDateTime.ofInstant(this, ZoneId.systemDefault()).format(timeFormat)
- )
- text.setChatStyle(
- ChatStyle()
- .setChatClickEvent(
- ClickEvent(ClickEvent.Action.OPEN_URL, "https://time.is/${this.epochSecond}"))
- .setChatHoverEvent(
- HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("Click to show on time.is")))
- .setColor(EnumChatFormatting.AQUA))
- return text
-}
diff --git a/src/main/kotlin/moe/nea/ledger/QueryCommand.kt b/src/main/kotlin/moe/nea/ledger/QueryCommand.kt
deleted file mode 100644
index 9967a4a..0000000
--- a/src/main/kotlin/moe/nea/ledger/QueryCommand.kt
+++ /dev/null
@@ -1,196 +0,0 @@
-package moe.nea.ledger
-
-import moe.nea.ledger.database.ANDExpression
-import moe.nea.ledger.database.BooleanExpression
-import moe.nea.ledger.database.Clause
-import moe.nea.ledger.database.DBItemEntry
-import moe.nea.ledger.database.DBLogEntry
-import moe.nea.ledger.database.Database
-import moe.nea.ledger.utils.di.Inject
-import net.minecraft.command.CommandBase
-import net.minecraft.command.ICommandSender
-import net.minecraft.util.BlockPos
-import net.minecraft.util.ChatComponentText
-import net.minecraft.util.ChatStyle
-import net.minecraft.util.EnumChatFormatting
-
-class QueryCommand : CommandBase() {
- override fun canCommandSenderUseCommand(sender: ICommandSender?): Boolean {
- return true
- }
-
- override fun getCommandName(): String {
- return "ledger"
- }
-
- override fun getCommandUsage(sender: ICommandSender?): String {
- return ""
- }
-
- override fun getCommandAliases(): List<String> {
- return listOf("lgq")
- }
-
- @Inject
- lateinit var logger: LedgerLogger
-
- override fun processCommand(sender: ICommandSender, args: Array<out String>) {
- if (args.isEmpty()) {
- logger.printOut("§eHere is how you can look up transactions:")
- logger.printOut("")
- logger.printOut("§f- §e/ledger withitem %POTATO%")
- logger.printOut(" §aLook up transactions involving potatoes!")
- logger.printOut("§f- §e/ledger withitem ENCHANTED_POTATO")
- logger.printOut(" §aLook up transactions involving just enchanted potatoes!")
- logger.printOut("§f- §e/ledger withitem %POTATO% withitem %CARROT%")
- logger.printOut(" §aLook up transactions involving potatoes or carrots!")
- logger.printOut("§f- §e/ledger withtype AUCTION_SOLD")
- logger.printOut(" §aLook up transactions of sold auctions!")
- logger.printOut("§f- §e/ledger withtype AUCTION_SOLD withitem CRIMSON%")
- logger.printOut(" §aLook up sold auctions involving crimson armor pieces!")
- logger.printOut("")
- logger.printOut("§eFilters of the same type apply using §aOR§e and loggers of different types apply using §aAND§e.")
- logger.printOut("§eYou can use % as a wildcard!")
- return
- }
- val p = parseArgs(args)
- when (p) {
- is ParseResult.Success -> {
- executeQuery(p)
- }
-
- is ParseResult.UnknownFilter -> {
- logger.printOut("§cUnknown filter name ${p.start}. Available filter names are: ${mFilters.keys.joinToString()}")
- }
-
- is ParseResult.MissingArg -> {
- logger.printOut("§cFilter ${p.filterM.name} is missing an argument.")
- }
- }
- }
-
- override fun addTabCompletionOptions(
- sender: ICommandSender,
- args: Array<out String>,
- pos: BlockPos
- ): MutableList<String>? {
- when (val p = parseArgs(args)) {
- is ParseResult.MissingArg -> return null
- is ParseResult.Success -> return p.lastFilterM.tabComplete(args.last())
- is ParseResult.UnknownFilter -> return getListOfStringsMatchingLastWord(args, mFilters.keys)
- }
- }
-
- @Inject
- lateinit var database: Database
- private fun executeQuery(parse: ParseResult.Success) {
- val grouped = parse.filters
- val query = DBLogEntry.from(database.connection)
- .select(DBLogEntry.type, DBLogEntry.transactionId)
- .join(DBItemEntry, on = Clause { column(DBLogEntry.transactionId) eq column(DBItemEntry.transactionId) })
- for (value in grouped.values) {
- query.where(ANDExpression(value))
- }
- query.limit(80u)
- val dedup = mutableSetOf<UUIDUtil.ULIDWrapper>()
- query.forEach {
- val type = it[DBLogEntry.type]
- val transactionId = it[DBLogEntry.transactionId]
- if (!dedup.add(transactionId)) {
- return@forEach
- }
- val timestamp = transactionId.getTimestamp()
- val items = DBItemEntry.selectAll(database.connection)
- .where(Clause { column(DBItemEntry.transactionId) eq string(transactionId.wrapped) })
- .map { ItemChange.from(it) }
- val text = ChatComponentText("")
- .setChatStyle(ChatStyle().setColor(EnumChatFormatting.YELLOW))
- .appendSibling(
- ChatComponentText(type.name)
- .setChatStyle(ChatStyle().setColor(EnumChatFormatting.GREEN))
- )
- .appendText(" on ")
- .appendSibling(timestamp.formatChat())
- .appendText("\n")
- .appendSibling(
- ChatComponentText(transactionId.wrapped).setChatStyle(ChatStyle().setColor(EnumChatFormatting.DARK_GRAY))
- )
- for (item in items) {
- text.appendText("\n")
- .appendSibling(item.formatChat())
- }
- text.appendText("\n")
- logger.printOut(text)
- }
- }
-
- sealed interface ParseResult {
- data class UnknownFilter(val start: String) : ParseResult
- data class MissingArg(val filterM: FilterM) : ParseResult
- data class Success(val lastFilterM: FilterM, val filters: Map<FilterM, List<BooleanExpression>>) : ParseResult
- }
-
- fun parseArgs(args: Array<out String>): ParseResult {
- require(args.isNotEmpty())
- val arr = args.iterator()
- val filters = mutableMapOf<FilterM, MutableList<BooleanExpression>>()
- var lastFilterM: FilterM? = null
- while (arr.hasNext()) {
- val filterName = arr.next()
- val filterM = mFilters[filterName]
- if (filterM == null) {
- return ParseResult.UnknownFilter(filterName)
- }
- if (!arr.hasNext()) {
- return ParseResult.MissingArg(filterM)
- }
- filters.getOrPut(filterM, ::mutableListOf).add(filterM.getFilter(arr.next()))
- lastFilterM = filterM
- }
- return ParseResult.Success(lastFilterM!!, filters)
- }
-
-
- val mFilters = listOf(TypeFilter, ItemFilter).associateBy { it.name }
-
- object TypeFilter : FilterM {
- override val name: String
- get() = "withtype"
-
- override fun getFilter(text: String): BooleanExpression {
- val preparedText = "%" + text.trim('%') + "%"
- return Clause { column(DBLogEntry.type) like preparedText }
- }
-
- override fun tabComplete(partialArg: String): MutableList<String> {
- return TransactionType.entries.asSequence().map { it.name }.filter { partialArg in it }.toMutableList()
- }
- }
-
- object ItemFilter : FilterM {
- override val name: String
- get() = "withitem"
-
- private val itemIdProvider = Ledger.di.provide<ItemIdProvider>() // TODO: close this escape hatch
- override fun getFilter(text: String): BooleanExpression {
- return Clause { column(DBItemEntry.itemId) like text }
- }
-
- override fun tabComplete(partialArg: String): MutableList<String>? {
- return itemIdProvider.getKnownItemIds()
- .asSequence()
- .map { it.string }
- .filter { partialArg in it }
- .take(100)
- .toMutableList()
- }
- }
-
- interface FilterM {
- val name: String
- fun getFilter(text: String): BooleanExpression
- fun tabComplete(partialArg: String): MutableList<String>?
-// fun tabCompleteFilter() TODO
- }
-
-} \ 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
deleted file mode 100644
index 783664b..0000000
--- a/src/main/kotlin/moe/nea/ledger/ScoreboardUtil.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-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/TelemetryProvider.kt b/src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt
deleted file mode 100644
index d9c7108..0000000
--- a/src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt
+++ /dev/null
@@ -1,66 +0,0 @@
-package moe.nea.ledger
-
-import com.google.gson.JsonArray
-import com.google.gson.JsonElement
-import com.google.gson.JsonObject
-import moe.nea.ledger.gen.BuildConfig
-import moe.nea.ledger.utils.di.DI
-import moe.nea.ledger.utils.di.DIProvider
-import moe.nea.ledger.utils.telemetry.CommonKeys
-import moe.nea.ledger.utils.telemetry.ContextValue
-import moe.nea.ledger.utils.telemetry.EventRecorder
-import moe.nea.ledger.utils.telemetry.JsonElementContext
-import moe.nea.ledger.utils.telemetry.LoggingEventRecorder
-import moe.nea.ledger.utils.telemetry.Span
-import net.minecraft.client.Minecraft
-import net.minecraft.util.Session
-import net.minecraftforge.fml.common.Loader
-
-object TelemetryProvider {
- fun injectTo(di: DI) {
- di.register(
- EventRecorder::class.java,
- if (DevUtil.isDevEnv) DIProvider.singeleton(LoggingEventRecorder(Ledger.logger, true))
- else DIProvider.singeleton(
- LoggingEventRecorder(Ledger.logger, false)) // TODO: replace with upload to server
- )
- }
-
- val USER = "minecraft_user"
- val MINECRAFT_VERSION = "minecraft_version"
- val MODS = "mods"
-
- class MinecraftUser(val session: Session) : ContextValue {
- override fun serialize(): JsonElement {
- val obj = JsonObject()
- obj.addProperty("uuid", session.playerID)
- obj.addProperty("name", session.username)
- return obj
- }
- }
-
- fun setupDefaultSpan() {
- val sp = Span.current()
- sp.add(USER, MinecraftUser(Minecraft.getMinecraft().session))
- sp.add(MINECRAFT_VERSION, ContextValue.compound(
- "static" to "1.8.9",
- "rt" to Minecraft.getMinecraft().version,
- ))
- val mods = JsonArray()
- Loader.instance().activeModList.map {
- val obj = JsonObject()
- obj.addProperty("id", it.modId)
- obj.addProperty("version", it.version)
- obj.addProperty("displayVersion", it.displayVersion)
- obj
- }.forEach(mods::add)
- sp.add(MODS, JsonElementContext(mods))
- sp.add(CommonKeys.VERSION, ContextValue.string(BuildConfig.FULL_VERSION))
- sp.add(CommonKeys.COMMIT_VERSION, ContextValue.string(BuildConfig.GIT_COMMIT))
- }
-
- fun setupFor(di: DI) {
- injectTo(di)
- setupDefaultSpan()
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/TransactionType.kt b/src/main/kotlin/moe/nea/ledger/TransactionType.kt
deleted file mode 100644
index f6bbe6a..0000000
--- a/src/main/kotlin/moe/nea/ledger/TransactionType.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package moe.nea.ledger
-
-enum class TransactionType {
- AUCTION_BOUGHT,
- AUCTION_LISTING_CHARGE,
- AUCTION_SOLD,
- AUTOMERCHANT_PROFIT_COLLECT,
- BANK_DEPOSIT,
- BANK_WITHDRAW,
- BAZAAR_BUY_INSTANT,
- BAZAAR_BUY_ORDER,
- BAZAAR_SELL_INSTANT,
- BAZAAR_SELL_ORDER,
- BITS_PURSE_STATUS,
- BOOSTER_COOKIE_ATE,
- COMMUNITY_SHOP_BUY,
- CORPSE_DESECRATED,
- FORGED,
- DIE_ROLLED,
- DUNGEON_CHEST_OPEN,
- KAT_TIMESKIP,
- KAT_UPGRADE,
- KISMET_REROLL,
- KUUDRA_CHEST_OPEN,
- NPC_BUY,
- NPC_SELL,
- VISITOR_BARGAIN,
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/TriggerCommand.kt b/src/main/kotlin/moe/nea/ledger/TriggerCommand.kt
deleted file mode 100644
index c97627d..0000000
--- a/src/main/kotlin/moe/nea/ledger/TriggerCommand.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package moe.nea.ledger
-
-import moe.nea.ledger.events.TriggerEvent
-import net.minecraft.command.CommandBase
-import net.minecraft.command.ICommandSender
-import net.minecraft.event.ClickEvent
-import net.minecraft.util.ChatComponentText
-import net.minecraftforge.common.MinecraftForge
-
-class TriggerCommand : CommandBase() {
- fun getTriggerCommandLine(trigger: String): ClickEvent {
- return ClickEvent(ClickEvent.Action.RUN_COMMAND, "/${commandName} $trigger")
- }
-
- override fun getCommandName(): String {
- return "__ledgertrigger"
- }
-
- override fun getCommandUsage(sender: ICommandSender?): String {
- return ""
- }
-
- override fun processCommand(sender: ICommandSender, args: Array<out String>) {
- val event = TriggerEvent(args.joinToString(" "))
- MinecraftForge.EVENT_BUS.post(event)
- if (!event.isCanceled)
- sender.addChatMessage(ChatComponentText("§cCould not find the given trigger. This is an internal command for ledger."))
- }
-
- override fun canCommandSenderUseCommand(sender: ICommandSender?): Boolean {
- return true
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/UUIDUtil.kt b/src/main/kotlin/moe/nea/ledger/UUIDUtil.kt
deleted file mode 100644
index 5549908..0000000
--- a/src/main/kotlin/moe/nea/ledger/UUIDUtil.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package moe.nea.ledger
-
-import com.mojang.util.UUIDTypeAdapter
-import io.azam.ulidj.ULID
-import net.minecraft.client.Minecraft
-import java.time.Instant
-import java.util.UUID
-import kotlin.random.Random
-
-object UUIDUtil {
- @JvmInline
- value class ULIDWrapper(
- val wrapped: String
- ) {
- fun getTimestamp(): Instant {
- return Instant.ofEpochMilli(ULID.getTimestamp(wrapped))
- }
-
- init {
- require(ULID.isValid(wrapped))
- }
- }
-
- fun parseDashlessUuid(string: String) = UUIDTypeAdapter.fromString(string)
- val NIL_UUID = UUID(0L, 0L)
- fun getPlayerUUID(): UUID {
- val currentUUID = Minecraft.getMinecraft().thePlayer?.uniqueID
- ?: Minecraft.getMinecraft().session?.playerID?.let(::parseDashlessUuid)
- ?: lastKnownUUID
- lastKnownUUID = currentUUID
- return currentUUID
- }
-
- fun createULIDAt(timestamp: Instant): ULIDWrapper {
- return ULIDWrapper(ULID.generate(
- timestamp.toEpochMilli(),
- Random.nextBytes(10)
- ))
- }
-
- private var lastKnownUUID: UUID = NIL_UUID
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/config/DebugOptions.kt b/src/main/kotlin/moe/nea/ledger/config/DebugOptions.kt
deleted file mode 100644
index fd5ed3d..0000000
--- a/src/main/kotlin/moe/nea/ledger/config/DebugOptions.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package moe.nea.ledger.config
-
-import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean
-import io.github.notenoughupdates.moulconfig.annotations.ConfigOption
-
-class DebugOptions {
- @ConfigOption(name = "Log entries to chat",
- desc = "Appends all logged entries into the chat as they are logged. This option does not persist on restarts.")
- @Transient
- @ConfigEditorBoolean
- @JvmField
- var logEntries = false
-}
diff --git a/src/main/kotlin/moe/nea/ledger/config/LedgerConfig.kt b/src/main/kotlin/moe/nea/ledger/config/LedgerConfig.kt
deleted file mode 100644
index 91ee5c1..0000000
--- a/src/main/kotlin/moe/nea/ledger/config/LedgerConfig.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-package moe.nea.ledger.config
-
-import io.github.notenoughupdates.moulconfig.Config
-import io.github.notenoughupdates.moulconfig.DescriptionRendereringBehaviour
-import io.github.notenoughupdates.moulconfig.annotations.Category
-import io.github.notenoughupdates.moulconfig.processor.ProcessedOption
-import moe.nea.ledger.Ledger
-
-class LedgerConfig : Config() {
- override fun getTitle(): String {
- return "§6Ledger §7- §6Hypixel SkyBlock data logger §7by §anea89o"
- }
-
- override fun saveNow() {
- super.saveNow()
- Ledger.managedConfig.saveToFile()
- }
-
- override fun getDescriptionBehaviour(option: ProcessedOption?): DescriptionRendereringBehaviour {
- return DescriptionRendereringBehaviour.EXPAND_PANEL
- }
-
- @Category(name = "Ledger", desc = "")
- @JvmField
- val main = MainOptions()
-
- @Category(name = "Synchronization", desc = "")
- @JvmField
- val synchronization = SynchronizationOptions()
-
- @Category(name = "Debug", desc = "")
- @JvmField
- val debug = DebugOptions()
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/config/MainOptions.kt b/src/main/kotlin/moe/nea/ledger/config/MainOptions.kt
deleted file mode 100644
index 1efa970..0000000
--- a/src/main/kotlin/moe/nea/ledger/config/MainOptions.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package moe.nea.ledger.config
-
-import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown
-import io.github.notenoughupdates.moulconfig.annotations.ConfigOption
-
-class MainOptions {
- @ConfigOption(name = "Marker for Update UI", desc = "_")
- @JvmField
- @UpdateUiMarker
- @Transient
- var testOption = Unit
-
- @ConfigOption(name = "Check for Updates", desc = "Automatically check for updates on startup")
- @ConfigEditorDropdown
- @JvmField
- var updateCheck = UpdateCheckBehaviour.SEMI
-
- enum class UpdateCheckBehaviour(val label: String) {
- SEMI("Semi-Automatic"),
- FULL("Full-Automatic"),
- NONE("Don't check");
-
- override fun toString(): String {
- return label
- }
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/config/SynchronizationOptions.kt b/src/main/kotlin/moe/nea/ledger/config/SynchronizationOptions.kt
deleted file mode 100644
index b8c740b..0000000
--- a/src/main/kotlin/moe/nea/ledger/config/SynchronizationOptions.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package moe.nea.ledger.config
-
-import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean
-import io.github.notenoughupdates.moulconfig.annotations.ConfigOption
-
-class SynchronizationOptions {
- @ConfigOption(name = "Test Option", desc = "Test Description")
- @ConfigEditorBoolean
- @JvmField
- var testOption = false
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/config/UpdateUi.kt b/src/main/kotlin/moe/nea/ledger/config/UpdateUi.kt
deleted file mode 100644
index 86ccbf7..0000000
--- a/src/main/kotlin/moe/nea/ledger/config/UpdateUi.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package moe.nea.ledger.config
-
-import io.github.notenoughupdates.moulconfig.gui.GuiComponent
-import io.github.notenoughupdates.moulconfig.gui.component.TextComponent
-import io.github.notenoughupdates.moulconfig.gui.editors.ComponentEditor
-import io.github.notenoughupdates.moulconfig.processor.ProcessedOption
-import moe.nea.ledger.Ledger
-
-class UpdateUi(option: ProcessedOption) : ComponentEditor(option) {
- val delegate by lazy {// TODO
- TextComponent("Hier könnte ihre werbung stehen")
- }
-
- override fun getDelegate(): GuiComponent {
- return delegate
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/config/UpdateUiMarker.kt b/src/main/kotlin/moe/nea/ledger/config/UpdateUiMarker.kt
deleted file mode 100644
index 7a0466a..0000000
--- a/src/main/kotlin/moe/nea/ledger/config/UpdateUiMarker.kt
+++ /dev/null
@@ -1,6 +0,0 @@
-package moe.nea.ledger.config
-
-@Retention(AnnotationRetention.RUNTIME)
-@Target(AnnotationTarget.FIELD)
-annotation class UpdateUiMarker {
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/database/DBLogEntry.kt b/src/main/kotlin/moe/nea/ledger/database/DBLogEntry.kt
deleted file mode 100644
index 77ac215..0000000
--- a/src/main/kotlin/moe/nea/ledger/database/DBLogEntry.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package moe.nea.ledger.database
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.TransactionType
-
-object DBLogEntry : Table("LogEntry") {
- val transactionId = column("transactionId", DBUlid)
- val type = column("type", DBEnum<TransactionType>())
- val profileId = column("profileId", DBUuid)
- val playerId = column("playerId", DBUuid)
-}
-
-object DBItemEntry : Table("ItemEntry") {
- val transactionId = column("transactionId", DBUlid) // TODO: add foreign keys
- val mode = column("mode", DBEnum<ItemChange.ChangeDirection>())
- val itemId = column("item", DBString.mapped(ItemId::string, ::ItemId))
- val size = column("size", DBDouble)
-}
diff --git a/src/main/kotlin/moe/nea/ledger/database/DBSchema.kt b/src/main/kotlin/moe/nea/ledger/database/DBSchema.kt
deleted file mode 100644
index 492f261..0000000
--- a/src/main/kotlin/moe/nea/ledger/database/DBSchema.kt
+++ /dev/null
@@ -1,545 +0,0 @@
-package moe.nea.ledger.database
-
-import moe.nea.ledger.UUIDUtil
-import java.sql.Connection
-import java.sql.PreparedStatement
-import java.sql.ResultSet
-import java.time.Instant
-import java.util.UUID
-
-interface DBSchema {
- val tables: List<Table>
-}
-
-interface DBType<T> {
- val dbType: String
-
- fun get(result: ResultSet, index: Int): T
- fun set(stmt: PreparedStatement, index: Int, value: T)
- fun getName(): String = javaClass.simpleName
- fun <R> mapped(
- from: (R) -> T,
- to: (T) -> R,
- ): DBType<R> {
- return object : DBType<R> {
- override fun getName(): String {
- return "Mapped(${this@DBType.getName()})"
- }
-
- override val dbType: String
- get() = this@DBType.dbType
-
- override fun get(result: ResultSet, index: Int): R {
- return to(this@DBType.get(result, index))
- }
-
- override fun set(stmt: PreparedStatement, index: Int, value: R) {
- this@DBType.set(stmt, index, from(value))
- }
- }
- }
-}
-
-object DBUuid : DBType<UUID> {
- override val dbType: String
- get() = "TEXT"
-
- override fun get(result: ResultSet, index: Int): UUID {
- return UUIDUtil.parseDashlessUuid(result.getString(index))
- }
-
- override fun set(stmt: PreparedStatement, index: Int, value: UUID) {
- stmt.setString(index, value.toString())
- }
-}
-
-object DBUlid : DBType<UUIDUtil.ULIDWrapper> {
- override val dbType: String
- get() = "TEXT"
-
- override fun get(result: ResultSet, index: Int): UUIDUtil.ULIDWrapper {
- val text = result.getString(index)
- return UUIDUtil.ULIDWrapper(text)
- }
-
- override fun set(stmt: PreparedStatement, index: Int, value: UUIDUtil.ULIDWrapper) {
- stmt.setString(index, value.wrapped)
- }
-}
-
-object DBString : DBType<String> {
- override val dbType: String
- get() = "TEXT"
-
- override fun get(result: ResultSet, index: Int): String {
- return result.getString(index)
- }
-
- override fun set(stmt: PreparedStatement, index: Int, value: String) {
- stmt.setString(index, value)
- }
-}
-
-class DBEnum<T : Enum<T>>(
- val type: Class<T>,
-) : DBType<T> {
- companion object {
- inline operator fun <reified T : Enum<T>> invoke(): DBEnum<T> {
- return DBEnum(T::class.java)
- }
- }
-
- override val dbType: String
- get() = "TEXT"
-
- override fun getName(): String {
- return "DBEnum(${type.simpleName})"
- }
-
- override fun set(stmt: PreparedStatement, index: Int, value: T) {
- stmt.setString(index, value.name)
- }
-
- override fun get(result: ResultSet, index: Int): T {
- val name = result.getString(index)
- return java.lang.Enum.valueOf(type, name)
- }
-}
-
-object DBDouble : DBType<Double> {
- override val dbType: String
- get() = "DOUBLE"
-
- override fun get(result: ResultSet, index: Int): Double {
- return result.getDouble(index)
- }
-
- override fun set(stmt: PreparedStatement, index: Int, value: Double) {
- stmt.setDouble(index, value)
- }
-}
-
-object DBInt : DBType<Long> {
- override val dbType: String
- get() = "INTEGER"
-
- override fun get(result: ResultSet, index: Int): Long {
- return result.getLong(index)
- }
-
- override fun set(stmt: PreparedStatement, index: Int, value: Long) {
- stmt.setLong(index, value)
- }
-}
-
-object DBInstant : DBType<Instant> {
- override val dbType: String
- get() = "INTEGER"
-
- override fun set(stmt: PreparedStatement, index: Int, value: Instant) {
- stmt.setLong(index, value.toEpochMilli())
- }
-
- override fun get(result: ResultSet, index: Int): Instant {
- return Instant.ofEpochMilli(result.getLong(index))
- }
-}
-
-class Column<T> @Deprecated("Use Table.column instead") constructor(
- val table: Table,
- val name: String,
- val type: DBType<T>
-) {
- val sqlName get() = "`$name`"
- val qualifiedSqlName get() = table.sqlName + "." + sqlName
-}
-
-interface Constraint {
- val affectedColumns: Collection<Column<*>>
- fun asSQL(): String
-}
-
-class UniqueConstraint(val columns: List<Column<*>>) : Constraint {
- init {
- require(columns.isNotEmpty())
- }
-
- override val affectedColumns: Collection<Column<*>>
- get() = columns
-
- override fun asSQL(): String {
- return "UNIQUE (${columns.joinToString() { it.sqlName }})"
- }
-}
-
-abstract class Table(val name: String) {
- val sqlName get() = "`$name`"
- protected val _mutable_columns: MutableList<Column<*>> = mutableListOf()
- protected val _mutable_constraints: MutableList<Constraint> = mutableListOf()
- val columns: List<Column<*>> get() = _mutable_columns
- val constraints get() = _mutable_constraints
- protected fun unique(vararg columns: Column<*>) {
- _mutable_constraints.add(UniqueConstraint(columns.toList()))
- }
-
- protected fun <T> column(name: String, type: DBType<T>): Column<T> {
- @Suppress("DEPRECATION") val column = Column(this, name, type)
- _mutable_columns.add(column)
- return column
- }
-
- fun debugSchema() {
- val nameWidth = columns.maxOf { it.name.length }
- val typeWidth = columns.maxOf { it.type.getName().length }
- val totalWidth = maxOf(2 + nameWidth + 3 + typeWidth + 2, name.length + 4)
- val adjustedTypeWidth = totalWidth - nameWidth - 2 - 3 - 2
-
- var string = "\n"
- string += ("+" + "-".repeat(totalWidth - 2) + "+\n")
- string += ("| $name${" ".repeat(totalWidth - 4 - name.length)} |\n")
- string += ("+" + "-".repeat(totalWidth - 2) + "+\n")
- for (column in columns) {
- string += ("| ${column.name}${" ".repeat(nameWidth - column.name.length)} |")
- string += (" ${column.type.getName()}" +
- "${" ".repeat(adjustedTypeWidth - column.type.getName().length)} |\n")
- }
- string += ("+" + "-".repeat(totalWidth - 2) + "+")
- println(string)
- }
-
- fun createIfNotExists(
- connection: Connection,
- filteredColumns: List<Column<*>> = columns
- ) {
- val properties = mutableListOf<String>()
- for (column in filteredColumns) {
- properties.add("${column.sqlName} ${column.type.dbType}")
- }
- val columnSet = filteredColumns.toSet()
- for (constraint in constraints) {
- if (columnSet.containsAll(constraint.affectedColumns)) {
- properties.add(constraint.asSQL())
- }
- }
- connection.prepareAndLog("CREATE TABLE IF NOT EXISTS $sqlName (" + properties.joinToString() + ")")
- .execute()
- }
-
- fun alterTableAddColumns(
- connection: Connection,
- newColumns: List<Column<*>>
- ) {
- for (column in newColumns) {
- connection.prepareAndLog("ALTER TABLE $sqlName ADD ${column.sqlName} ${column.type.dbType}")
- .execute()
- }
- for (constraint in constraints) {
- // TODO: automatically add constraints, maybe (or maybe move constraints into the upgrade schema)
- }
- }
-
- enum class OnConflict {
- FAIL,
- IGNORE,
- REPLACE,
- ;
-
- fun asSql(): String {
- return name
- }
- }
-
- fun insert(connection: Connection, onConflict: OnConflict = OnConflict.FAIL, block: (InsertStatement) -> Unit) {
- val insert = InsertStatement(HashMap())
- block(insert)
- require(insert.properties.keys == columns.toSet())
- val columnNames = columns.joinToString { it.sqlName }
- val valueNames = columns.joinToString { "?" }
- val statement =
- connection.prepareAndLog("INSERT OR ${onConflict.asSql()} INTO $sqlName ($columnNames) VALUES ($valueNames)")
- for ((index, column) in columns.withIndex()) {
- (column as Column<Any>).type.set(statement, index + 1, insert.properties[column]!!)
- }
- statement.execute()
- }
-
- fun from(connection: Connection): Query {
- return Query(connection, mutableListOf(), this)
- }
-
- fun selectAll(connection: Connection): Query {
- return Query(connection, columns.toMutableList(), this)
- }
-}
-
-class InsertStatement(val properties: MutableMap<Column<*>, Any>) {
- operator fun <T : Any> set(key: Column<T>, value: T) {
- properties[key] = value
- }
-}
-
-fun Connection.prepareAndLog(statement: String): PreparedStatement {
- println("Preparing to execute $statement")
- return prepareStatement(statement)
-}
-
-interface SQLQueryComponent {
- fun asSql(): String
-
- /**
- * @return the next writable index (should equal to the amount of `?` in [asSql] + [startIndex])
- */
- fun appendToStatement(stmt: PreparedStatement, startIndex: Int): Int
-
- companion object {
- fun standalone(sql: String): SQLQueryComponent {
- return object : SQLQueryComponent {
- override fun asSql(): String {
- return sql
- }
-
- override fun appendToStatement(stmt: PreparedStatement, startIndex: Int): Int {
- return startIndex
- }
- }
- }
- }
-}
-
-interface BooleanExpression : SQLQueryComponent
-
-data class ORExpression(
- val elements: List<BooleanExpression>
-) : BooleanExpression {
- init {
- require(elements.isNotEmpty())
- }
-
- override fun asSql(): String {
- return (elements + SQLQueryComponent.standalone("FALSE")).joinToString(" OR ", "(", ")") { it.asSql() }
- }
-
- override fun appendToStatement(stmt: PreparedStatement, startIndex: Int): Int {
- var index = startIndex
- for (element in elements) {
- index = element.appendToStatement(stmt, index)
- }
- return index
- }
-}
-
-
-data class ANDExpression(
- val elements: List<BooleanExpression>
-) : BooleanExpression {
- init {
- require(elements.isNotEmpty())
- }
-
- override fun asSql(): String {
- return (elements + SQLQueryComponent.standalone("TRUE")).joinToString(" AND ", "(", ")") { it.asSql() }
- }
-
- override fun appendToStatement(stmt: PreparedStatement, startIndex: Int): Int {
- var index = startIndex
- for (element in elements) {
- index = element.appendToStatement(stmt, index)
- }
- return index
- }
-}
-
-class ClauseBuilder {
- fun <T> column(column: Column<T>): Operand<T> = Operand.ColumnOperand(column)
- fun string(string: String): Operand.StringOperand = Operand.StringOperand(string)
- infix fun Operand<*>.eq(operand: Operand<*>) = Clause.EqualsClause(this, operand)
- infix fun Operand<*>.like(op: Operand.StringOperand) = Clause.LikeClause(this, op)
- infix fun Operand<*>.like(op: String) = Clause.LikeClause(this, string(op))
-}
-
-interface Clause : BooleanExpression {
- companion object {
- operator fun invoke(builder: ClauseBuilder.() -> Clause): Clause {
- return builder(ClauseBuilder())
- }
- }
-
- data class EqualsClause(val left: Operand<*>, val right: Operand<*>) : Clause { // TODO: typecheck this somehow
- override fun asSql(): String {
- return left.asSql() + " = " + right.asSql()
- }
-
- override fun appendToStatement(stmt: PreparedStatement, startIndex: Int): Int {
- var index = startIndex
- index = left.appendToStatement(stmt, index)
- index = right.appendToStatement(stmt, index)
- return index
- }
- }
-
- data class LikeClause<T>(val left: Operand<T>, val right: Operand.StringOperand) : Clause {
- //TODO: check type safety with this one
- override fun asSql(): String {
- return "(" + left.asSql() + " LIKE " + right.asSql() + ")"
- }
-
- override fun appendToStatement(stmt: PreparedStatement, startIndex: Int): Int {
- var index = startIndex
- index = left.appendToStatement(stmt, index)
- index = right.appendToStatement(stmt, index)
- return index
- }
- }
-}
-
-interface Operand<T> : SQLQueryComponent {
- data class ColumnOperand<T>(val column: Column<T>) : Operand<T> {
- override fun asSql(): String {
- return column.qualifiedSqlName
- }
-
- override fun appendToStatement(stmt: PreparedStatement, startIndex: Int): Int {
- return startIndex
- }
- }
-
- data class StringOperand(val value: String) : Operand<String> {
- override fun asSql(): String {
- return "?"
- }
-
- override fun appendToStatement(stmt: PreparedStatement, startIndex: Int): Int {
- stmt.setString(startIndex, value)
- return 1 + startIndex
- }
- }
-}
-
-data class Join(
- val table: Table,
-//TODO: aliased columns val tableAlias: String,
- val filter: Clause,
-) : SQLQueryComponent {
- // JOIN ItemEntry on LogEntry.transactionId = ItemEntry.transactionId
- override fun asSql(): String {
- return "JOIN ${table.sqlName} ON ${filter.asSql()}"
- }
-
- override fun appendToStatement(stmt: PreparedStatement, startIndex: Int): Int {
- return filter.appendToStatement(stmt, startIndex)
- }
-}
-
-fun List<SQLQueryComponent>.concatToFilledPreparedStatement(connection: Connection): PreparedStatement {
- var query = ""
- for (element in this) {
- if (query.isNotEmpty()) {
- query += " "
- }
- query += element.asSql()
- }
- val statement = connection.prepareAndLog(query)
- var index = 1
- for (element in this) {
- val nextIndex = element.appendToStatement(statement, index)
- if (nextIndex < index) error("$element went back in time")
- index = nextIndex
- }
- return statement
-}
-
-class Query(
- val connection: Connection,
- val selectedColumns: MutableList<Column<*>>,
- var table: Table,
- var limit: UInt? = null,
- var skip: UInt? = null,
- val joins: MutableList<Join> = mutableListOf(),
- val conditions: MutableList<BooleanExpression> = mutableListOf(),
-// var order: OrderClause?= null,
-) : Iterable<ResultRow> {
- fun join(table: Table, on: Clause): Query {
- joins.add(Join(table, on))
- return this
- }
-
- fun where(binOp: BooleanExpression): Query {
- conditions.add(binOp)
- return this
- }
-
- fun select(vararg columns: Column<*>): Query {
- selectedColumns.addAll(columns)
- return this
- }
-
- fun skip(skip: UInt): Query {
- require(limit != null)
- this.skip = skip
- return this
- }
-
- fun limit(limit: UInt): Query {
- this.limit = limit
- return this
- }
-
- override fun iterator(): Iterator<ResultRow> {
- val columnSelections = selectedColumns.joinToString { it.qualifiedSqlName }
- val elements = mutableListOf(
- SQLQueryComponent.standalone("SELECT $columnSelections FROM ${table.sqlName}"),
- )
- elements.addAll(joins)
- if (conditions.any()) {
- elements.add(SQLQueryComponent.standalone("WHERE"))
- elements.add(ANDExpression(conditions))
- }
- if (limit != null) {
- elements.add(SQLQueryComponent.standalone("LIMIT $limit"))
- if (skip != null) {
- elements.add(SQLQueryComponent.standalone("OFFSET $skip"))
- }
- }
- val prepared = elements.concatToFilledPreparedStatement(connection)
- val results = prepared.executeQuery()
- return object : Iterator<ResultRow> {
- var hasAdvanced = false
- var hasEnded = false
- override fun hasNext(): Boolean {
- if (hasEnded) return false
- if (hasAdvanced) return true
- if (results.next()) {
- hasAdvanced = true
- return true
- } else {
- results.close() // TODO: somehow enforce closing this
- hasEnded = true
- return false
- }
- }
-
- override fun next(): ResultRow {
- if (!hasNext()) {
- throw NoSuchElementException()
- }
- hasAdvanced = false
- return ResultRow(selectedColumns.withIndex().associate {
- it.value to it.value.type.get(results, it.index + 1)
- })
- }
-
- }
- }
-}
-
-class ResultRow(val columnValues: Map<Column<*>, *>) {
- operator fun <T> get(column: Column<T>): T {
- val value = columnValues[column]
- ?: error("Invalid column ${column.name}. Only ${columnValues.keys.joinToString { it.name }} are available.")
- return value as T
- }
-}
-
-
-
-
diff --git a/src/main/kotlin/moe/nea/ledger/database/DBUpgrade.kt b/src/main/kotlin/moe/nea/ledger/database/DBUpgrade.kt
deleted file mode 100644
index 7d1782a..0000000
--- a/src/main/kotlin/moe/nea/ledger/database/DBUpgrade.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-package moe.nea.ledger.database
-
-import java.sql.Connection
-
-interface DBUpgrade {
- val toVersion: Long
- val fromVersion get() = toVersion - 1
- fun performUpgrade(connection: Connection)
-
- companion object {
-
- fun performUpgrades(
- connection: Connection,
- upgrades: Iterable<DBUpgrade>,
- ) {
- for (upgrade in upgrades) {
- upgrade.performUpgrade(connection)
- }
- }
-
- fun performUpgradeChain(
- connection: Connection,
- from: Long, to: Long,
- upgrades: Iterable<DBUpgrade>,
- afterEach: (newVersion: Long) -> Unit,
- ) {
- val table = buildLookup(upgrades)
- for (version in (from + 1)..(to)) {
- val currentUpgrades = table[version] ?: listOf()
- println("Scheduled ${currentUpgrades.size} upgrades to reach DB version $version")
- performUpgrades(connection, currentUpgrades)
- afterEach(version)
- }
- }
-
- fun buildLookup(upgrades: Iterable<DBUpgrade>): Map<Long, List<DBUpgrade>> {
- return upgrades.groupBy { it.toVersion }
- }
-
- fun createTable(to: Long, table: Table, vararg columns: Column<*>): DBUpgrade {
- require(columns.all { it in table.columns })
- return of("Create table ${table}", to) {
- table.createIfNotExists(it, columns.toList())
- }
- }
-
- fun addColumns(to: Long, table: Table, vararg columns: Column<*>): DBUpgrade {
- return of("Add columns to table $table", to) {
- table.alterTableAddColumns(it, columns.toList())
- }
- }
-
- fun of(name: String, to: Long, block: (Connection) -> Unit): DBUpgrade {
- return object : DBUpgrade {
- override val toVersion: Long
- get() = to
-
- override fun performUpgrade(connection: Connection) {
- block(connection)
- }
-
- override fun toString(): String {
- return name
- }
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/database/Database.kt b/src/main/kotlin/moe/nea/ledger/database/Database.kt
deleted file mode 100644
index a77ea30..0000000
--- a/src/main/kotlin/moe/nea/ledger/database/Database.kt
+++ /dev/null
@@ -1,54 +0,0 @@
-package moe.nea.ledger.database
-
-import moe.nea.ledger.Ledger
-import java.sql.Connection
-import java.sql.DriverManager
-
-class Database {
- lateinit var connection: Connection
-
- object MetaTable : Table("LedgerMeta") {
- val key = column("key", DBString)
- val value = column("value", DBString)
-
- init {
- unique(key)
- }
- }
-
- data class MetaKey(val name: String) {
- companion object {
- val DATABASE_VERSION = MetaKey("databaseVersion")
- val LAST_LAUNCH = MetaKey("lastLaunch")
- }
- }
-
- fun setMetaKey(key: MetaKey, value: String) {
- MetaTable.insert(connection, Table.OnConflict.REPLACE) {
- it[MetaTable.key] = key.name
- it[MetaTable.value] = value
- }
- }
-
- val databaseVersion: Long = 1
-
- fun loadAndUpgrade() {
- connection = DriverManager.getConnection("jdbc:sqlite:${Ledger.dataFolder.resolve("database.db")}")
- MetaTable.createIfNotExists(connection)
- val meta = MetaTable.selectAll(connection).associate { MetaKey(it[MetaTable.key]) to it[MetaTable.value] }
- val lastLaunch = meta[MetaKey.LAST_LAUNCH]?.toLong() ?: 0L
- println("Last launch $lastLaunch")
- setMetaKey(MetaKey.LAST_LAUNCH, System.currentTimeMillis().toString())
-
- val oldVersion = meta[MetaKey.DATABASE_VERSION]?.toLong() ?: -1
- println("Old Database Version: $oldVersion; Current version: $databaseVersion")
- // TODO: create a backup if there is a db version upgrade happening
- DBUpgrade.performUpgradeChain(
- connection, oldVersion, databaseVersion,
- Upgrades().upgrades
- ) { version ->
- setMetaKey(MetaKey.DATABASE_VERSION, version.toString())
- }
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/database/Upgrades.kt b/src/main/kotlin/moe/nea/ledger/database/Upgrades.kt
deleted file mode 100644
index e83abe7..0000000
--- a/src/main/kotlin/moe/nea/ledger/database/Upgrades.kt
+++ /dev/null
@@ -1,20 +0,0 @@
-package moe.nea.ledger.database
-
-class Upgrades {
- val upgrades = mutableListOf<DBUpgrade>()
-
- fun add(upgrade: DBUpgrade) = upgrades.add(upgrade)
-
- init {
- add(DBUpgrade.createTable(
- 0, DBLogEntry,
- DBLogEntry.type, DBLogEntry.playerId, DBLogEntry.profileId,
- DBLogEntry.transactionId))
- add(DBUpgrade.createTable(
- 0, DBItemEntry,
- DBItemEntry.itemId, DBItemEntry.size, DBItemEntry.mode, DBItemEntry.transactionId
- ))
- }
-
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/database/schema.dot b/src/main/kotlin/moe/nea/ledger/database/schema.dot
deleted file mode 100644
index d932f6a..0000000
--- a/src/main/kotlin/moe/nea/ledger/database/schema.dot
+++ /dev/null
@@ -1,23 +0,0 @@
-digraph {
- node [shape=plain];
- rankdir=LR;
- entry [label=<
- <table border="0" cellborder="1" cellspacing="0">
- <tr><td>Log Entry</td></tr>
- <tr><td port="player">playerId</td></tr>
- <tr><td port="profile">profileId</td></tr>
- <tr><td port="date">timestamp</td></tr>
- <tr><td port="type">Type</td></tr>
- </table>
- >];
- item [label=<
- <table border="0" cellborder="1" cellspacing="0">
- <tr><td>Item Stack</td><tr>
- <tr><td port="transaction">Transaction</td></tr>
- <tr><td port="id">Item ID</td></tr>
- <tr><td port="count">Count</td></tr>
- <tr><td port="direction">Transfer Direction</td></tr>
- </table>
- >];
-// item:transaction -> entry;
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt b/src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt
deleted file mode 100644
index 098912a..0000000
--- a/src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package moe.nea.ledger.events
-
-import net.minecraft.client.gui.GuiScreen
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
-import net.minecraftforge.fml.common.eventhandler.Event
-
-data class BeforeGuiAction(val gui: GuiScreen) : Event() {
- val chest = gui as? GuiChest
- val chestSlots = chest?.inventorySlots as ContainerChest?
-}
diff --git a/src/main/kotlin/moe/nea/ledger/events/ChatReceived.kt b/src/main/kotlin/moe/nea/ledger/events/ChatReceived.kt
deleted file mode 100644
index a352c27..0000000
--- a/src/main/kotlin/moe/nea/ledger/events/ChatReceived.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package moe.nea.ledger.events
-
-import moe.nea.ledger.unformattedString
-import net.minecraftforge.client.event.ClientChatReceivedEvent
-import net.minecraftforge.fml.common.eventhandler.Event
-import java.time.Instant
-
-data class ChatReceived(
- val message: String,
- val timestamp: Instant = Instant.now()
-) : Event() {
- constructor(event: ClientChatReceivedEvent) : this(
- event.message.unformattedText.unformattedString().trimEnd()
- )
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/events/ExtraSupplyIdEvent.kt b/src/main/kotlin/moe/nea/ledger/events/ExtraSupplyIdEvent.kt
deleted file mode 100644
index d040961..0000000
--- a/src/main/kotlin/moe/nea/ledger/events/ExtraSupplyIdEvent.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package moe.nea.ledger.events
-
-import moe.nea.ledger.ItemId
-import net.minecraftforge.fml.common.eventhandler.Event
-
-class ExtraSupplyIdEvent(
- private val store: (String, ItemId) -> Unit
-) : Event() {
- fun store(name: String, id: ItemId) {
- store.invoke(name, id)
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/events/GuiClickEvent.kt b/src/main/kotlin/moe/nea/ledger/events/GuiClickEvent.kt
deleted file mode 100644
index 9e057dd..0000000
--- a/src/main/kotlin/moe/nea/ledger/events/GuiClickEvent.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package moe.nea.ledger.events
-
-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/events/InitializationComplete.kt b/src/main/kotlin/moe/nea/ledger/events/InitializationComplete.kt
deleted file mode 100644
index d917039..0000000
--- a/src/main/kotlin/moe/nea/ledger/events/InitializationComplete.kt
+++ /dev/null
@@ -1,6 +0,0 @@
-package moe.nea.ledger.events
-
-import net.minecraftforge.fml.common.eventhandler.Event
-
-class InitializationComplete : Event() {
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/events/SupplyDebugInfo.kt b/src/main/kotlin/moe/nea/ledger/events/SupplyDebugInfo.kt
deleted file mode 100644
index cab0a20..0000000
--- a/src/main/kotlin/moe/nea/ledger/events/SupplyDebugInfo.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package moe.nea.ledger.events
-
-import net.minecraftforge.fml.common.eventhandler.Event
-
-class SupplyDebugInfo : Event() { // TODO: collect this in the event recorder
- val data = mutableListOf<Pair<String, Any>>()
- fun record(key: String, value: Any) {
- data.add(key to value)
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/events/TriggerEvent.kt b/src/main/kotlin/moe/nea/ledger/events/TriggerEvent.kt
deleted file mode 100644
index 3751f43..0000000
--- a/src/main/kotlin/moe/nea/ledger/events/TriggerEvent.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package moe.nea.ledger.events
-
-import net.minecraftforge.fml.common.eventhandler.Cancelable
-import net.minecraftforge.fml.common.eventhandler.Event
-
-@Cancelable
-data class TriggerEvent(val action: String) : Event()
diff --git a/src/main/kotlin/moe/nea/ledger/events/WorldLoadEvent.kt b/src/main/kotlin/moe/nea/ledger/events/WorldLoadEvent.kt
deleted file mode 100644
index d60f3a4..0000000
--- a/src/main/kotlin/moe/nea/ledger/events/WorldLoadEvent.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package moe.nea.ledger.events
-
-import net.minecraftforge.fml.common.eventhandler.Event
-
-class LateWorldLoadEvent : Event()
diff --git a/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt
deleted file mode 100644
index d02095d..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt
+++ /dev/null
@@ -1,143 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ExpiringValue
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.ItemIdProvider
-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.events.BeforeGuiAction
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.getInternalId
-import moe.nea.ledger.getLore
-import moe.nea.ledger.parseShortNumber
-import moe.nea.ledger.unformattedString
-import moe.nea.ledger.useMatcher
-import moe.nea.ledger.utils.di.Inject
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.regex.Pattern
-import kotlin.time.Duration.Companion.seconds
-
-class AuctionHouseDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemIdProvider) {
- data class LastViewedItem(
- val count: Int,
- val id: ItemId,
- )
- /*
- 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 createAuctionScreen = "Confirm( BIN)? Auction".toPattern()
- val auctionCreationCostPattern = "Cost: (?<cost>$SHORT_NUMBER_PATTERN) coins?".toPattern()
-
- val auctionCreatedChatPattern = "(BIN )?Auction started for .*".toPattern()
-
- var lastCreationCost: ExpiringValue<Double> = ExpiringValue.empty()
-
- @SubscribeEvent
- fun onCreateAuctionClick(event: BeforeGuiAction) {
- val slots = event.chestSlots ?: return
- if (!createAuctionScreen.asPredicate().test(slots.lowerChestInventory.name)) return
- val auctionSlot = slots.lowerChestInventory.getStackInSlot(9 + 2) ?: return
- val creationCost = auctionSlot.getLore().firstNotNullOfOrNull {
- auctionCreationCostPattern.useMatcher(it.unformattedString()) { parseShortNumber(group("cost")) }
- }
- if (creationCost != null) {
- lastCreationCost = ExpiringValue(creationCost)
- }
- }
-
- @SubscribeEvent
- fun onCreateAuctionChat(event: ChatReceived) {
- auctionCreatedChatPattern.useMatcher(event.message) {
- lastCreationCost.consume(3.seconds)?.let { cost ->
- ledger.logEntry(LedgerEntry(
- TransactionType.AUCTION_LISTING_CHARGE,
- event.timestamp,
- listOf(ItemChange.loseCoins(cost))
- ))
- }
- }
- }
-
- 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(
- TransactionType.AUCTION_SOLD,
- event.timestamp,
- listOfNotNull(
- ItemChange.gainCoins(parseShortNumber(group("coins"))),
- lastViewedItem?.let { ItemChange.lose(it.id, it.count) }
- ),
- )
- )
- }
- purchased.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.AUCTION_BOUGHT,
- event.timestamp,
- listOf(
- ItemChange.loseCoins(parseShortNumber(group("coins"))),
- ItemChange.gain(
- ids.findForName(group("what")) ?: ItemId.NIL,
- 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))
- }
-
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt
deleted file mode 100644
index 928d30c..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt
+++ /dev/null
@@ -1,49 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-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.events.ChatReceived
-import moe.nea.ledger.parseShortNumber
-import moe.nea.ledger.useMatcher
-import moe.nea.ledger.utils.di.Inject
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.regex.Pattern
-
-
-class BankDetection @Inject constructor(val ledger: LedgerLogger) {
- val withdrawPattern =
- Pattern.compile("^(You have withdrawn|Withdrew) (?<amount>$SHORT_NUMBER_PATTERN) coins?! (?:There's now|You now have) (?<newtotal>$SHORT_NUMBER_PATTERN) coins? (?:left in the account!|in your account!)$")
- val depositPattern =
- Pattern.compile("^(?:You have deposited|Deposited) (?<amount>$SHORT_NUMBER_PATTERN) coins?! (?:There's now|You now have) (?<newtotal>$SHORT_NUMBER_PATTERN) coins? (?:in your account!|in the account!)$")
-
- @SubscribeEvent
- fun onChat(event: ChatReceived) {
- withdrawPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.BANK_WITHDRAW,
- event.timestamp,
- listOf(ItemChange(ItemId.COINS,
- parseShortNumber(group("amount")),
- ItemChange.ChangeDirection.TRANSFORM)),
- )
- )
- }
- depositPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.BANK_DEPOSIT,
- event.timestamp,
- listOf(ItemChange(ItemId.COINS,
- parseShortNumber(group("amount")),
- ItemChange.ChangeDirection.TRANSFORM)),
- )
- )
- }
- }
-
-}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt
deleted file mode 100644
index 0f1fc2c..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt
+++ /dev/null
@@ -1,58 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.ItemIdProvider
-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.events.ChatReceived
-import moe.nea.ledger.parseShortNumber
-import moe.nea.ledger.useMatcher
-import moe.nea.ledger.utils.di.Inject
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.regex.Pattern
-
-class BazaarDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemIdProvider) {
-
- val instaBuyPattern =
- Pattern.compile("\\[Bazaar\\] Bought (?<count>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
- val instaSellPattern =
- Pattern.compile("\\[Bazaar\\] Sold (?<count>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
-
-
- @SubscribeEvent
- fun onInstSellChat(event: ChatReceived) {
- instaBuyPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.BAZAAR_BUY_INSTANT,
- event.timestamp,
- listOf(
- ItemChange.loseCoins(parseShortNumber(group("coins"))),
- ItemChange.gain(
- ids.findForName(group("what")) ?: ItemId.NIL,
- parseShortNumber(group("count"))
- )
- )
- )
- )
- }
- instaSellPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.BAZAAR_SELL_INSTANT,
- event.timestamp,
- listOf(
- ItemChange.gainCoins(parseShortNumber(group("coins"))),
- ItemChange.lose(
- ids.findForName(group("what")) ?: ItemId.NIL,
- parseShortNumber(group("count"))
- )
- ),
- )
- )
- }
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt
deleted file mode 100644
index 330ee1d..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt
+++ /dev/null
@@ -1,95 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.ItemIdProvider
-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.events.ChatReceived
-import moe.nea.ledger.mixin.AccessorGuiEditSign
-import moe.nea.ledger.parseShortNumber
-import moe.nea.ledger.useMatcher
-import moe.nea.ledger.utils.di.Inject
-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 @Inject constructor(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(
- TransactionType.BAZAAR_BUY_ORDER,
- event.timestamp,
- listOf(
- ItemChange.loseCoins(lastFlippedPreviousPrice * amount),
- ItemChange.gain(
- ids.findForName(group("what")) ?: ItemId.NIL,
- amount,
- )
- )
- )
- )
- }
- buyOrderClaimed.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.BAZAAR_BUY_ORDER,
- event.timestamp,
- listOf(
- ItemChange.loseCoins(parseShortNumber(group("coins"))),
- ItemChange.gain(
- ids.findForName(group("what")) ?: ItemId.NIL,
- parseShortNumber(group("amount"))
- )
- ),
- )
- )
- }
- sellOrderClaimed.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.BAZAAR_SELL_ORDER,
- event.timestamp,
- listOf(
- ItemChange.gainCoins(
- parseShortNumber(group("coins"))
- ),
- ItemChange.lose(
- ids.findForName(group("what")) ?: ItemId.NIL,
- parseShortNumber(group("amount")),
- )
- ),
- )
- )
- }
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt
deleted file mode 100644
index e4c3c98..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt
+++ /dev/null
@@ -1,61 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.events.LateWorldLoadEvent
-import moe.nea.ledger.LedgerEntry
-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.parseShortNumber
-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
-
-class BitsDetection @Inject constructor(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(
- TransactionType.BITS_PURSE_STATUS,
- Instant.now(),
- listOf(
- ItemChange(ItemId.BITS, bits.toDouble(), ItemChange.ChangeDirection.SYNC)
- )
- )
- )
- lastBits = bits
- }
- return
- }
- }
- }
-
- @SubscribeEvent
- fun onEvent(event: ChatReceived) {
- if (event.message.startsWith("You consumed a Booster Cookie!")) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.BOOSTER_COOKIE_ATE,
- Instant.now(),
- listOf(
- ItemChange.lose(ItemId.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
deleted file mode 100644
index d7e0a0d..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt
+++ /dev/null
@@ -1,65 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.events.GuiClickEvent
-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.getInternalId
-import moe.nea.ledger.getLore
-import moe.nea.ledger.parseShortNumber
-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
-
-class BitsShopDetection @Inject constructor(val ledger: LedgerLogger) {
-
-
- data class BitShopEntry(
- val id: ItemId,
- val stackSize: Int,
- 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, stack.stackSize, 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(
- TransactionType.COMMUNITY_SHOP_BUY,
- Instant.now(),
- listOf(
- ItemChange.lose(ItemId.BITS, lastBit.bitPrice.toDouble()),
- ItemChange.gain(lastBit.id, lastBit.stackSize)
- )
- )
- )
- }
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/ChestDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/ChestDetection.kt
deleted file mode 100644
index cca02e1..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/ChestDetection.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.ItemIdProvider
-import moe.nea.ledger.getDisplayNameU
-import moe.nea.ledger.getInternalId
-import moe.nea.ledger.getLore
-import moe.nea.ledger.unformattedString
-import moe.nea.ledger.utils.di.Inject
-import net.minecraft.init.Blocks
-import net.minecraft.inventory.Slot
-import net.minecraft.item.Item
-import java.time.Instant
-
-abstract class ChestDetection {
- data class ChestCost(
- val diff: List<ItemChange>,
- val timestamp: Instant,
- )
-
- @Inject
- lateinit var itemIdProvider: ItemIdProvider
- fun scrapeChestReward(rewardSlot: Slot): ChestCost? {
- val inventory = rewardSlot.inventory
- if (!inventory.displayName.unformattedText.unformattedString()
- .endsWith(" Chest")
- ) return null
- val rewardStack = rewardSlot.stack ?: return null
- val name = rewardStack.getDisplayNameU()
- if (name != "§aOpen Reward Chest") return null
- val lore = rewardStack.getLore()
- val cost = itemIdProvider.findCostItemsFromSpan(lore)
- val gain = (9..18)
- .mapNotNull { inventory.getStackInSlot(it) }
- .filter { it.item != Item.getItemFromBlock(Blocks.stained_glass_pane) }
- .map {
- it.getInternalId()?.withStackSize(it.stackSize)
- ?: itemIdProvider.findStackableItemByName(it.displayName)
- ?: ItemId.NIL.withStackSize(it.stackSize)
- }
- return ChestCost(
- cost.map { ItemChange.lose(it.first, it.second) } + gain.map { ItemChange.gain(it.first, it.second) },
- Instant.now()
- )
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt
deleted file mode 100644
index feb452e..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt
+++ /dev/null
@@ -1,70 +0,0 @@
-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.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 kotlin.time.Duration.Companion.seconds
-
-class DungeonChestDetection @Inject constructor(val logger: LedgerLogger) : ChestDetection() {
-
- @SubscribeEvent
- fun onKismetClick(event: GuiClickEvent) {
- val slot = event.slotIn ?: return
- if (!slot.inventory.displayName.unformattedText.unformattedString().endsWith(" Chest")) return
- val stack = slot.stack ?: return
- if (stack.getDisplayNameU() == "§aReroll Chest") {
- logger.logEntry(
- LedgerEntry(
- TransactionType.KISMET_REROLL,
- Instant.now(),
- listOf(
- ItemChange.lose(ItemId.KISMET_FEATHER, 1)
- )
- )
- )
- }
- }
-
-
- var lastOpenedChest = ExpiringValue.empty<ChestCost>()
-
- @SubscribeEvent
- fun supplyExtraIds(event: ExtraSupplyIdEvent) {
- event.store("Dungeon Chest Key", ItemId("DUNGEON_CHEST_KEY"))
- event.store("Kismet Feather", ItemId("KISMET_FEATHER"))
- }
-
- @SubscribeEvent
- fun onRewardChestClick(event: GuiClickEvent) {
- lastOpenedChest = ExpiringValue(scrapeChestReward(event.slotIn ?: return) ?: return)
- }
-
- val rewardMessage = " .* CHEST REWARDS".toPattern()
-
- @SubscribeEvent
- fun onChatMessage(event: ChatReceived) {
- if (event.message == "You don't have that many coins in the bank!") {
- lastOpenedChest.take()
- }
- rewardMessage.useMatcher(event.message) {
- val chest = lastOpenedChest.consume(3.seconds) ?: return
- logger.logEntry(LedgerEntry(
- TransactionType.DUNGEON_CHEST_OPEN,
- chest.timestamp,
- chest.diff,
- ))
- }
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/ExternalDataProvider.kt b/src/main/kotlin/moe/nea/ledger/modules/ExternalDataProvider.kt
deleted file mode 100644
index 93bb453..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/ExternalDataProvider.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.events.InitializationComplete
-import moe.nea.ledger.events.SupplyDebugInfo
-import moe.nea.ledger.utils.GsonUtil
-import moe.nea.ledger.utils.di.Inject
-import moe.nea.ledger.utils.network.Request
-import moe.nea.ledger.utils.network.RequestUtil
-import net.minecraftforge.common.MinecraftForge
-import net.minecraftforge.fml.common.eventhandler.Event
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.concurrent.CompletableFuture
-
-class ExternalDataProvider @Inject constructor(
- val requestUtil: RequestUtil
-) {
-
- fun createAuxillaryDataRequest(path: String): Request {
- return requestUtil.createRequest("https://github.com/nea89o/ledger-auxiliary-data/raw/refs/heads/master/$path")
- }
-
- private val itemNameFuture: CompletableFuture<Map<String, String>> = CompletableFuture.supplyAsync {
- val request = createAuxillaryDataRequest("data/item_names.json")
- val response = request.execute(requestUtil)
- val nameMap = response.json(GsonUtil.typeToken<Map<String, String>>())
- return@supplyAsync nameMap
- }
-
- lateinit var itemNames: Map<String, String>
-
- class DataLoaded(val provider: ExternalDataProvider) : Event()
-
- @SubscribeEvent
- fun onDebugData(debugInfo: SupplyDebugInfo) {
- debugInfo.record("externalItemsLoaded", itemNameFuture.isDone && !itemNameFuture.isCompletedExceptionally)
- }
-
- @SubscribeEvent
- fun onInitComplete(event: InitializationComplete) {
- itemNames = itemNameFuture.join()
- MinecraftForge.EVENT_BUS.post(DataLoaded(this))
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/ForgeDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/ForgeDetection.kt
deleted file mode 100644
index 95811ed..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/ForgeDetection.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.LedgerEntry
-import moe.nea.ledger.LedgerLogger
-import moe.nea.ledger.TransactionType
-import moe.nea.ledger.events.GuiClickEvent
-import moe.nea.ledger.getInternalId
-import moe.nea.ledger.matches
-import moe.nea.ledger.unformattedString
-import moe.nea.ledger.utils.di.Inject
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.time.Instant
-
-class ForgeDetection {
- val furnaceSlot = 9 + 4
- val furnaceName = "Forge Slot.*".toPattern()
-
- @SubscribeEvent
- fun onClick(event: GuiClickEvent) {
- val slot = event.slotIn ?: return
- val clickedItem = slot.stack ?: return
- if (clickedItem.displayName.unformattedString() != "Confirm") return
- val furnaceSlotName = slot.inventory.getStackInSlot(furnaceSlot)?.displayName?.unformattedString() ?: return
- if (!furnaceName.matches(furnaceSlotName))
- return
- val cl = (0 until slot.inventory.sizeInventory - 9)
- .mapNotNull {
- val stack = slot.inventory.getStackInSlot(it) ?: return@mapNotNull null
- val x = it % 9
- if (x == 4) return@mapNotNull null
- ItemChange(
- stack.getInternalId() ?: return@mapNotNull null,
- stack.stackSize.toDouble(),
- if (x < 4) ItemChange.ChangeDirection.LOST else ItemChange.ChangeDirection.GAINED
- )
- }
- logger.logEntry(LedgerEntry(
- TransactionType.FORGED,
- Instant.now(),
- cl,
- ))
- }
-
- @Inject
- lateinit var logger: LedgerLogger
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/GambleDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/GambleDetection.kt
deleted file mode 100644
index 6a339d7..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/GambleDetection.kt
+++ /dev/null
@@ -1,61 +0,0 @@
-package moe.nea.ledger.modules
-
-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.useMatcher
-import moe.nea.ledger.utils.di.Inject
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-class GambleDetection {
-
- val dieRolled =
- "Your (?<isHighClass>High Class )?Archfiend Dice rolled a (?<face>[1-7])!.*"
- .toPattern()
-
- @Inject
- lateinit var logger: LedgerLogger
-
- @SubscribeEvent
- 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 face = group("face")
- val rollCost = if (isLowClass) 666_000.0 else 6_600_000.0
- if (face == "7") {
- logger.logEntry(LedgerEntry(
- TransactionType.DIE_ROLLED,
- event.timestamp,
- listOf(
- ItemChange.lose(item, 1),
- ItemChange.loseCoins(rollCost),
- ItemChange.gain(ItemId.ARCHFIEND_DYE, 1),
- )
- ))
- } else if (face == "6") {
- logger.logEntry(LedgerEntry(
- TransactionType.DIE_ROLLED,
- event.timestamp,
- listOf(
- ItemChange.lose(item, 1),
- ItemChange.loseCoins(rollCost),
- ItemChange.gainCoins(if (isLowClass) 15_000_000.0 else 100_000_000.0),
- )
- ))
- } else {
- logger.logEntry(LedgerEntry(
- TransactionType.DIE_ROLLED,
- event.timestamp,
- listOf(
- ItemChange(item, 1.0, ItemChange.ChangeDirection.CATALYST),
- ItemChange.loseCoins(rollCost),
- )
- ))
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt
deleted file mode 100644
index eda5aba..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt
+++ /dev/null
@@ -1,95 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.ItemIdProvider
-import moe.nea.ledger.LedgerEntry
-import moe.nea.ledger.LedgerLogger
-import moe.nea.ledger.TransactionType
-import moe.nea.ledger.events.BeforeGuiAction
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.getInternalId
-import moe.nea.ledger.getLore
-import moe.nea.ledger.useMatcher
-import moe.nea.ledger.utils.di.Inject
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-
-class KatDetection {
- @Inject
- lateinit var log: LedgerLogger
-
- @Inject
- lateinit var itemIdProvider: ItemIdProvider
-
- val giftNameToIdMap = mapOf(
- "flower" to ItemId("KAT_FLOWER"),
- "bouquet" to ItemId("KAT_BOUQUET"),
- )
- val katGift = "\\[NPC\\] Kat: A (?<gift>.*)\\? For me\\? How sweet!".toPattern()
-
- @SubscribeEvent
- fun onChat(event: ChatReceived) {
- katGift.useMatcher(event.message) {
- val giftName = group("gift")
- val giftId = giftNameToIdMap[giftName]
- log.logEntry(LedgerEntry(
- TransactionType.KAT_TIMESKIP,
- event.timestamp,
- listOf(
- ItemChange.lose(giftId ?: ItemId.NIL, 1)
- )
- ))
- }
- }
-
- val confirmSlot = 9 + 9 + 4
- val petSlot = 9 + 4
-
- data class PetUpgrade(
- val beforePetId: ItemId,
- val cost: List<Pair<ItemId, Double>>
- )
-
- var lastPetUpgradeScheduled: PetUpgrade? = null
-
- @SubscribeEvent
- fun onClick(event: BeforeGuiAction) {
- val slots = event.chestSlots ?: return
- val petItem = slots.lowerChestInventory.getStackInSlot(petSlot) ?: return
- val beforePetId = petItem.getInternalId() ?: return
- val confirmItem = slots.lowerChestInventory.getStackInSlot(confirmSlot) ?: return
- val lore = confirmItem.getLore()
- val cost = itemIdProvider.findCostItemsFromSpan(lore)
- lastPetUpgradeScheduled = PetUpgrade(beforePetId, cost)
- }
-
- val petUpgradeDialogue = "\\[NPC\\] Kat: I'll get your (?<type>.*) upgraded to (?<tier>.*) in no time!".toPattern()
- fun upgradePetTier(itemId: ItemId): ItemId {
- val str = itemId.string.split(";", limit = 2)
- if (str.size == 2) {
- val (type, tier) = str
- val tierT = tier.toIntOrNull()
- if (tierT != null)
- return ItemId(type + ";" + (tierT + 1))
- }
- return itemId
- }
-
- @SubscribeEvent
- fun onPetUpgrade(event: ChatReceived) {
- petUpgradeDialogue.useMatcher(event.message) {
- val upgrade = lastPetUpgradeScheduled ?: return
- lastPetUpgradeScheduled = null
- log.logEntry(LedgerEntry(
- TransactionType.KAT_UPGRADE,
- event.timestamp,
- listOf(
- ItemChange.lose(upgrade.beforePetId, 1),
- ItemChange.gain(upgradePetTier(upgrade.beforePetId), 1),
- ) + upgrade.cost.map { ItemChange.lose(it.first, it.second) },
- ))
- }
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/KuudraChestDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/KuudraChestDetection.kt
deleted file mode 100644
index e0e9322..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/KuudraChestDetection.kt
+++ /dev/null
@@ -1,45 +0,0 @@
-package moe.nea.ledger.modules
-
-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.GuiClickEvent
-import moe.nea.ledger.getInternalId
-import moe.nea.ledger.utils.di.Inject
-import net.minecraft.client.Minecraft
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-class KuudraChestDetection : ChestDetection() {
- // TODO: extra essence for kuudra pet (how?), item SALVAGE detection
- // TODO: save uuid along side item id
-
- val kuudraKeyPattern = "KUUDRA_.*_TIER_KEY".toPattern()
-
- @Inject
- lateinit var log: LedgerLogger
-
- @Inject
- lateinit var minecraft: Minecraft
- fun hasKey(keyItem: ItemId): Boolean {
- val p = minecraft.thePlayer ?: return false
- return p.inventory.mainInventory.any { it?.getInternalId() == keyItem }
- }
-
- @SubscribeEvent
- fun onRewardChestClick(event: GuiClickEvent) {
- val diffs = scrapeChestReward(event.slotIn ?: return) ?: return
- val requiredKey = diffs.diff.find {
- it.direction == ItemChange.ChangeDirection.LOST && kuudraKeyPattern.asPredicate().test(it.itemId.string)
- }?.itemId
- if (requiredKey != null && !hasKey(requiredKey)) {
- return
- }
- log.logEntry(LedgerEntry(
- TransactionType.KUUDRA_CHEST_OPEN,
- diffs.timestamp,
- diffs.diff,
- ))
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/MineshaftCorpseDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/MineshaftCorpseDetection.kt
deleted file mode 100644
index 60b06ae..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/MineshaftCorpseDetection.kt
+++ /dev/null
@@ -1,81 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.ItemIdProvider
-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.matches
-import moe.nea.ledger.useMatcher
-import moe.nea.ledger.utils.BorderedTextTracker
-import moe.nea.ledger.utils.di.Inject
-
-class MineshaftCorpseDetection : BorderedTextTracker() {
- /*
-[23:39:47] [Client thread/INFO]: [CHAT] §r§a§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬§r
-[23:39:47] [Client thread/INFO]: [CHAT] §r §r§b§l§r§9§lLAPIS §r§b§lCORPSE LOOT! §r
-[23:39:47] [Client thread/INFO]: [CHAT] §r §r§a§lREWARDS§r
-[23:39:47] [Client thread/INFO]: [CHAT] §r §r§5+100 HOTM Experience§r
-[23:39:47] [Client thread/INFO]: [CHAT] §r §r§a§r§aGreen Goblin Egg§r
-[23:39:47] [Client thread/INFO]: [CHAT] §r §r§9Enchanted Glacite §r§8x2§r
-[23:39:47] [Client thread/INFO]: [CHAT] §r §r§9☠ Fine Onyx Gemstone§r
-[23:39:47] [Client thread/INFO]: [CHAT] §r §r§a☠ Flawed Onyx Gemstone §r§8x20§r
-[23:39:47] [Client thread/INFO]: [CHAT] §r §r§a☘ Flawed Peridot Gemstone §r§8x40§r
-[23:39:47] [Client thread/INFO]: [CHAT] §r §r§bGlacite Powder §r§8x500§r
-[23:39:47] [Client thread/INFO]: [CHAT] §e[SkyHanni] Profit for §9Lapis Corpse§e: §678k§r
-[23:39:47] [Client thread/INFO]: [CHAT] §r§a§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬§r
- */
-
- val corpseEnterMessage = " (?<corpseKind>.*) CORPSE LOOT!".toPattern()
-
- override fun shouldEnter(event: ChatReceived): Boolean {
- return corpseEnterMessage.matches(event.message)
- }
-
- override fun shouldExit(event: ChatReceived): Boolean {
- return genericBorderExit.matches(event.message)
- }
-
- override fun onBorderedTextFinished(enclosed: List<ChatReceived>) {
- val rewards = enclosed.asSequence()
- .dropWhile { it.message != " REWARDS" }
- .drop(1)
- .mapNotNull {
- itemIdProvider.findStackableItemByName(it.message, true)
- }
- .map { ItemChange.unpairGain(it) }
- .toMutableList()
- val introMessage = enclosed.first()
- val corpseTyp = corpseEnterMessage.useMatcher(introMessage.message) {
- group("corpseKind")
- }!!
- val keyTyp = corpseNameToKey[corpseTyp]
- if (keyTyp == null) {
- errorUtil.reportAdHoc("Unknown corpse type $corpseTyp")
- } else if (keyTyp != ItemId.NIL) {
- rewards.add(ItemChange.lose(keyTyp, 1))
- }
- logger.logEntry(
- LedgerEntry(
- TransactionType.CORPSE_DESECRATED,
- introMessage.timestamp,
- rewards
- )
- )
- }
-
- val corpseNameToKey = mapOf(
- "LAPIS" to ItemId.NIL,
- "VANGUARD" to ItemId("SKELETON_KEY"),
- "UMBER" to ItemId("UMBER_KEY"),
- "TUNGSTEN" to ItemId("TUNGSTEN_KEY"),
- )
-
- @Inject
- lateinit var logger: LedgerLogger
-
- @Inject
- lateinit var itemIdProvider: ItemIdProvider
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt
deleted file mode 100644
index 6999c7f..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt
+++ /dev/null
@@ -1,61 +0,0 @@
-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.ROMAN_NUMBER_PATTERN
-import moe.nea.ledger.SHORT_NUMBER_PATTERN
-import moe.nea.ledger.TransactionType
-import moe.nea.ledger.events.BeforeGuiAction
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.parseRomanNumber
-import moe.nea.ledger.parseShortNumber
-import moe.nea.ledger.unformattedString
-import moe.nea.ledger.useMatcher
-import moe.nea.ledger.utils.di.Inject
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.time.Instant
-import kotlin.time.Duration.Companion.seconds
-
-class MinionDetection @Inject constructor(val ledger: LedgerLogger) {
- // §aYou received §r§6367,516.8 coins§r§a!
- val hopperCollectPattern = "You received (?<amount>$SHORT_NUMBER_PATTERN) coins?!".toPattern()
- val minionNamePattern = "(?<name>.*) Minion (?<level>$ROMAN_NUMBER_PATTERN)".toPattern()
-
- var lastOpenedMinion = ExpiringValue.empty<ItemId>()
-
- @SubscribeEvent
- fun onBeforeClaim(event: BeforeGuiAction) {
- val container = event.gui as? GuiChest ?: return
- val inv = (container.inventorySlots as ContainerChest).lowerChestInventory
- val invName = inv.displayName.unformattedText.unformattedString()
- minionNamePattern.useMatcher(invName) {
- val name = group("name")
- val level = parseRomanNumber(group("level"))
- lastOpenedMinion = ExpiringValue(
- ItemId(name.uppercase().replace(" ", "_")
- .replace("MINION", "GENERATOR") + "_" + level))
- }
- }
-
-
- @SubscribeEvent
- fun onChat(event: ChatReceived) {
- hopperCollectPattern.useMatcher(event.message) {
- val minionName = lastOpenedMinion.consume(3.seconds)
- ledger.logEntry(LedgerEntry(
- TransactionType.AUTOMERCHANT_PROFIT_COLLECT,
- Instant.now(),
- listOf(
- ItemChange.gainCoins(parseShortNumber(group("amount"))),
- ItemChange(minionName ?: ItemId.NIL, 1.0, ItemChange.ChangeDirection.CATALYST)
- ),
- ))
- }
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
deleted file mode 100644
index 95b8aa5..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
+++ /dev/null
@@ -1,111 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.ItemIdProvider
-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.asIterable
-import moe.nea.ledger.events.BeforeGuiAction
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.events.ExtraSupplyIdEvent
-import moe.nea.ledger.getDisplayNameU
-import moe.nea.ledger.getInternalId
-import moe.nea.ledger.getLore
-import moe.nea.ledger.parseShortNumber
-import moe.nea.ledger.unformattedString
-import moe.nea.ledger.useMatcher
-import moe.nea.ledger.utils.ErrorUtil
-import moe.nea.ledger.utils.di.Inject
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.regex.Pattern
-
-class NpcDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemIdProvider) {
-
- val npcBuyPattern =
- Pattern.compile("You bought (back )?(?<what>.*?) (x(?<count>$SHORT_NUMBER_PATTERN) )?for (?<coins>$SHORT_NUMBER_PATTERN) Coins?!")
- val npcSellPattern =
- Pattern.compile("You sold (?<what>.*) (x(?<count>$SHORT_NUMBER_PATTERN) )?for (?<coins>$SHORT_NUMBER_PATTERN) Coins?!")
-
- // You bought InfiniDirt™ Wand!
- // You bought Prismapump x4!
- val npcBuyWithItemPattern =
- "You bought (?<what>.*?)!".toPattern()
- var storedPurchases = mutableMapOf<String, List<ItemChange>>()
-
- @SubscribeEvent
- fun onClick(event: BeforeGuiAction) {
- (event.chestSlots?.lowerChestInventory?.asIterable() ?: listOf())
- .filterNotNull().forEach {
- val name = it.getDisplayNameU().unformattedString()
- val id = it.getInternalId() ?: return@forEach
- val count = it.stackSize
- val cost = ids.findCostItemsFromSpan(it.getLore())
- storedPurchases[name] = listOf(ItemChange.gain(id, count)) + cost.map { ItemChange.unpairLose(it) }
- }
- }
-
- @SubscribeEvent
- fun addChocolate(event: ExtraSupplyIdEvent) {
- event.store("Chocolate", ItemId("SKYBLOCK_CHOCOLATE"))
- }
-
- @Inject
- lateinit var errorUtil: ErrorUtil
-
- @SubscribeEvent
- fun onBarteredItemBought(event: ChatReceived) {
- npcBuyWithItemPattern.useMatcher(event.message) {
- val changes = storedPurchases[group("what")]
- if (changes == null) {
- errorUtil.reportAdHoc("Item bought for items without associated cost")
- }
- storedPurchases.clear()
- ledger.logEntry(
- LedgerEntry(
- TransactionType.NPC_BUY,
- event.timestamp,
- changes ?: listOf()
- )
- )
- }
- }
-
- @SubscribeEvent
- fun onNpcBuy(event: ChatReceived) {
- npcBuyPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.NPC_BUY,
- event.timestamp,
- listOf(
- ItemChange.loseCoins(
- parseShortNumber(group("coins")),
- ),
- ItemChange.gain(
- ids.findForName(group("what")) ?: ItemId.NIL,
- group("count")?.let(::parseShortNumber) ?: 1,
- )
- )
- )
- )
- }
- npcSellPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- TransactionType.NPC_SELL,
- event.timestamp,
- listOf(
- ItemChange.gainCoins(parseShortNumber(group("coins"))),
- ItemChange.lose(
- ids.findForName(group("what")) ?: ItemId.NIL,
- group("count")?.let(::parseShortNumber)?.toInt() ?: 1,
- )
- )
- )
- )
- }
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/UpdateChecker.kt b/src/main/kotlin/moe/nea/ledger/modules/UpdateChecker.kt
deleted file mode 100644
index 1d6e299..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/UpdateChecker.kt
+++ /dev/null
@@ -1,149 +0,0 @@
-package moe.nea.ledger.modules
-
-import com.google.gson.JsonPrimitive
-import moe.nea.ledger.DevUtil
-import moe.nea.ledger.LedgerLogger
-import moe.nea.ledger.TriggerCommand
-import moe.nea.ledger.config.LedgerConfig
-import moe.nea.ledger.config.MainOptions
-import moe.nea.ledger.events.RegistrationFinishedEvent
-import moe.nea.ledger.events.TriggerEvent
-import moe.nea.ledger.gen.BuildConfig
-import moe.nea.ledger.utils.ErrorUtil
-import moe.nea.ledger.utils.MinecraftExecutor
-import moe.nea.ledger.utils.di.Inject
-import moe.nea.ledger.utils.network.RequestUtil
-import moe.nea.libautoupdate.CurrentVersion
-import moe.nea.libautoupdate.GithubReleaseUpdateData
-import moe.nea.libautoupdate.GithubReleaseUpdateSource
-import moe.nea.libautoupdate.PotentialUpdate
-import moe.nea.libautoupdate.UpdateContext
-import moe.nea.libautoupdate.UpdateData
-import moe.nea.libautoupdate.UpdateTarget
-import moe.nea.libautoupdate.UpdateUtils
-import net.minecraft.util.ChatComponentText
-import net.minecraft.util.ChatStyle
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.concurrent.CompletableFuture
-
-class UpdateChecker @Inject constructor(
- val errorUtil: ErrorUtil,
- val requestUtil: RequestUtil,
-) {
-
- @Inject
- lateinit var minecraftExecutor: MinecraftExecutor
-
- val updater = UpdateContext(
- NightlyAwareGithubUpdateSource("nea89o", "LocalTransactionLedger"),
- if (DevUtil.isDevEnv) UpdateTarget { listOf() }
- else UpdateTarget.deleteAndSaveInTheSameFolder(UpdateChecker::class.java),
- CurrentVersion.ofTag(BuildConfig.GIT_COMMIT),
- "ledger"
- )
-
- class NightlyAwareGithubUpdateSource(owner: String, repository: String) :
- GithubReleaseUpdateSource(owner, repository) {
- override fun selectUpdate(updateStream: String, releases: List<GithubRelease>): UpdateData? {
- if (updateStream == "nightly") {
- return findAsset(releases.find { it.tagName == "nightly" })
- }
- return super.selectUpdate(updateStream, releases.filter { it.tagName != "nightly" })
- }
-
- val releaseRegex = "commit: `(?<hash>[a-f0-9]+)`".toPattern()
-
- override fun findAsset(release: GithubRelease?): UpdateData? {
- val update = super.findAsset(release) as GithubReleaseUpdateData? ?: return null
- return GithubReleaseUpdateData(
- update.versionName,
- releaseRegex.matcher(update.releaseDescription)
- .takeIf { it.find() }
- ?.run { group("hash") }
- ?.let(::JsonPrimitive)
- ?: update.versionNumber,
- update.sha256,
- update.download,
- update.releaseDescription,
- update.targetCommittish,
- update.createdAt,
- update.publishedAt,
- update.htmlUrl
- )
- }
- }
-
- init {
- UpdateUtils.patchConnection {
- this.requestUtil.enhanceConnection(it)
- }
- }
-
- var latestUpdate: PotentialUpdate? = null
- var hasNotified = false
-
- @SubscribeEvent
- fun onStartup(event: RegistrationFinishedEvent) {
- if (config.main.updateCheck == MainOptions.UpdateCheckBehaviour.NONE) return
- launchUpdateCheck()
- }
-
- fun launchUpdateCheck() {
- errorUtil.listenToFuture(
- updater.checkUpdate("nightly")
- .thenAcceptAsync(
- {
- latestUpdate = it
- informAboutUpdates(it)
- }, minecraftExecutor)
- )
- }
-
- @Inject
- lateinit var config: LedgerConfig
-
- @Inject
- lateinit var triggerCommand: TriggerCommand
-
- val installTrigger = "execute-download"
-
- @Inject
- lateinit var logger: LedgerLogger
- fun informAboutUpdates(potentialUpdate: PotentialUpdate) {
- if (hasNotified) return
- hasNotified = true
-// logger.printOut("Update: ${potentialUpdate}")
- if (!potentialUpdate.isUpdateAvailable) return
- logger.printOut(
- ChatComponentText("§aThere is a new update for LocalTransactionLedger. Click here to automatically download and install it.")
- .setChatStyle(ChatStyle().setChatClickEvent(triggerCommand.getTriggerCommandLine(installTrigger))))
- if (config.main.updateCheck == MainOptions.UpdateCheckBehaviour.FULL) {
- downloadUpdate()
- }
- }
-
- var updateFuture: CompletableFuture<Void>? = null
-
- fun downloadUpdate() {
- val l = latestUpdate ?: return
- if (updateFuture != null) return
- // TODO: inject into findAsset to overwrite the tag id with the commit id
- logger.printOut("§aTrying to download ledger update ${l.update.versionName}")
- updateFuture =
- latestUpdate?.launchUpdate()
- ?.thenAcceptAsync(
- {
- logger.printOut("§aLedger update downloaded. It will automatically apply after your next restart.")
- }, minecraftExecutor)
- ?.let(errorUtil::listenToFuture)
- }
-
- @SubscribeEvent
- fun onTrigger(event: TriggerEvent) {
- if (event.action == installTrigger) {
- event.isCanceled = true
- downloadUpdate()
- }
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/VisitorDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/VisitorDetection.kt
deleted file mode 100644
index f457ae4..0000000
--- a/src/main/kotlin/moe/nea/ledger/modules/VisitorDetection.kt
+++ /dev/null
@@ -1,87 +0,0 @@
-package moe.nea.ledger.modules
-
-import moe.nea.ledger.ItemChange
-import moe.nea.ledger.ItemId
-import moe.nea.ledger.ItemIdProvider
-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.events.ExtraSupplyIdEvent
-import moe.nea.ledger.events.GuiClickEvent
-import moe.nea.ledger.getDisplayNameU
-import moe.nea.ledger.getLore
-import moe.nea.ledger.parseShortNumber
-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
-
-class VisitorDetection {
- @Inject
- lateinit var logger: LedgerLogger
-
- @Inject
- lateinit var idProvider: ItemIdProvider
-
- @SubscribeEvent
- fun parseFromItem(event: GuiClickEvent) {
- val stack = event.slotIn?.stack ?: return
-
- val displayName = stack.getDisplayNameU()
- if (displayName != "§aAccept Offer") return
- val lore = stack.getLore()
- if (!lore.contains("§eClick to give!")) return
-
- val rewards = lore
- .asSequence()
- .dropWhile { it != "§7Rewards:" }.drop(1)
- .takeWhile { it != "" }
- .mapNotNull { parseGardenLoreLine(it) }
- .map { ItemChange.gain(it.first, it.second) }
- .toList()
-
- val cost = lore
- .asSequence()
- .dropWhile { it != "§7Items Required:" }.drop(1)
- .takeWhile { it != "" }
- .mapNotNull { parseGardenLoreLine(it) }
- .map { ItemChange.lose(it.first, it.second) }
- .toList()
-
- logger.logEntry(LedgerEntry(
- TransactionType.VISITOR_BARGAIN,
- Instant.now(),
- cost + rewards
- ))
- }
-
- private fun parseGardenLoreLine(rewardLine: String): Pair<ItemId, Double>? {
- val f = rewardLine.unformattedString().trim()
- return idProvider.findStackableItemByName(f, true)
- }
-
-
- @SubscribeEvent
- fun supplyNames(event: ExtraSupplyIdEvent) {
- event.store("Carrot", ItemId("CARROT_ITEM"))
- event.store("Potato", ItemId("POTATO_ITEM"))
- event.store("Jacob's Ticket", ItemId("JACOBS_TICKET"))
- event.store("Cocoa Beans", ItemId("INK_SACK:3"))
- event.store("Enchanted Cocoa Beans", ItemId("ENCHANTED_COCOA"))
- event.store("Enchanted Red Mushroom Block", ItemId("ENCHANTED_HUGE_MUSHROOM_2"))
- event.store("Enchanted Brown Mushroom Block", ItemId("ENCHANTED_HUGE_MUSHROOM_1"))
- event.store("Nether Wart", ItemId("NETHER_STALK"))
- event.store("Enchanted Nether Wart", ItemId("ENCHANTED_NETHER_STALK"))
- event.store("Mutant Nether Wart", ItemId("MUTANT_NETHER_STALK"))
- event.store("Jack o' Lantern", ItemId("JACK_O_LANTERN"))
- event.store("Cactus Green", ItemId("INK_SACK:2"))
- event.store("Hay Bale", ItemId("HAY_BLOCK"))
- event.store("Rabbit's Foot", ItemId("RABBIT_FOOT"))
- event.store("Raw Porkchop", ItemId("PORK"))
- event.store("Raw Rabbit", ItemId("RABBIT"))
- event.store("White Wool", ItemId("WOOL"))
- event.store("Copper Dye", ItemId("DYE_COPPER"))
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt b/src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt
deleted file mode 100644
index 9e621e8..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/BorderedTextTracker.kt
+++ /dev/null
@@ -1,41 +0,0 @@
-package moe.nea.ledger.utils
-
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.utils.di.Inject
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-abstract class BorderedTextTracker {
-
- val genericBorderExit = "▬{10,}".toPattern()
-
- @Inject
- lateinit var errorUtil: ErrorUtil
- var stack: MutableList<ChatReceived>? = null
-
-
- @SubscribeEvent
- fun receiveText(event: ChatReceived) {
- if (stack != null && shouldExit(event)) {
- exit()
- return
- }
- if (shouldEnter(event)) {
- if (stack != null) {
- errorUtil.reportAdHoc("Double entered a bordered message")
- exit()
- }
- stack = mutableListOf()
- }
- stack?.add(event)
- }
-
- private fun exit() {
- onBorderedTextFinished(stack!!)
- stack = null
- }
-
- abstract fun shouldEnter(event: ChatReceived): Boolean
- abstract fun shouldExit(event: ChatReceived): Boolean
- abstract fun onBorderedTextFinished(enclosed: List<ChatReceived>)
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt b/src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt
deleted file mode 100644
index e0c83f9..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt
+++ /dev/null
@@ -1,52 +0,0 @@
-package moe.nea.ledger.utils
-
-import moe.nea.ledger.utils.di.Inject
-import moe.nea.ledger.utils.telemetry.ContextValue
-import moe.nea.ledger.utils.telemetry.EventRecorder
-import moe.nea.ledger.utils.telemetry.Span
-import java.util.concurrent.CompletableFuture
-
-class ErrorUtil {
-
- @Inject
- lateinit var reporter: EventRecorder
-
- fun reportAdHoc(message: String) {
- report(Exception(message), message)
-
- }
-
- fun report(exception: Throwable, message: String?) {
- Span.current().recordException(reporter, exception, message)
- }
-
- fun <T> Result<T>.getOrReport(): T? {
- val exc = exceptionOrNull()
- if (exc != null) {
- report(exc, null)
- }
- return getOrNull()
- }
-
- fun <T : CompletableFuture<*>> listenToFuture(t: T): T {
- t.handle { ignored, exception ->
- if (exception != null)
- report(exception, "Uncaught exception in completable future")
- }
- return t
- }
-
- inline fun <T> catch(
- vararg pairs: Pair<String, ContextValue>,
- crossinline function: () -> T
- ): T? {
- return Span.current().enterWith(*pairs) {
- try {
- return@enterWith function()
- } catch (ex: Exception) {
- report(ex, null)
- return@enterWith null
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/GsonUtil.kt b/src/main/kotlin/moe/nea/ledger/utils/GsonUtil.kt
deleted file mode 100644
index d3c1f6e..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/GsonUtil.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package moe.nea.ledger.utils
-
-import com.google.gson.reflect.TypeToken
-
-object GsonUtil {
- inline fun <reified T> typeToken(): TypeToken<T> {
- return object : TypeToken<T>() {}
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/MinecraftExecutor.kt b/src/main/kotlin/moe/nea/ledger/utils/MinecraftExecutor.kt
deleted file mode 100644
index affd86c..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/MinecraftExecutor.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package moe.nea.ledger.utils
-
-import net.minecraft.client.Minecraft
-import java.util.concurrent.Executor
-
-class MinecraftExecutor : Executor {
- override fun execute(command: Runnable) {
- Minecraft.getMinecraft().addScheduledTask(command)
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/di/DI.kt b/src/main/kotlin/moe/nea/ledger/utils/di/DI.kt
deleted file mode 100644
index a9061d7..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/di/DI.kt
+++ /dev/null
@@ -1,78 +0,0 @@
-package moe.nea.ledger.utils.di
-
-import java.lang.reflect.AnnotatedElement
-import java.util.Collections
-import java.util.Stack
-
-@Suppress("UNCHECKED_CAST")
-class DI {
- private fun formatInjectionStack() =
- injectionStack.joinToString(" -> ")
-
- fun <T : Any> getProvider(type: Class<T>): BaseDIProvider<T, *> {
- val provider = providers[type] as BaseDIProvider<T, *>?
- ?: error("Could not find provider for type $type")
- return provider
- }
-
- private fun <T : Any, C> internalProvide(type: Class<T>, element: AnnotatedElement? = null): T {
- try {
- val provider = getProvider(type) as BaseDIProvider<T, C>
- val context = if (element == null) provider.createEmptyContext() else provider.createContext(element)
- val key = Pair(type, context)
- val existingValue = values[key]
- if (existingValue != null) return existingValue as T
- if (type in injectionStack) {
- error("Found injection cycle: ${formatInjectionStack()} -> $type")
- }
- injectionStack.push(type)
- val value =
- provider.provideWithContext(this, context)
- val cycleCheckCookie = injectionStack.pop()
- require(cycleCheckCookie == type) { "Unbalanced stack cookie: $cycleCheckCookie != $type" }
- values[key] = value
- return value
- } catch (ex: Exception) {
- throw RuntimeException("Could not create instance for type $type (in stack ${formatInjectionStack()})", ex)
- }
- }
-
- fun <T : Any> provide(type: Class<T>, element: AnnotatedElement? = null): T {
- return internalProvide<T, Any>(type, element)
- }
-
- inline fun <reified T : Any> provide(): T = provide(T::class.java)
-
- fun <T : Any> register(type: Class<T>, provider: BaseDIProvider<T, *>) {
- providers[type] = provider
- }
-
- fun registerInjectableClasses(vararg type: Class<*>) {
- type.forEach { internalRegisterInjectableClass(it) }
- }
-
- private fun <T : Any> internalRegisterInjectableClass(type: Class<T>) {
- register(type, DIProvider.fromInjectableClass(type))
- }
-
- fun instantiateAll() {
- providers.keys.forEach {
- provide(it, null)
- }
- }
-
- fun getAllInstances(): Collection<Any> =
- Collections.unmodifiableCollection(values.values)
-
- fun <T : Any> registerSingleton(value: T) {
- register(value.javaClass, DIProvider.singeleton(value))
- }
-
- private val injectionStack: Stack<Class<*>> = Stack()
- private val values = mutableMapOf<Pair<Class<*>, *>, Any>()
- private val providers = mutableMapOf<Class<*>, BaseDIProvider<*, *>>()
-
- init {
- registerSingleton(this)
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt b/src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt
deleted file mode 100644
index bd5b9ef..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt
+++ /dev/null
@@ -1,52 +0,0 @@
-package moe.nea.ledger.utils.di
-
-import java.lang.reflect.AnnotatedElement
-import java.lang.reflect.Constructor
-
-fun interface DIProvider<T : Any> : BaseDIProvider<T, Unit> {
- override fun provideWithContext(di: DI, context: Unit): T {
- return provide(di)
- }
-
- override fun createContext(element: AnnotatedElement) {
- }
-
- override fun createEmptyContext() {
- }
-
- fun provide(di: DI): T
-
- companion object {
-
- fun <T : Any> fromInjectableClass(clazz: Class<T>): DIProvider<T> {
- @Suppress("UNCHECKED_CAST")
- val cons = (clazz.constructors.find { it.getAnnotation(Inject::class.java) != null }
- ?: clazz.constructors.find { it.parameterCount == 0 }
- ?: error("Could not find DI injection entrypoint for class $clazz"))
- as Constructor<out T>
- // TODO: consider using unsafe init to inject the parameters *before* calling the constructor
- return DIProvider { di ->
- val typArgs = cons.parameters.map {
- di.provide(it.type, it)
- }.toTypedArray()
- val instance = cons.newInstance(*typArgs)
- for (it in clazz.fields) {
- if (it.getAnnotation(Inject::class.java) == null) continue
- it.set(instance, di.provide(it.type, it))
- }
- instance
- }
- }
-
- fun <T : Any> singeleton(value: T): DIProvider<T> {
- return DIProvider { _ -> value }
- }
- }
-
-}
-
-interface BaseDIProvider<T : Any, C> {
- fun createContext(element: AnnotatedElement): C
- fun provideWithContext(di: DI, context: C): T
- fun createEmptyContext(): C
-}
diff --git a/src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt b/src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt
deleted file mode 100644
index a8fdd87..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt
+++ /dev/null
@@ -1,6 +0,0 @@
-package moe.nea.ledger.utils.di
-
-@Retention(AnnotationRetention.RUNTIME)
-@Target(AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FIELD)
-annotation class Inject(
-)
diff --git a/src/main/kotlin/moe/nea/ledger/utils/network/Request.kt b/src/main/kotlin/moe/nea/ledger/utils/network/Request.kt
deleted file mode 100644
index ddf2fcc..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/network/Request.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-package moe.nea.ledger.utils.network
-
-import com.google.gson.JsonElement
-import java.net.URL
-
-data class Request(
- val url: URL,
- val method: Method,
- val body: String?,
- val headers: Map<String, String>,
-) {
- enum class Method {
- GET, POST
- }
-
- enum class MediaType(val text: String) {
- JSON("application/json"),
- TEXT("text/plain"),
- HTML("text/html"),
- ANY("*/*"),
- }
-
- fun withHeaders(map: Map<String, String>): Request {
- // TODO: enforce caselessness?
- return this.copy(headers = headers + map)
- }
-
- fun post() = copy(method = Method.POST)
- fun get() = copy(method = Method.GET)
-
- fun json(element: JsonElement) = copy(
- headers = headers + mapOf("content-type" to "application/json"),
- body = element.toString())
-
- fun accept(request: MediaType) = withHeaders(mapOf("accept" to request.text))
-
- fun acceptJson() = accept(MediaType.JSON)
-
- fun execute(requestUtil: RequestUtil) = requestUtil.executeRequest(this)
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/network/RequestUtil.kt b/src/main/kotlin/moe/nea/ledger/utils/network/RequestUtil.kt
deleted file mode 100644
index a49c65a..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/network/RequestUtil.kt
+++ /dev/null
@@ -1,63 +0,0 @@
-package moe.nea.ledger.utils.network
-
-import moe.nea.ledger.utils.ErrorUtil
-import moe.nea.ledger.utils.di.Inject
-import java.net.URL
-import java.net.URLConnection
-import java.security.KeyStore
-import java.util.zip.GZIPInputStream
-import javax.net.ssl.HttpsURLConnection
-import javax.net.ssl.KeyManagerFactory
-import javax.net.ssl.SSLContext
-import javax.net.ssl.TrustManagerFactory
-
-class RequestUtil @Inject constructor(val errorUtil: ErrorUtil) {
-
- private fun createSSLContext(): SSLContext? = errorUtil.catch {
- val keyStorePath = RequestUtil::class.java.getResourceAsStream("/ledgerkeystore.jks")
- ?: error("Could not locate keystore")
- val keyStore = KeyStore.getInstance("JKS")
- keyStore.load(keyStorePath, "neuneu".toCharArray())
- val kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm())
- val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
- kmf.init(keyStore, null)
- tmf.init(keyStore)
- val ctx = SSLContext.getInstance("TLS")
- ctx.init(kmf.keyManagers, tmf.trustManagers, null)
- return@catch ctx
- }
-
- val sslContext = createSSLContext()
-
- fun enhanceConnection(connection: URLConnection) {
- if (connection is HttpsURLConnection && sslContext != null) {
- connection.sslSocketFactory = sslContext.socketFactory
- }
- }
-
- fun createRequest(url: String) = createRequest(URL(url))
- fun createRequest(url: URL) = Request(url, Request.Method.GET, null, mapOf())
-
- fun executeRequest(request: Request): Response {
- val connection = request.url.openConnection()
- enhanceConnection(connection)
- connection.setRequestProperty("accept-encoding", "gzip")
- request.headers.forEach { (k, v) ->
- connection.setRequestProperty(k, v)
- }
- if (request.body != null) {
- connection.getOutputStream().write(request.body.encodeToByteArray())
- connection.getOutputStream().close()
- }
- var stream = connection.getInputStream()
- if (connection.contentEncoding == "gzip") {
- stream = GZIPInputStream(stream)
- }
- val text = stream.bufferedReader().readText()
- stream.close()
- // Do NOT call connection.disconnect() to allow for connection reuse
- return Response(request, text, connection.headerFields)
- }
-
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/network/Response.kt b/src/main/kotlin/moe/nea/ledger/utils/network/Response.kt
deleted file mode 100644
index daae7f7..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/network/Response.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package moe.nea.ledger.utils.network
-
-import com.google.gson.reflect.TypeToken
-import moe.nea.ledger.Ledger
-
-data class Response(
- val source: Request,
- // TODO: allow other body processors, to avoid loading everything as strings
- val response: String,
- val headers: Map<String, List<String>>,
-) {
- fun <T : Any> json(typ: TypeToken<T>): T {
- return Ledger.gson.fromJson(response, typ.type)
- }
-
- fun <T : Any> json(clazz: Class<T>): T {
- return Ledger.gson.fromJson(response, clazz)
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/BooleanContext.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/BooleanContext.kt
deleted file mode 100644
index 5f4ccdf..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/BooleanContext.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-import com.google.gson.JsonElement
-import com.google.gson.JsonPrimitive
-
-class BooleanContext(val boolean: Boolean) : ContextValue {
- override fun serialize(): JsonElement {
- return JsonPrimitive(boolean)
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/CommonKeys.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/CommonKeys.kt
deleted file mode 100644
index 004ae9c..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/CommonKeys.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-object CommonKeys {
- val EVENT_MESSAGE = "event_message"
- val EXCEPTION = "event_exception"
- val COMMIT_VERSION = "version_commit"
- val VERSION = "version"
- val PHASE = "phase" // TODO: add a sort of "manual" stacktrace with designated function phases
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/Context.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/Context.kt
deleted file mode 100644
index 3c30a52..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/Context.kt
+++ /dev/null
@@ -1,57 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-import com.google.gson.JsonObject
-
-class Context(val data: MutableMap<String, ContextValue> = mutableMapOf()) : ContextValue.Collatable<Context> {
-
- inline fun <reified T : ContextValue> getT(key: String): T? {
- return get(key) as? T
- }
-
- fun get(key: String): ContextValue? {
- return data[key]
- }
-
- fun add(key: String, value: ContextValue) {
- data[key] = value
- }
-
- @Suppress("NOTHING_TO_INLINE")
- private inline fun <T : ContextValue.Collatable<T>> cope(
- left: ContextValue.Collatable<T>,
- right: ContextValue
- ): ContextValue {
- return try {
- left.combineWith(right as T)
- } catch (ex: Exception) {
- // TODO: cope with this better
- right
- }
- }
-
- override fun combineWith(overrides: Context): Context {
- val copy = data.toMutableMap()
- for ((key, overrideValue) in overrides.data) {
- copy.merge(key, overrideValue) { old, new ->
- if (old is ContextValue.Collatable<*>) {
- cope(old, new)
- } else {
- new
- }
- }
- }
- return Context(copy)
- }
-
- override fun actualize(): Context {
- return this
- }
-
- override fun serialize(): JsonObject {
- val obj = JsonObject()
- data.forEach { (k, v) ->
- obj.add(k, v.serialize())
- }
- return obj
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/ContextValue.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/ContextValue.kt
deleted file mode 100644
index b5891fc..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/ContextValue.kt
+++ /dev/null
@@ -1,70 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-import com.google.gson.JsonElement
-import com.google.gson.JsonObject
-
-interface ContextValue {
- companion object {
- fun <T : Collatable<T>> lazyCollatable(value: () -> Collatable<T>): Collatable<T> {
- return LazyCollatable(value)
- }
-
- fun lazy(value: () -> ContextValue): ContextValue {
- return object : ContextValue {
- val value by kotlin.lazy(value)
- override fun serialize(): JsonElement {
- return this.value.serialize()
- }
- }
- }
-
- fun bool(boolean: Boolean): ContextValue {
- return BooleanContext(boolean)
- }
-
- fun string(message: String): ContextValue {
- return StringContext(message)
- }
-
- fun jsonObject(vararg pairs: Pair<String, JsonElement>): ContextValue {
- val obj = JsonObject()
- for ((l, r) in pairs) {
- obj.add(l, r)
- }
- return JsonElementContext(obj)
- }
-
- fun compound(vararg pairs: Pair<String, String>): ContextValue {
- val obj = JsonObject()
- for ((l, r) in pairs) {
- obj.addProperty(l, r)
- }
- // TODO: should this be its own class?
- return JsonElementContext(obj)
- }
- }
-
- // TODO: allow other serialization formats
- fun serialize(): JsonElement
- interface Collatable<T : Collatable<T>> : ContextValue {
- fun combineWith(overrides: T): T
- fun actualize(): T
- }
-
- private class LazyCollatable<T : Collatable<T>>(
- provider: () -> Collatable<T>,
- ) : Collatable<T> {
- val value by kotlin.lazy(provider)
- override fun actualize(): T {
- return value.actualize()
- }
-
- override fun combineWith(overrides: T): T {
- return value.combineWith(overrides)
- }
-
- override fun serialize(): JsonElement {
- return value.serialize()
- }
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/EventRecorder.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/EventRecorder.kt
deleted file mode 100644
index 28b1ab5..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/EventRecorder.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-interface EventRecorder {
- companion object {
- var instance: EventRecorder? = null
- }
-
- fun record(event: RecordedEvent)
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt
deleted file mode 100644
index 96b70ec..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-import com.google.gson.JsonArray
-import com.google.gson.JsonElement
-import com.google.gson.JsonObject
-
-class ExceptionContextValue(val exception: Throwable) : ContextValue {
- val stackTrace by lazy {
- exception.stackTraceToString()
- }
-
- override fun serialize(): JsonElement {
- val jsonObject = JsonObject()
- jsonObject.addProperty("exception_stackTrace", stackTrace)
- jsonObject.add("exception_structure", walkExceptions(exception, 6))
- return jsonObject
- }
-
- private fun walkExceptions(exception: Throwable, searchDepth: Int): JsonElement {
- val obj = JsonObject()
- obj.addProperty("class", exception.javaClass.name)
- obj.addProperty("message", exception.message)
- // TODO: allow exceptions to implement an "extra info" interface
- if (searchDepth > 0) {
- val cause = exception.cause
- if (cause != null && cause !== exception) {
- obj.add("cause", walkExceptions(cause, searchDepth - 1))
- }
- val suppressions = JsonArray()
- for (suppressedException in exception.suppressedExceptions) {
- suppressions.add(walkExceptions(suppressedException, searchDepth - 1))
- }
- if (suppressions.size() > 0) {
- obj.add("suppressions", suppressions)
- }
- }
- return obj
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/JsonElementContext.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/JsonElementContext.kt
deleted file mode 100644
index 1601f56..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/JsonElementContext.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-import com.google.gson.JsonElement
-
-class JsonElementContext(val element: JsonElement) : ContextValue {
- override fun serialize(): JsonElement {
- return element
- }
-}
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/LoggingEventRecorder.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/LoggingEventRecorder.kt
deleted file mode 100644
index 82a76ed..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/LoggingEventRecorder.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-import com.google.gson.GsonBuilder
-import org.apache.logging.log4j.Logger
-
-class LoggingEventRecorder(
- val logger: Logger,
- val logJson: Boolean
-) : EventRecorder {
- companion object {
- private val gson = GsonBuilder().setPrettyPrinting().create()
- }
-
- override fun record(event: RecordedEvent) {
- val exc = event.context.getT<ExceptionContextValue>(CommonKeys.EXCEPTION)
- var message = "Event Recorded: " + event.context.getT<StringContext>(CommonKeys.EVENT_MESSAGE)?.message
- if (logJson) {
- message += "\n" + gson.toJson(event.context.serialize())
- }
- if (exc != null)
- logger.error(message, exc.exception)
- else
- logger.warn(message)
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/RecordedEvent.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/RecordedEvent.kt
deleted file mode 100644
index 346417d..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/RecordedEvent.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-class RecordedEvent(val context: Context) {
-
-}
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/Severity.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/Severity.kt
deleted file mode 100644
index e9a3b79..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/Severity.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-enum class Severity {
- INFO,
- WARN,
- ERROR,
- CRITICAL,
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt
deleted file mode 100644
index 0d680a9..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt
+++ /dev/null
@@ -1,146 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-class Span(val parent: Span?) : AutoCloseable {
- companion object {
- private val _current = object : InheritableThreadLocal<Span>() {
- override fun initialValue(): Span {
- return Span(null)
- }
-
- override fun childValue(parentValue: Span?): Span {
- return parentValue?.forkNewRoot() ?: initialValue()
- }
- }
-
- fun current(): Span {
- return _current.get()
- }
- }
-
- private val data = Context()
-
- // TODO : replace string key with a SpanKey<T> class
- fun add(key: String, value: ContextValue) {
- data.add(key, value)
- }
-
- /**
- * Create a sub span, and [enter] it, with the given values.
- */
- fun <T> enterWith(vararg pairs: Pair<String, ContextValue>, block: Span.() -> T): T {
- return enter().use { span ->
- pairs.forEach { (k, value) ->
- span.add(k, value)
- }
- block(span)
- }
- }
-
- /**
- * Create a sub span, to attach some additional context, without modifying the [current] at all.
- */
- fun forkWith(vararg pairs: Pair<String, ContextValue?>): Span {
- val newSpan = fork()
- for ((key, value) in pairs) {
- if (value == null) continue
- newSpan.add(key, value)
- }
- return newSpan
- }
-
- /**
- * Create a sub span, to which additional context can be added. This context will receive updates from its parent,
- * and will be set as the [current]. To return to the parent, either call [exit] on the child. Or use inside of a
- * [use] block.
- */
- fun enter(): Span {
- require(_current.get() == this)
- return fork().enterSelf()
- }
-
- /**
- * Force [enter] this span, without creating a subspan. This bypasses checks like parent / child being the [current].
- */
- fun enterSelf(): Span {
- _current.set(this)
- return this
- }
-
- /**
- * Creates a temporary sub span, to which additional context can be added. This context will receive updates from
- * its parent, but will not be set as the [current].
- */
- fun fork(): Span {
- return Span(this)
- }
-
- /**
- * Create a new root span, that will not receive any updates from the current span, but will have all the same
- * context keys associated.
- */
- fun forkNewRoot(): Span {
- val newRoot = Span(null)
- newRoot.data.data.putAll(collectContext().data)
- return newRoot
- }
-
- /**
- * Collect the context, including all parent context
- */
- fun collectContext(): Context {
- if (parent != null)
- return data.combineWith(parent.collectContext())
- return data
- }
-
- /**
- * Exit an [entered][enter] span, returning back to the parent context, and discard any current keys.
- */
- fun exit() {
- require(parent != null)
- require(_current.get() == this)
- _current.set(parent)
- }
-
- /**
- * [AutoCloseable] implementation for [exit]
- */
- override fun close() {
- return exit()
- }
-
- /**
- * Record an empty event given the context. This indicates nothing except for "I was here".
- * @see recordMessageEvent
- * @see recordException
- */
- fun recordEmptyTrace(recorder: EventRecorder) {
- recorder.record(RecordedEvent(collectContext()))
- }
-
- /**
- * Record a message with the key `"event_message"` to the recorder
- */
- fun recordMessageEvent(
- recorder: EventRecorder,
- message: String
- ) {
- forkWith(CommonKeys.EVENT_MESSAGE to ContextValue.string(message))
- .recordEmptyTrace(recorder)
- }
-
- /**
- * Record an exception to the recorder
- */
- fun recordException(
- recorder: EventRecorder,
- exception: Throwable,
- message: String? = null
- ) {
- forkWith(
- CommonKeys.EVENT_MESSAGE to message?.let(ContextValue::string),
- CommonKeys.EXCEPTION to ExceptionContextValue(exception),
- ).recordEmptyTrace(recorder)
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/StringContext.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/StringContext.kt
deleted file mode 100644
index 2d33075..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/StringContext.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-import com.google.gson.JsonElement
-import com.google.gson.JsonPrimitive
-
-class StringContext(val message: String) : ContextValue {
- override fun serialize(): JsonElement {
- return JsonPrimitive(message)
- }
-
-}
diff --git a/src/main/resources/ledgerkeystore.jks b/src/main/resources/ledgerkeystore.jks
deleted file mode 100644
index b71185a..0000000
--- a/src/main/resources/ledgerkeystore.jks
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info
deleted file mode 100644
index fdeffd8..0000000
--- a/src/main/resources/mcmod.info
+++ /dev/null
@@ -1,18 +0,0 @@
-[
- {
- "modid": "${modid}",
- "name": "Simple Ledger Mod",
- "description": "Export all your activities into a file",
- "version": "${version}",
- "mcversion": "${mcversion}",
- "url": "https://github.com/nea89o/LocalTransactionLedger/",
- "updateUrl": "",
- "authorList": [
- "nea89"
- ],
- "credits": "",
- "logoFile": "",
- "screenshots": [],
- "dependencies": []
- }
-] \ No newline at end of file
diff --git a/src/main/resources/mixins.moneyledger.json b/src/main/resources/mixins.moneyledger.json
deleted file mode 100644
index 5ea0c57..0000000
--- a/src/main/resources/mixins.moneyledger.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "package": "${basePackage}.mixin",
- "plugin": "${basePackage}.init.AutoDiscoveryMixinPlugin",
- "refmap": "mixins.${modid}.refmap.json",
- "minVersion": "0.7",
- "compatibilityLevel": "JAVA_8",
- "__comment": "You do not need to manually register mixins in this template. Check the auto discovery mixin plugin for more info."
-}