Heimdall cleanup and refactor.

This commit is contained in:
Alex Zenla 2023-02-07 03:51:42 -05:00
parent 5e9ceebc53
commit eb587dc299
Signed by: alex
GPG Key ID: C0780728420EBFE5
21 changed files with 102 additions and 146 deletions

View File

@ -1,16 +1,5 @@
package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table
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")
object BlockBreakTable : PlayerTimedLocalEventTable("block_breaks") {
val block = text("block")
}

View File

@ -1,16 +1,5 @@
package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table
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")
object BlockPlaceTable : PlayerTimedLocalEventTable("block_places") {
val block = text("block")
}

View File

@ -1,17 +1,6 @@
package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.javatime.timestamp
object EntityKillTable : Table("entity_kills") {
val time = timestamp("time")
val player = uuid("player")
object EntityKillTable : PlayerTimedLocalEventTable("entity_kills") {
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")
}

View File

@ -1,16 +1,5 @@
package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table
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")
object PlayerAdvancementTable : PlayerTimedLocalEventTable("player_advancements") {
val advancement = text("advancement")
}

View File

@ -1,17 +1,6 @@
package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table
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")
object PlayerDeathTable : PlayerTimedLocalEventTable("player_deaths") {
val experience = double("experience")
val message = text("message").nullable()
}

View File

@ -1,15 +1,3 @@
package gay.pizza.foundation.heimdall.table
import org.jetbrains.exposed.sql.Table
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")
}
object PlayerPositionTable : PlayerTimedLocalEventTable("player_positions")

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
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.javatime.timestamp
object WorldChangeTable : Table("world_changes") {
val time = timestamp("time")
object WorldChangeTable : TimedEventTable("world_changes") {
val player = uuid("player")
val fromWorld = uuid("from_world")
val toWorld = uuid("to_world")

View File

@ -1,17 +1,8 @@
package gay.pizza.foundation.heimdall.view
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.javatime.timestamp
import gay.pizza.foundation.heimdall.table.PlayerTimedLocalEventTable
object BlockChangeView : Table("block_changes") {
object BlockChangeView : PlayerTimedLocalEventTable("block_changes") {
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")
}

View File

@ -1,7 +1,6 @@
package gay.pizza.foundation.chaos
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.ChaosModules
import org.bukkit.boss.BarColor

View File

@ -15,19 +15,16 @@ class BlockBreak(
val material: Material,
val timestamp: Instant = Instant.now()
) : 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) {
transaction.apply {
BlockBreakTable.insert {
it[time] = timestamp
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()
putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[block] = material.key.toString()
}
}

View File

@ -15,19 +15,16 @@ class BlockPlace(
val material: Material,
val timestamp: Instant = Instant.now()
) : 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) {
transaction.apply {
BlockPlaceTable.insert {
it[time] = timestamp
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()
putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[block] = material.key.toString()
}
}

View File

@ -17,14 +17,7 @@ class EntityKill(
override fun store(transaction: Transaction) {
transaction.apply {
EntityKillTable.insert {
it[time] = timestamp
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()
putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[entity] = entityUniqueIdentity
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 timestamp: Instant = Instant.now()
) : 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) {
transaction.apply {
PlayerAdvancementTable.insert {
it[time] = timestamp
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()
putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[advancement] = this@PlayerAdvancement.advancement.key.toString()
}
}

View File

@ -25,14 +25,7 @@ class PlayerDeath(
override fun store(transaction: Transaction) {
transaction.apply {
PlayerDeathTable.insert {
it[time] = timestamp
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()
putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
it[experience] = experienceLevel.toDouble()
it[message] = deathMessage
}

View File

@ -13,19 +13,15 @@ class PlayerPosition(
val location: Location,
val timestamp: Instant = Instant.now()
) : HeimdallEvent() {
constructor(event: PlayerMoveEvent) : this(event.player.uniqueId, event.to)
constructor(event: PlayerMoveEvent) : this(
event.player.uniqueId,
event.to
)
override fun store(transaction: Transaction) {
transaction.apply {
PlayerPositionTable.insert {
it[time] = timestamp
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()
putPlayerTimedLocalEvent(it, timestamp, location, playerUniqueIdentity)
}
}
}

View File

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

View File

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