From e1e67eb83e2ae35e770fb0612a4b99dd29f869da Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Tue, 2 Apr 2024 16:47:40 +0200 Subject: Add logging toggle --- src/main/kotlin/moe/nea/ledger/Ledger.kt | 2 ++ src/main/kotlin/moe/nea/ledger/LedgerLogger.kt | 28 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'src') 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?) { + 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() -- cgit