aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/UUIDUtil.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/UUIDUtil.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/UUIDUtil.kt43
1 files changed, 0 insertions, 43 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/UUIDUtil.kt b/src/main/kotlin/moe/nea/ledger/UUIDUtil.kt
deleted file mode 100644
index 5549908..0000000
--- a/src/main/kotlin/moe/nea/ledger/UUIDUtil.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package moe.nea.ledger
-
-import com.mojang.util.UUIDTypeAdapter
-import io.azam.ulidj.ULID
-import net.minecraft.client.Minecraft
-import java.time.Instant
-import java.util.UUID
-import kotlin.random.Random
-
-object UUIDUtil {
- @JvmInline
- value class ULIDWrapper(
- val wrapped: String
- ) {
- fun getTimestamp(): Instant {
- return Instant.ofEpochMilli(ULID.getTimestamp(wrapped))
- }
-
- init {
- require(ULID.isValid(wrapped))
- }
- }
-
- fun parseDashlessUuid(string: String) = UUIDTypeAdapter.fromString(string)
- val NIL_UUID = UUID(0L, 0L)
- fun getPlayerUUID(): UUID {
- val currentUUID = Minecraft.getMinecraft().thePlayer?.uniqueID
- ?: Minecraft.getMinecraft().session?.playerID?.let(::parseDashlessUuid)
- ?: lastKnownUUID
- lastKnownUUID = currentUUID
- return currentUUID
- }
-
- fun createULIDAt(timestamp: Instant): ULIDWrapper {
- return ULIDWrapper(ULID.generate(
- timestamp.toEpochMilli(),
- Random.nextBytes(10)
- ))
- }
-
- private var lastKnownUUID: UUID = NIL_UUID
-
-} \ No newline at end of file