From fa72dd4ce107190cda7bc56234fed650f20e3aa9 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 8 Dec 2024 00:42:01 +0100 Subject: feat: Add visitor trading detection --- src/main/kotlin/moe/nea/ledger/LedgerEntry.kt | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/kotlin/moe/nea/ledger/LedgerEntry.kt (limited to 'src/main/kotlin/moe/nea/ledger/LedgerEntry.kt') diff --git a/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt b/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt new file mode 100644 index 0000000..dec0727 --- /dev/null +++ b/src/main/kotlin/moe/nea/ledger/LedgerEntry.kt @@ -0,0 +1,28 @@ +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, +) { + 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 -- cgit