diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-02 16:13:06 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-04-02 16:13:06 +0200 |
commit | 6ffca24b549fc50988b26dacb5297ff8bec7e601 (patch) | |
tree | 9ba796bf0c79f6a71da49cc0b4805a60684b5a0d | |
parent | 3e0198e3a803d2dd46988ba0ac445412c7da8390 (diff) | |
download | money-ledger-6ffca24b549fc50988b26dacb5297ff8bec7e601.tar.gz money-ledger-6ffca24b549fc50988b26dacb5297ff8bec7e601.tar.bz2 money-ledger-6ffca24b549fc50988b26dacb5297ff8bec7e601.zip |
Add player / profile id
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/LedgerLogger.kt | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt b/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt index ba7fd96..56738c5 100644 --- a/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt +++ b/src/main/kotlin/moe/nea/ledger/LedgerLogger.kt @@ -17,6 +17,18 @@ class LedgerLogger { Minecraft.getMinecraft().ingameGUI?.chatGUI?.printChatMessage(ChatComponentText(text)) } + 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: String? = null + + @SubscribeEvent + fun onProfileSwitch(event: ChatReceived) { + profileIdPattern.useMatcher(event.message) { + currentProfile = group("profile") + } + } + fun printToChat(entry: LedgerEntry) { printOut( @@ -27,6 +39,7 @@ class LedgerLogger { §eTOTAL VALUE: §a${entry.totalTransactionCoins} §eITEM ID: §a${entry.itemId} §eITEM AMOUNT: §a${entry.itemAmount} + §ePROFILE: §a${currentProfile} §e================= TRANSACTION END """.trimIndent() ) @@ -62,7 +75,7 @@ class LedgerLogger { fun logEntry(entry: LedgerEntry) { printToChat(entry) Ledger.logger.info("Logging entry of type ${entry.transactionType}") - entries.add(entry.intoJson()) + entries.add(entry.intoJson(currentProfile)) commit() } @@ -101,13 +114,19 @@ data class LedgerEntry( val itemId: String? = null, val itemAmount: Int? = null, ) { - fun intoJson(): JsonObject { + fun intoJson(profileId: String?): JsonObject { return JsonObject().apply { addProperty("transactionType", transactionType) addProperty("timestamp", timestamp.toEpochMilli().toString()) addProperty("totalTransactionValue", totalTransactionCoins) addProperty("itemId", itemId ?: "") addProperty("itemAmount", itemAmount ?: 0) + addProperty("profileId", profileId) + addProperty( + "playerId", + (Minecraft.getMinecraft().thePlayer?.uniqueID?.toString() ?: lastKnownUUID).also { lastKnownUUID = it }) } } } + +var lastKnownUUID = "null" |