From 277643f8c39ad02d9485f7fc9039243f098ec383 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 15 Feb 2024 21:59:56 +0100 Subject: use higher priority and add logging --- gradle.properties | 2 +- src/main/kotlin/moe/nea/ledger/ChatReceived.kt | 3 +-- src/main/kotlin/moe/nea/ledger/Ledger.kt | 8 +++++++- src/main/kotlin/moe/nea/ledger/LedgerLogger.kt | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 0cefedf..b414fac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,5 +2,5 @@ loom.platform=forge org.gradle.jvmargs=-Xmx2g baseGroup = moe.nea.ledger mcVersion = 1.8.9 -modid = ledger +modid = moneyledger version = 1.0.0 diff --git a/src/main/kotlin/moe/nea/ledger/ChatReceived.kt b/src/main/kotlin/moe/nea/ledger/ChatReceived.kt index 5e19083..f3c4c50 100644 --- a/src/main/kotlin/moe/nea/ledger/ChatReceived.kt +++ b/src/main/kotlin/moe/nea/ledger/ChatReceived.kt @@ -9,7 +9,6 @@ data class ChatReceived( val timestamp: Instant = Instant.now() ) : Event() { constructor(event: ClientChatReceivedEvent) : this( - event.message.unformattedText - .replace("§.".toRegex(), "") + event.message.unformattedText.unformattedString() ) } \ No newline at end of file diff --git a/src/main/kotlin/moe/nea/ledger/Ledger.kt b/src/main/kotlin/moe/nea/ledger/Ledger.kt index e9f5efc..108c238 100644 --- a/src/main/kotlin/moe/nea/ledger/Ledger.kt +++ b/src/main/kotlin/moe/nea/ledger/Ledger.kt @@ -4,7 +4,9 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.common.MinecraftForge 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 org.apache.logging.log4j.LogManager @Mod(modid = "ledger", useMetadata = true) class Ledger { @@ -33,9 +35,13 @@ class Ledger { TODO: TRADING, FORGE, COOKIE_EATEN, NPC_SELL, NPC_BUY */ + companion object { + val logger = LogManager.getLogger("MoneyLedger") + } @Mod.EventHandler fun init(event: FMLInitializationEvent) { + logger.info("Initializing ledger") val ledger = LedgerLogger() val ids = ItemIdProvider() listOf( @@ -48,7 +54,7 @@ class Ledger { ).forEach(MinecraftForge.EVENT_BUS::register) } - @SubscribeEvent + @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/LedgerLogger.kt b/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt index 548b09d..7690d25 100644 --- a/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt +++ b/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt @@ -33,6 +33,7 @@ class LedgerLogger { val entries = JsonArray() fun logEntry(entry: LedgerEntry) { + Ledger.logger.info("Logging entry of type ${entry.transactionType}") entries.add(entry.intoJson()) commit() } @@ -41,7 +42,7 @@ class LedgerLogger { try { file.writeText(gson.toJson(entries)) } catch (ex: Exception) { - ex.printStackTrace() + Ledger.logger.error("Could not save file", ex) } } -- cgit