aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-02 16:47:40 +0200
committerLinnea Gräf <nea@nea.moe>2024-04-02 16:47:40 +0200
commite1e67eb83e2ae35e770fb0612a4b99dd29f869da (patch)
treef8309286b524f2b38285a407b7db367162f90866 /src/main
parent3f2c87f82167afe75e8c17f74d24e8ee659d4a61 (diff)
downloadLocalTransactionLedger-e1e67eb83e2ae35e770fb0612a4b99dd29f869da.tar.gz
LocalTransactionLedger-e1e67eb83e2ae35e770fb0612a4b99dd29f869da.tar.bz2
LocalTransactionLedger-e1e67eb83e2ae35e770fb0612a4b99dd29f869da.zip
Add logging toggle
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/moe/nea/ledger/Ledger.kt2
-rw-r--r--src/main/kotlin/moe/nea/ledger/LedgerLogger.kt28
2 files changed, 30 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/Ledger.kt b/src/main/kotlin/moe/nea/ledger/Ledger.kt
index 1fc7954..bf3ac9e 100644
--- a/src/main/kotlin/moe/nea/ledger/Ledger.kt
+++ b/src/main/kotlin/moe/nea/ledger/Ledger.kt
@@ -1,6 +1,8 @@
package moe.nea.ledger
import net.minecraft.client.Minecraft
+import net.minecraft.command.CommandBase
+import net.minecraftforge.client.ClientCommandHandler
import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.event.entity.EntityJoinWorldEvent
diff --git a/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt b/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt
index 1e6a861..4d21e5d 100644
--- a/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt
+++ b/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt
@@ -4,7 +4,10 @@ import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import net.minecraft.client.Minecraft
+import net.minecraft.command.CommandBase
+import net.minecraft.command.ICommandSender
import net.minecraft.util.ChatComponentText
+import net.minecraftforge.client.ClientCommandHandler
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
import java.io.File
@@ -22,6 +25,29 @@ class LedgerLogger {
var currentProfile: String? = null
+ var shouldLog = false
+
+ init {
+ ClientCommandHandler.instance.registerCommand(object : CommandBase() {
+ 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>?) {
+ shouldLog = !shouldLog
+ printOut("§eLedger logging toggled " + (if (shouldLog) "§aon" else "§coff") + "§e.")
+ }
+ })
+ }
+
@SubscribeEvent
fun onProfileSwitch(event: ChatReceived) {
profileIdPattern.useMatcher(event.message) {
@@ -73,6 +99,8 @@ class LedgerLogger {
}
fun logEntry(entry: LedgerEntry) {
+ if (shouldLog)
+ printToChat(entry)
Ledger.logger.info("Logging entry of type ${entry.transactionType}")
entries.add(entry.intoJson(currentProfile))
commit()