mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 03:39:37 +00:00 
			
		
		
		
	Heimdall: Implement Entity Kill Tracking
This commit is contained in:
		@ -14,6 +14,7 @@ import org.bukkit.event.EventHandler
 | 
			
		||||
import org.bukkit.event.Listener
 | 
			
		||||
import org.bukkit.event.block.BlockBreakEvent
 | 
			
		||||
import org.bukkit.event.block.BlockPlaceEvent
 | 
			
		||||
import org.bukkit.event.entity.EntityDeathEvent
 | 
			
		||||
import org.bukkit.event.entity.PlayerDeathEvent
 | 
			
		||||
import org.bukkit.event.player.*
 | 
			
		||||
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() {
 | 
			
		||||
    bufferFlushThread.stop()
 | 
			
		||||
    val endTime = Instant.now()
 | 
			
		||||
 | 
			
		||||
@ -24,10 +24,12 @@ class BlockBreak(
 | 
			
		||||
        it[time] = timestamp
 | 
			
		||||
        it[player] = playerUniqueIdentity
 | 
			
		||||
        it[world] = location.world.uid
 | 
			
		||||
        it[block] = material.storageBlockName
 | 
			
		||||
        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.storageBlockName
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
package cloud.kubelet.foundation.heimdall.event
 | 
			
		||||
 | 
			
		||||
import cloud.kubelet.foundation.heimdall.storageBlockName
 | 
			
		||||
import cloud.kubelet.foundation.heimdall.table.BlockBreakTable
 | 
			
		||||
import cloud.kubelet.foundation.heimdall.table.BlockPlaceTable
 | 
			
		||||
import org.bukkit.Location
 | 
			
		||||
import org.bukkit.Material
 | 
			
		||||
@ -21,13 +22,15 @@ class BlockPlace(
 | 
			
		||||
  override fun store(transaction: Transaction) {
 | 
			
		||||
    transaction.apply {
 | 
			
		||||
      BlockPlaceTable.insert {
 | 
			
		||||
        it[time] = timestamp
 | 
			
		||||
        it[player] = playerUniqueIdentity
 | 
			
		||||
        it[world] = location.world.uid
 | 
			
		||||
        it[block] = material.storageBlockName
 | 
			
		||||
        it[x] = location.x
 | 
			
		||||
        it[y] = location.y
 | 
			
		||||
        it[z] = location.z
 | 
			
		||||
        it[BlockBreakTable.time] = timestamp
 | 
			
		||||
        it[BlockBreakTable.player] = playerUniqueIdentity
 | 
			
		||||
        it[BlockBreakTable.world] = location.world.uid
 | 
			
		||||
        it[BlockBreakTable.x] = location.x
 | 
			
		||||
        it[BlockBreakTable.y] = location.y
 | 
			
		||||
        it[BlockBreakTable.z] = location.z
 | 
			
		||||
        it[BlockBreakTable.pitch] = location.pitch.toDouble()
 | 
			
		||||
        it[BlockBreakTable.yaw] = location.yaw.toDouble()
 | 
			
		||||
        it[BlockBreakTable.block] = material.storageBlockName
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -5,10 +5,12 @@ import org.jetbrains.exposed.sql.javatime.timestamp
 | 
			
		||||
 | 
			
		||||
object BlockBreakTable : Table("block_breaks") {
 | 
			
		||||
  val time = timestamp("time")
 | 
			
		||||
  val world = uuid("world")
 | 
			
		||||
  val player = uuid("player")
 | 
			
		||||
  val block = text("block")
 | 
			
		||||
  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")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,10 +5,12 @@ import org.jetbrains.exposed.sql.javatime.timestamp
 | 
			
		||||
 | 
			
		||||
object BlockPlaceTable : Table("block_places") {
 | 
			
		||||
  val time = timestamp("time")
 | 
			
		||||
  val world = uuid("world")
 | 
			
		||||
  val player = uuid("player")
 | 
			
		||||
  val block = text("block")
 | 
			
		||||
  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")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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")
 | 
			
		||||
}
 | 
			
		||||
@ -5,8 +5,8 @@ import org.jetbrains.exposed.sql.javatime.timestamp
 | 
			
		||||
 | 
			
		||||
object PlayerAdvancementTable : Table("player_advancements") {
 | 
			
		||||
  val time = timestamp("time")
 | 
			
		||||
  val world = uuid("world")
 | 
			
		||||
  val player = uuid("player")
 | 
			
		||||
  val world = uuid("world")
 | 
			
		||||
  val x = double("x")
 | 
			
		||||
  val y = double("y")
 | 
			
		||||
  val z = double("z")
 | 
			
		||||
 | 
			
		||||
@ -5,8 +5,8 @@ import org.jetbrains.exposed.sql.javatime.timestamp
 | 
			
		||||
 | 
			
		||||
object PlayerPositionTable : Table("player_positions") {
 | 
			
		||||
  val time = timestamp("time")
 | 
			
		||||
  val world = uuid("world")
 | 
			
		||||
  val player = uuid("player")
 | 
			
		||||
  val world = uuid("world")
 | 
			
		||||
  val x = double("x")
 | 
			
		||||
  val y = double("y")
 | 
			
		||||
  val z = double("z")
 | 
			
		||||
 | 
			
		||||
@ -23,10 +23,12 @@ create table if not exists heimdall.block_breaks (
 | 
			
		||||
    time timestamp not null,
 | 
			
		||||
    player uuid not null,
 | 
			
		||||
    world uuid not null,
 | 
			
		||||
    block text 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,
 | 
			
		||||
    block text not null,
 | 
			
		||||
    PRIMARY KEY (time, player, world)
 | 
			
		||||
);
 | 
			
		||||
--
 | 
			
		||||
@ -36,10 +38,12 @@ create table if not exists heimdall.block_places (
 | 
			
		||||
    time timestamp not null,
 | 
			
		||||
    player uuid not null,
 | 
			
		||||
    world uuid not null,
 | 
			
		||||
    block text 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,
 | 
			
		||||
    block text not null,
 | 
			
		||||
    PRIMARY KEY (time, player, world)
 | 
			
		||||
);
 | 
			
		||||
--
 | 
			
		||||
@ -93,8 +97,24 @@ create table if not exists heimdall.player_advancements (
 | 
			
		||||
    z double precision not null,
 | 
			
		||||
    pitch double precision not null,
 | 
			
		||||
    yaw double precision not null,
 | 
			
		||||
    advancement text null,
 | 
			
		||||
    advancement text not null,
 | 
			
		||||
    primary key (time, player, advancement)
 | 
			
		||||
);
 | 
			
		||||
--
 | 
			
		||||
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);
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user