Heimdall: Implement Entity Kill Tracking

This commit is contained in:
Kenneth Endfinger 2021-12-24 19:04:03 -05:00
parent e10fa42c68
commit d7f094f765
No known key found for this signature in database
GPG Key ID: C4E68E5647420E10
10 changed files with 103 additions and 17 deletions

View File

@ -14,6 +14,7 @@ import org.bukkit.event.EventHandler
import org.bukkit.event.Listener import org.bukkit.event.Listener
import org.bukkit.event.block.BlockBreakEvent import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.block.BlockPlaceEvent import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.entity.EntityDeathEvent
import org.bukkit.event.entity.PlayerDeathEvent import org.bukkit.event.entity.PlayerDeathEvent
import org.bukkit.event.player.* import org.bukkit.event.player.*
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
@ -133,6 +134,12 @@ class FoundationHeimdallPlugin : JavaPlugin(), Listener {
) )
) )
@EventHandler
fun onEntityDeath(event: EntityDeathEvent) {
val killer = event.entity.killer ?: return
buffer.push(EntityKill(killer.uniqueId, killer.location, event.entity.uniqueId, event.entityType.key.toString()))
}
override fun onDisable() { override fun onDisable() {
bufferFlushThread.stop() bufferFlushThread.stop()
val endTime = Instant.now() val endTime = Instant.now()

View File

@ -24,10 +24,12 @@ class BlockBreak(
it[time] = timestamp it[time] = timestamp
it[player] = playerUniqueIdentity it[player] = playerUniqueIdentity
it[world] = location.world.uid it[world] = location.world.uid
it[block] = material.storageBlockName
it[x] = location.x it[x] = location.x
it[y] = location.y it[y] = location.y
it[z] = location.z it[z] = location.z
it[pitch] = location.pitch.toDouble()
it[yaw] = location.yaw.toDouble()
it[block] = material.storageBlockName
} }
} }
} }

View File

@ -1,6 +1,7 @@
package cloud.kubelet.foundation.heimdall.event package cloud.kubelet.foundation.heimdall.event
import cloud.kubelet.foundation.heimdall.storageBlockName import cloud.kubelet.foundation.heimdall.storageBlockName
import cloud.kubelet.foundation.heimdall.table.BlockBreakTable
import cloud.kubelet.foundation.heimdall.table.BlockPlaceTable import cloud.kubelet.foundation.heimdall.table.BlockPlaceTable
import org.bukkit.Location import org.bukkit.Location
import org.bukkit.Material import org.bukkit.Material
@ -21,13 +22,15 @@ class BlockPlace(
override fun store(transaction: Transaction) { override fun store(transaction: Transaction) {
transaction.apply { transaction.apply {
BlockPlaceTable.insert { BlockPlaceTable.insert {
it[time] = timestamp it[BlockBreakTable.time] = timestamp
it[player] = playerUniqueIdentity it[BlockBreakTable.player] = playerUniqueIdentity
it[world] = location.world.uid it[BlockBreakTable.world] = location.world.uid
it[block] = material.storageBlockName it[BlockBreakTable.x] = location.x
it[x] = location.x it[BlockBreakTable.y] = location.y
it[y] = location.y it[BlockBreakTable.z] = location.z
it[z] = location.z it[BlockBreakTable.pitch] = location.pitch.toDouble()
it[BlockBreakTable.yaw] = location.yaw.toDouble()
it[BlockBreakTable.block] = material.storageBlockName
} }
} }
} }

View File

@ -0,0 +1,33 @@
package cloud.kubelet.foundation.heimdall.event
import cloud.kubelet.foundation.heimdall.table.EntityKillTable
import org.bukkit.Location
import org.jetbrains.exposed.sql.Transaction
import org.jetbrains.exposed.sql.insert
import java.time.Instant
import java.util.*
class EntityKill(
val playerUniqueIdentity: UUID,
val location: Location,
val entityUniqueIdentity: UUID,
val entityTypeName: String,
val timestamp: Instant = Instant.now()
) : HeimdallEvent() {
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()
it[entity] = entityUniqueIdentity
it[entityType] = entityTypeName
}
}
}
}

View File

@ -5,10 +5,12 @@ import org.jetbrains.exposed.sql.javatime.timestamp
object BlockBreakTable : Table("block_breaks") { object BlockBreakTable : Table("block_breaks") {
val time = timestamp("time") val time = timestamp("time")
val world = uuid("world")
val player = uuid("player") val player = uuid("player")
val block = text("block") val world = uuid("world")
val x = double("x") val x = double("x")
val y = double("y") val y = double("y")
val z = double("z") val z = double("z")
val pitch = double("pitch")
val yaw = double("yaw")
val block = text("block")
} }

View File

@ -5,10 +5,12 @@ import org.jetbrains.exposed.sql.javatime.timestamp
object BlockPlaceTable : Table("block_places") { object BlockPlaceTable : Table("block_places") {
val time = timestamp("time") val time = timestamp("time")
val world = uuid("world")
val player = uuid("player") val player = uuid("player")
val block = text("block") val world = uuid("world")
val x = double("x") val x = double("x")
val y = double("y") val y = double("y")
val z = double("z") val z = double("z")
val pitch = double("pitch")
val yaw = double("yaw")
val block = text("block")
} }

View File

@ -0,0 +1,17 @@
package cloud.kubelet.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")
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

@ -5,8 +5,8 @@ import org.jetbrains.exposed.sql.javatime.timestamp
object PlayerAdvancementTable : Table("player_advancements") { object PlayerAdvancementTable : Table("player_advancements") {
val time = timestamp("time") val time = timestamp("time")
val world = uuid("world")
val player = uuid("player") val player = uuid("player")
val world = uuid("world")
val x = double("x") val x = double("x")
val y = double("y") val y = double("y")
val z = double("z") val z = double("z")

View File

@ -5,8 +5,8 @@ import org.jetbrains.exposed.sql.javatime.timestamp
object PlayerPositionTable : Table("player_positions") { object PlayerPositionTable : Table("player_positions") {
val time = timestamp("time") val time = timestamp("time")
val world = uuid("world")
val player = uuid("player") val player = uuid("player")
val world = uuid("world")
val x = double("x") val x = double("x")
val y = double("y") val y = double("y")
val z = double("z") val z = double("z")

View File

@ -23,10 +23,12 @@ create table if not exists heimdall.block_breaks (
time timestamp not null, time timestamp not null,
player uuid not null, player uuid not null,
world uuid not null, world uuid not null,
block text not null,
x double precision not null, x double precision not null,
y double precision not null, y double precision not null,
z double precision not null, z double precision not null,
pitch double precision not null,
yaw double precision not null,
block text not null,
PRIMARY KEY (time, player, world) PRIMARY KEY (time, player, world)
); );
-- --
@ -36,10 +38,12 @@ create table if not exists heimdall.block_places (
time timestamp not null, time timestamp not null,
player uuid not null, player uuid not null,
world uuid not null, world uuid not null,
block text not null,
x double precision not null, x double precision not null,
y double precision not null, y double precision not null,
z double precision not null, z double precision not null,
pitch double precision not null,
yaw double precision not null,
block text not null,
PRIMARY KEY (time, player, world) PRIMARY KEY (time, player, world)
); );
-- --
@ -93,8 +97,24 @@ create table if not exists heimdall.player_advancements (
z double precision not null, z double precision not null,
pitch double precision not null, pitch double precision not null,
yaw double precision not null, yaw double precision not null,
advancement text null, advancement text not null,
primary key (time, player, advancement) primary key (time, player, advancement)
); );
-- --
select create_hypertable('heimdall.player_advancements', 'time', 'player', 4, if_not_exists => TRUE); select create_hypertable('heimdall.player_advancements', 'time', 'player', 4, if_not_exists => TRUE);
--
create table if not exists heimdall.entity_kills (
time timestamp not null,
player uuid not null,
entity uuid not null,
world uuid not null,
x double precision not null,
y double precision not null,
z double precision not null,
pitch double precision not null,
yaw double precision not null,
entity_type text not null,
primary key (time, entity, player)
);
--
select create_hypertable('heimdall.entity_kills', 'time', 'player', 4, if_not_exists => TRUE);