Heimdall cleanup and refactor.

This commit is contained in:
2023-02-07 03:51:42 -05:00
parent 5e9ceebc53
commit eb587dc299
21 changed files with 102 additions and 146 deletions

View File

@ -1,16 +1,5 @@
package gay.pizza.foundation.heimdall.table package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table object BlockBreakTable : PlayerTimedLocalEventTable("block_breaks") {
import org.jetbrains.exposed.sql.javatime.timestamp
object BlockBreakTable : Table("block_breaks") {
val time = timestamp("time")
val player = uuid("player")
val world = uuid("world")
val x = double("x")
val y = double("y")
val z = double("z")
val pitch = double("pitch")
val yaw = double("yaw")
val block = text("block") val block = text("block")
} }

View File

@ -1,16 +1,5 @@
package gay.pizza.foundation.heimdall.table package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table object BlockPlaceTable : PlayerTimedLocalEventTable("block_places") {
import org.jetbrains.exposed.sql.javatime.timestamp
object BlockPlaceTable : Table("block_places") {
val time = timestamp("time")
val player = uuid("player")
val world = uuid("world")
val x = double("x")
val y = double("y")
val z = double("z")
val pitch = double("pitch")
val yaw = double("yaw")
val block = text("block") val block = text("block")
} }

View File

@ -1,17 +1,6 @@
package gay.pizza.foundation.heimdall.table package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table object EntityKillTable : PlayerTimedLocalEventTable("entity_kills") {
import org.jetbrains.exposed.sql.javatime.timestamp
object EntityKillTable : Table("entity_kills") {
val time = timestamp("time")
val player = uuid("player")
val entity = uuid("entity") val entity = uuid("entity")
val world = uuid("world")
val x = double("x")
val y = double("y")
val z = double("z")
val pitch = double("pitch")
val yaw = double("yaw")
val entityType = text("entity_type") val entityType = text("entity_type")
} }

View File

@ -1,16 +1,5 @@
package gay.pizza.foundation.heimdall.table package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table object PlayerAdvancementTable : PlayerTimedLocalEventTable("player_advancements") {
import org.jetbrains.exposed.sql.javatime.timestamp
object PlayerAdvancementTable : Table("player_advancements") {
val time = timestamp("time")
val player = uuid("player")
val world = uuid("world")
val x = double("x")
val y = double("y")
val z = double("z")
val pitch = double("pitch")
val yaw = double("yaw")
val advancement = text("advancement") val advancement = text("advancement")
} }

View File

@ -1,17 +1,6 @@
package gay.pizza.foundation.heimdall.table package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table object PlayerDeathTable : PlayerTimedLocalEventTable("player_deaths") {
import org.jetbrains.exposed.sql.javatime.timestamp
object PlayerDeathTable : Table("player_deaths") {
val time = timestamp("time")
val world = uuid("world")
val player = uuid("player")
val x = double("x")
val y = double("y")
val z = double("z")
val pitch = double("pitch")
val yaw = double("yaw")
val experience = double("experience") val experience = double("experience")
val message = text("message").nullable() val message = text("message").nullable()
} }

View File

@ -1,15 +1,3 @@
package gay.pizza.foundation.heimdall.table package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table object PlayerPositionTable : PlayerTimedLocalEventTable("player_positions")
import org.jetbrains.exposed.sql.javatime.timestamp
object PlayerPositionTable : Table("player_positions") {
val time = timestamp("time")
val player = uuid("player")
val world = uuid("world")
val x = double("x")
val y = double("y")
val z = double("z")
val pitch = double("pitch")
val yaw = double("yaw")
}

View File

@ -0,0 +1,7 @@
package gay.pizza.foundation.heimdall.table
abstract class PlayerTimedLocalEventTable(name: String) : TimedLocalEventTable(name) {
val player = uuid("player")
val pitch = double("pitch")
val yaw = double("yaw")
}

View File

@ -0,0 +1,8 @@
package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.javatime.timestamp
abstract class TimedEventTable(name: String) : Table(name) {
val time = timestamp("time")
}

View File

@ -0,0 +1,8 @@
package gay.pizza.foundation.heimdall.table
abstract class TimedLocalEventTable(name: String) : TimedEventTable(name) {
val world = uuid("world")
val x = double("x")
val y = double("y")
val z = double("z")
}

View File

@ -1,10 +1,6 @@
package gay.pizza.foundation.heimdall.table package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table object WorldChangeTable : TimedEventTable("world_changes") {
import org.jetbrains.exposed.sql.javatime.timestamp
object WorldChangeTable : Table("world_changes") {
val time = timestamp("time")
val player = uuid("player") val player = uuid("player")
val fromWorld = uuid("from_world") val fromWorld = uuid("from_world")
val toWorld = uuid("to_world") val toWorld = uuid("to_world")

View File

@ -1,17 +1,8 @@
package gay.pizza.foundation.heimdall.view package gay.pizza.foundation.heimdall.view
import org.jetbrains.exposed.sql.Table import gay.pizza.foundation.heimdall.table.PlayerTimedLocalEventTable
import org.jetbrains.exposed.sql.javatime.timestamp
object BlockChangeView : Table("block_changes") { object BlockChangeView : PlayerTimedLocalEventTable("block_changes") {
val isBreak = bool("break") val isBreak = bool("break")
val time = timestamp("time")
val player = uuid("player")
val world = uuid("world")
val x = double("x")
val y = double("y")
val z = double("z")
val pitch = double("pitch")
val yaw = double("yaw")
val block = text("block") val block = text("block")
} }

View File

@ -1,7 +1,6 @@
package gay.pizza.foundation.chaos package gay.pizza.foundation.chaos
import gay.pizza.foundation.chaos.model.ChaosConfig import gay.pizza.foundation.chaos.model.ChaosConfig
import gay.pizza.foundation.chaos.model.ChaosModuleConfig
import gay.pizza.foundation.chaos.modules.ChaosModule import gay.pizza.foundation.chaos.modules.ChaosModule
import gay.pizza.foundation.chaos.modules.ChaosModules import gay.pizza.foundation.chaos.modules.ChaosModules
import org.bukkit.boss.BarColor import org.bukkit.boss.BarColor

View File

@ -15,19 +15,16 @@ class BlockBreak(
val material: Material, val material: Material,
val timestamp: Instant = Instant.now() val timestamp: Instant = Instant.now()
) : HeimdallEvent() { ) : HeimdallEvent() {
constructor(event: BlockBreakEvent) : this(event.player.uniqueId, event.block.location, event.block.type) constructor(event: BlockBreakEvent) : this(
event.player.uniqueId,
event.block.location,
event.block.type
)
override fun store(transaction: Transaction) { override fun store(transaction: Transaction) {
transaction.apply { transaction.apply {
BlockBreakTable.insert { BlockBreakTable.insert {
it[time] = timestamp putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[player] = playerUniqueIdentity
it[world] = location.world.uid
it[x] = location.x
it[y] = location.y
it[z] = location.z
it[pitch] = location.pitch.toDouble()
it[yaw] = location.yaw.toDouble()
it[block] = material.key.toString() it[block] = material.key.toString()
} }
} }

View File

@ -15,19 +15,16 @@ class BlockPlace(
val material: Material, val material: Material,
val timestamp: Instant = Instant.now() val timestamp: Instant = Instant.now()
) : HeimdallEvent() { ) : HeimdallEvent() {
constructor(event: BlockPlaceEvent) : this(event.player.uniqueId, event.block.location, event.block.type) constructor(event: BlockPlaceEvent) : this(
event.player.uniqueId,
event.block.location,
event.block.type
)
override fun store(transaction: Transaction) { override fun store(transaction: Transaction) {
transaction.apply { transaction.apply {
BlockPlaceTable.insert { BlockPlaceTable.insert {
it[time] = timestamp putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[player] = playerUniqueIdentity
it[world] = location.world.uid
it[x] = location.x
it[y] = location.y
it[z] = location.z
it[pitch] = location.pitch.toDouble()
it[yaw] = location.yaw.toDouble()
it[block] = material.key.toString() it[block] = material.key.toString()
} }
} }

View File

@ -17,14 +17,7 @@ class EntityKill(
override fun store(transaction: Transaction) { override fun store(transaction: Transaction) {
transaction.apply { transaction.apply {
EntityKillTable.insert { EntityKillTable.insert {
it[time] = timestamp putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[player] = playerUniqueIdentity
it[world] = location.world.uid
it[x] = location.x
it[y] = location.y
it[z] = location.z
it[pitch] = location.pitch.toDouble()
it[yaw] = location.yaw.toDouble()
it[entity] = entityUniqueIdentity it[entity] = entityUniqueIdentity
it[entityType] = entityTypeName it[entityType] = entityTypeName
} }

View File

@ -0,0 +1,41 @@
package gay.pizza.foundation.heimdall.plugin.event
import gay.pizza.foundation.heimdall.table.PlayerTimedLocalEventTable
import gay.pizza.foundation.heimdall.table.TimedEventTable
import gay.pizza.foundation.heimdall.table.TimedLocalEventTable
import org.bukkit.Location
import org.jetbrains.exposed.sql.statements.InsertStatement
import java.time.Instant
import java.util.*
fun <T : TimedEventTable, K : Any> T.putTimedEvent(statement: InsertStatement<K>, time: Instant) {
statement[this.time] = time
}
fun <T : TimedLocalEventTable, K : Any> T.putTimedLocalEvent(
statement: InsertStatement<K>,
time: Instant,
location: Location
) {
statement[this.time] = time
statement[this.world] = location.world.uid
statement[this.x] = location.x
statement[this.y] = location.y
statement[this.z] = location.z
}
fun <T : PlayerTimedLocalEventTable, K : Any> T.putPlayerTimedLocalEvent(
statement: InsertStatement<K>,
time: Instant,
location: Location,
player: UUID
) {
statement[this.time] = time
statement[this.world] = location.world.uid
statement[this.x] = location.x
statement[this.y] = location.y
statement[this.z] = location.z
statement[this.player] = player
statement[this.pitch] = location.pitch.toDouble()
statement[this.yaw] = location.yaw.toDouble()
}

View File

@ -15,19 +15,16 @@ class PlayerAdvancement(
val advancement: Advancement, val advancement: Advancement,
val timestamp: Instant = Instant.now() val timestamp: Instant = Instant.now()
) : HeimdallEvent() { ) : HeimdallEvent() {
constructor(event: PlayerAdvancementDoneEvent) : this(event.player.uniqueId, event.player.location, event.advancement) constructor(event: PlayerAdvancementDoneEvent) : this(
event.player.uniqueId,
event.player.location,
event.advancement
)
override fun store(transaction: Transaction) { override fun store(transaction: Transaction) {
transaction.apply { transaction.apply {
PlayerAdvancementTable.insert { PlayerAdvancementTable.insert {
it[time] = timestamp putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[player] = playerUniqueIdentity
it[world] = location.world.uid
it[x] = location.x
it[y] = location.y
it[z] = location.z
it[pitch] = location.pitch.toDouble()
it[yaw] = location.yaw.toDouble()
it[advancement] = this@PlayerAdvancement.advancement.key.toString() it[advancement] = this@PlayerAdvancement.advancement.key.toString()
} }
} }

View File

@ -25,14 +25,7 @@ class PlayerDeath(
override fun store(transaction: Transaction) { override fun store(transaction: Transaction) {
transaction.apply { transaction.apply {
PlayerDeathTable.insert { PlayerDeathTable.insert {
it[time] = timestamp putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[player] = playerUniqueIdentity
it[world] = location.world.uid
it[x] = location.x
it[y] = location.y
it[z] = location.z
it[pitch] = location.pitch.toDouble()
it[yaw] = location.yaw.toDouble()
it[experience] = experienceLevel.toDouble() it[experience] = experienceLevel.toDouble()
it[message] = deathMessage it[message] = deathMessage
} }

View File

@ -13,19 +13,15 @@ class PlayerPosition(
val location: Location, val location: Location,
val timestamp: Instant = Instant.now() val timestamp: Instant = Instant.now()
) : HeimdallEvent() { ) : HeimdallEvent() {
constructor(event: PlayerMoveEvent) : this(event.player.uniqueId, event.to) constructor(event: PlayerMoveEvent) : this(
event.player.uniqueId,
event.to
)
override fun store(transaction: Transaction) { override fun store(transaction: Transaction) {
transaction.apply { transaction.apply {
PlayerPositionTable.insert { PlayerPositionTable.insert {
it[time] = timestamp putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[player] = playerUniqueIdentity
it[world] = location.world.uid
it[x] = location.x
it[y] = location.y
it[z] = location.z
it[pitch] = location.pitch.toDouble()
it[yaw] = location.yaw.toDouble()
} }
} }
} }

View File

@ -17,7 +17,7 @@ class WorldChange(
override fun store(transaction: Transaction) { override fun store(transaction: Transaction) {
transaction.apply { transaction.apply {
WorldChangeTable.insert { WorldChangeTable.insert {
it[time] = timestamp putTimedEvent(it, timestamp)
it[player] = playerUniqueIdentity it[player] = playerUniqueIdentity
it[fromWorld] = fromWorldId it[fromWorld] = fromWorldId
it[fromWorldName] = fromWorldActualName it[fromWorldName] = fromWorldActualName

View File

@ -63,9 +63,9 @@ class BlockChangelog(
BlockChangelog(BlockChangeView.select(filter).orderBy(BlockChangeView.time).map { row -> BlockChangelog(BlockChangeView.select(filter).orderBy(BlockChangeView.time).map { row ->
val time = row[BlockChangeView.time] val time = row[BlockChangeView.time]
val changeIsBreak = row[BlockChangeView.isBreak] val changeIsBreak = row[BlockChangeView.isBreak]
val x = row[gay.pizza.foundation.heimdall.view.BlockChangeView.x] val x = row[BlockChangeView.x]
val y = row[gay.pizza.foundation.heimdall.view.BlockChangeView.y] val y = row[BlockChangeView.y]
val z = row[gay.pizza.foundation.heimdall.view.BlockChangeView.z] val z = row[BlockChangeView.z]
val block = row[gay.pizza.foundation.heimdall.view.BlockChangeView.block] val block = row[gay.pizza.foundation.heimdall.view.BlockChangeView.block]
val location = BlockCoordinate(x.toLong(), y.toLong(), z.toLong()) val location = BlockCoordinate(x.toLong(), y.toLong(), z.toLong())