mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 13:10:55 +00:00
Heimdall: Implement world change events.
This commit is contained in:
parent
4017c3cb8c
commit
b2851d13b9
@ -4,19 +4,16 @@ import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||
import cloud.kubelet.foundation.core.Util
|
||||
import cloud.kubelet.foundation.heimdall.buffer.BufferFlushThread
|
||||
import cloud.kubelet.foundation.heimdall.buffer.EventBuffer
|
||||
import cloud.kubelet.foundation.heimdall.event.BlockBreak
|
||||
import cloud.kubelet.foundation.heimdall.event.BlockPlace
|
||||
import cloud.kubelet.foundation.heimdall.event.PlayerPosition
|
||||
import cloud.kubelet.foundation.heimdall.event.PlayerSession
|
||||
import cloud.kubelet.foundation.heimdall.event.*
|
||||
import cloud.kubelet.foundation.heimdall.model.HeimdallConfig
|
||||
import com.charleskorn.kaml.Yaml
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.BlockBreakEvent
|
||||
import org.bukkit.event.block.BlockPlaceEvent
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
import org.bukkit.event.player.PlayerMoveEvent
|
||||
import org.bukkit.event.player.PlayerQuitEvent
|
||||
@ -103,13 +100,26 @@ class FoundationHeimdallPlugin : JavaPlugin(), Listener {
|
||||
playerJoinTimes[event.player.uniqueId] = Instant.now()
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler
|
||||
fun onPlayerQuit(event: PlayerQuitEvent) {
|
||||
val startTime = playerJoinTimes.remove(event.player.uniqueId) ?: return
|
||||
val endTime = Instant.now()
|
||||
buffer.push(PlayerSession(event.player.uniqueId, event.player.name, startTime, endTime))
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onWorldLoad(event: PlayerChangedWorldEvent) {
|
||||
buffer.push(
|
||||
WorldChange(
|
||||
event.player.uniqueId,
|
||||
event.from.uid,
|
||||
event.from.name,
|
||||
event.player.world.uid,
|
||||
event.player.world.name
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
bufferFlushThread.stop()
|
||||
val endTime = Instant.now()
|
||||
|
@ -0,0 +1,29 @@
|
||||
package cloud.kubelet.foundation.heimdall.event
|
||||
|
||||
import cloud.kubelet.foundation.heimdall.table.WorldChangeTable
|
||||
import org.jetbrains.exposed.sql.Transaction
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
|
||||
class WorldChange(
|
||||
val playerUniqueIdentity: UUID,
|
||||
val fromWorldId: UUID,
|
||||
val fromWorldActualName: String,
|
||||
val toWorldId: UUID,
|
||||
val toWorldActualName: String,
|
||||
val timestamp: Instant = Instant.now()
|
||||
) : HeimdallEvent() {
|
||||
override fun store(transaction: Transaction) {
|
||||
transaction.apply {
|
||||
WorldChangeTable.insert {
|
||||
it[time] = timestamp
|
||||
it[player] = playerUniqueIdentity
|
||||
it[fromWorld] = fromWorldId
|
||||
it[fromWorldName] = fromWorldActualName
|
||||
it[toWorld] = toWorldId
|
||||
it[toWorldName] = toWorldActualName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cloud.kubelet.foundation.heimdall.table
|
||||
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.javatime.timestamp
|
||||
|
||||
object WorldChangeTable : Table("world_changes") {
|
||||
val time = timestamp("time")
|
||||
val player = uuid("player")
|
||||
val fromWorld = uuid("from_world")
|
||||
val toWorld = uuid("to_world")
|
||||
val fromWorldName = text("from_world_name")
|
||||
val toWorldName = text("to_world_name")
|
||||
}
|
@ -55,3 +55,14 @@ create table if not exists heimdall.player_sessions (
|
||||
);
|
||||
--
|
||||
select create_hypertable('heimdall.player_sessions', 'start', 'player', 4, if_not_exists => TRUE);
|
||||
--
|
||||
create table if not exists heimdall.world_changes (
|
||||
time timestamp not null,
|
||||
player uuid not null,
|
||||
from_world uuid not null,
|
||||
from_world_name text not null,
|
||||
to_world uuid not null,
|
||||
to_world_name text not null
|
||||
);
|
||||
--
|
||||
select create_hypertable('heimdall.world_changes', 'time', 'player', 4, if_not_exists => TRUE);
|
||||
|
Loading…
Reference in New Issue
Block a user