From 8ea1ea154015e88aab0e676d951f1e70b8844e62 Mon Sep 17 00:00:00 2001 From: Kenneth Endfinger Date: Sat, 8 Jan 2022 02:40:09 -0500 Subject: [PATCH] Gjallarhorn: Start support for player position changelogs and rename replay-block-log to block-changes --- ...lockLogReplay.kt => BlockChangeCommand.kt} | 8 +++--- .../kubelet/foundation/gjallarhorn/main.kt | 4 +-- .../gjallarhorn/state/BlockCoordinate.kt | 2 +- .../gjallarhorn/state/PlayerPositionChange.kt | 15 ++++++++++ .../state/PlayerPositionChangelog.kt | 28 +++++++++++++++++++ 5 files changed, 50 insertions(+), 7 deletions(-) rename tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/{BlockLogReplay.kt => BlockChangeCommand.kt} (96%) create mode 100644 tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/PlayerPositionChange.kt create mode 100644 tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/PlayerPositionChangelog.kt diff --git a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockLogReplay.kt b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockChangeCommand.kt similarity index 96% rename from tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockLogReplay.kt rename to tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockChangeCommand.kt index 1e817c0..6c1c0ec 100644 --- a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockLogReplay.kt +++ b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockChangeCommand.kt @@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ScheduledThreadPoolExecutor import java.util.concurrent.TimeUnit -class BlockLogReplay : CliktCommand("Replay Block Logs", name = "replay-block-log") { +class BlockChangeCommand : CliktCommand("Block Changes", name = "block-changes") { private val db by requireObject() private val exactTimeAsString by option("--time", help = "Replay Time") private val timelapseMode by option("--timelapse", help = "Timelapse Mode").enum { it.id } @@ -36,7 +36,7 @@ class BlockLogReplay : CliktCommand("Replay Block Logs", name = "replay-block-lo private val fromCoordinate by option("--trim-from", help = "Trim From Coordinate") private val toCoordinate by option("--trim-to", help = "Trim To Coordinate") - private val logger = LoggerFactory.getLogger(BlockLogReplay::class.java) + private val logger = LoggerFactory.getLogger(BlockChangeCommand::class.java) override fun run() { if (timelapseMode != null) { @@ -72,9 +72,9 @@ class BlockLogReplay : CliktCommand("Replay Block Logs", name = "replay-block-lo } logger.info("State Tracking Completed") val allBlockOffsets = trackers.map { it.value.calculateZeroBlockOffset() } - val globalBlockOffset = BlockCoordinate.maxOf(allBlockOffsets.asSequence()) + val globalBlockOffset = BlockCoordinate.maxOf(allBlockOffsets) val allBlockMaxes = trackers.map { it.value.calculateMaxBlock() } - val globalBlockMax = BlockCoordinate.maxOf(allBlockMaxes.asSequence()) + val globalBlockMax = BlockCoordinate.maxOf(allBlockMaxes) val globalBlockExpanse = BlockExpanse.offsetAndMax(globalBlockOffset, globalBlockMax) logger.info("Calculations Completed") diff --git a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/main.kt b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/main.kt index 3a8a693..585d802 100644 --- a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/main.kt +++ b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/main.kt @@ -1,12 +1,12 @@ package cloud.kubelet.foundation.gjallarhorn -import cloud.kubelet.foundation.gjallarhorn.commands.BlockLogReplay +import cloud.kubelet.foundation.gjallarhorn.commands.BlockChangeCommand import cloud.kubelet.foundation.gjallarhorn.commands.PlayerPositionExport import cloud.kubelet.foundation.gjallarhorn.commands.PlayerSessionExport import com.github.ajalt.clikt.core.subcommands fun main(args: Array) = GjallarhornCommand().subcommands( - BlockLogReplay(), + BlockChangeCommand(), PlayerSessionExport(), PlayerPositionExport() ).main(args) diff --git a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/BlockCoordinate.kt b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/BlockCoordinate.kt index 3ec4331..95210df 100644 --- a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/BlockCoordinate.kt +++ b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/BlockCoordinate.kt @@ -26,7 +26,7 @@ data class BlockCoordinate( companion object { val zero = BlockCoordinate(0, 0, 0) - fun maxOf(coordinates: Sequence): BlockCoordinate { + fun maxOf(coordinates: List): BlockCoordinate { val x = coordinates.maxOf { it.x } val y = coordinates.maxOf { it.y } val z = coordinates.maxOf { it.z } diff --git a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/PlayerPositionChange.kt b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/PlayerPositionChange.kt new file mode 100644 index 0000000..3d80957 --- /dev/null +++ b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/PlayerPositionChange.kt @@ -0,0 +1,15 @@ +package cloud.kubelet.foundation.gjallarhorn.state + +import java.time.Instant +import java.util.* + +data class PlayerPositionChange( + val time: Instant, + val player: UUID, + val world: UUID, + val x: Double, + val y: Double, + val z: Double, + val pitch: Double, + val yaw: Double +) diff --git a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/PlayerPositionChangelog.kt b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/PlayerPositionChangelog.kt new file mode 100644 index 0000000..8735acd --- /dev/null +++ b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/PlayerPositionChangelog.kt @@ -0,0 +1,28 @@ +package cloud.kubelet.foundation.gjallarhorn.state + +import cloud.kubelet.foundation.heimdall.table.PlayerPositionTable +import org.jetbrains.exposed.sql.Database +import org.jetbrains.exposed.sql.Op +import org.jetbrains.exposed.sql.select +import org.jetbrains.exposed.sql.transactions.transaction + +class PlayerPositionChangelog( + val changes: List +) { + companion object { + fun query(db: Database, filter: Op = Op.TRUE): PlayerPositionChangelog = transaction(db) { + PlayerPositionChangelog(PlayerPositionTable.select(filter).orderBy(PlayerPositionTable.time).map { row -> + val time = row[PlayerPositionTable.time] + val player = row[PlayerPositionTable.player] + val world = row[PlayerPositionTable.world] + val x = row[PlayerPositionTable.x] + val y = row[PlayerPositionTable.y] + val z = row[PlayerPositionTable.z] + val pitch = row[PlayerPositionTable.z] + val yaw = row[PlayerPositionTable.z] + + PlayerPositionChange(time, player, world, x, y, z, pitch, yaw) + }) + } + } +}