mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-06 15:01:32 +00:00
Heimdall: It's back!
This commit is contained in:
11
foundation-heimdall/src/main/resources/heimdall.yaml
Normal file
11
foundation-heimdall/src/main/resources/heimdall.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
# Whether Heimdall should be enabled for tracking events.
|
||||
enabled: false
|
||||
|
||||
# Database connection information.
|
||||
db:
|
||||
# JDBC URL
|
||||
url: "jdbc:postgresql://localhost/heimdall"
|
||||
# JDBC Username
|
||||
username: "heimdall"
|
||||
# JDBC Password
|
||||
password: "heimdall"
|
147
foundation-heimdall/src/main/resources/init.sql
Normal file
147
foundation-heimdall/src/main/resources/init.sql
Normal file
@ -0,0 +1,147 @@
|
||||
create extension if not exists "uuid-ossp";
|
||||
--
|
||||
create extension if not exists timescaledb;
|
||||
--
|
||||
create schema if not exists heimdall;
|
||||
--
|
||||
create table if not exists player_positions (
|
||||
time timestamp not null,
|
||||
player 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,
|
||||
PRIMARY KEY (time, player, world)
|
||||
);
|
||||
--
|
||||
select create_hypertable('player_positions', 'time', 'player', 4, if_not_exists => TRUE);
|
||||
--
|
||||
alter table player_positions set (
|
||||
timescaledb.compress,
|
||||
timescaledb.compress_segmentby = 'player,world',
|
||||
timescaledb.compress_orderby = 'time'
|
||||
);
|
||||
--
|
||||
select add_compression_policy('player_positions', interval '3 days', if_not_exists => true);
|
||||
--
|
||||
create table if not exists block_breaks (
|
||||
time timestamp not null,
|
||||
player 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,
|
||||
block text not null,
|
||||
PRIMARY KEY (time, player, world)
|
||||
);
|
||||
--
|
||||
select create_hypertable('block_breaks', 'time', 'player', 4, if_not_exists => TRUE);
|
||||
--
|
||||
create table if not exists block_places (
|
||||
time timestamp not null,
|
||||
player 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,
|
||||
block text not null,
|
||||
PRIMARY KEY (time, player, world)
|
||||
);
|
||||
--
|
||||
select create_hypertable('block_places', 'time', 'player', 4, if_not_exists => TRUE);
|
||||
--
|
||||
create table if not exists player_sessions (
|
||||
id uuid not null,
|
||||
player uuid not null,
|
||||
name text not null,
|
||||
"start" timestamp not null,
|
||||
"end" timestamp not null,
|
||||
primary key (id, player, start)
|
||||
);
|
||||
--
|
||||
select create_hypertable('player_sessions', 'start', 'player', 4, if_not_exists => TRUE);
|
||||
--
|
||||
create table if not exists 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,
|
||||
primary key (time, player)
|
||||
);
|
||||
--
|
||||
select create_hypertable('world_changes', 'time', 'player', 4, if_not_exists => TRUE);
|
||||
--
|
||||
create table if not exists player_deaths (
|
||||
time timestamp not null,
|
||||
player 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,
|
||||
experience double precision not null,
|
||||
message text null,
|
||||
primary key (time, player)
|
||||
);
|
||||
--
|
||||
select create_hypertable('player_deaths', 'time', 'player', 4, if_not_exists => TRUE);
|
||||
--
|
||||
create table if not exists player_advancements (
|
||||
time timestamp not null,
|
||||
player 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,
|
||||
advancement text not null,
|
||||
primary key (time, player, advancement)
|
||||
);
|
||||
--
|
||||
select create_hypertable('player_advancements', 'time', 'player', 4, if_not_exists => TRUE);
|
||||
--
|
||||
create table if not exists 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('entity_kills', 'time', 'player', 4, if_not_exists => TRUE);
|
||||
--
|
||||
create or replace view block_changes as
|
||||
select true as break, *
|
||||
from block_breaks
|
||||
union all
|
||||
select false as break, * from block_places;
|
||||
--
|
||||
create or replace view player_names as
|
||||
with unique_player_ids as (
|
||||
select distinct player
|
||||
from player_sessions
|
||||
)
|
||||
select player, (
|
||||
select name
|
||||
from player_sessions
|
||||
where player = unique_player_ids.player
|
||||
order by "end" desc
|
||||
limit 1
|
||||
) as name
|
||||
from unique_player_ids;
|
13
foundation-heimdall/src/main/resources/plugin.yml
Normal file
13
foundation-heimdall/src/main/resources/plugin.yml
Normal file
@ -0,0 +1,13 @@
|
||||
name: Heimdall
|
||||
version: '${version}'
|
||||
main: io.kexec.heimdall.plugin.HeimdallPlugin
|
||||
api-version: 1.18
|
||||
prefix: Heimdall
|
||||
load: STARTUP
|
||||
authors:
|
||||
- kendfinger
|
||||
commands:
|
||||
export_all_chunks:
|
||||
description: Export All Chunks
|
||||
usage: /export_all_chunks
|
||||
permission: heimdall.command.export_all_chunks
|
@ -0,0 +1,64 @@
|
||||
WITH
|
||||
unique_player_ids AS (
|
||||
SELECT
|
||||
DISTINCT player
|
||||
FROM player_sessions
|
||||
),
|
||||
player_names AS (
|
||||
SELECT
|
||||
player,
|
||||
(
|
||||
SELECT name
|
||||
FROM player_sessions
|
||||
WHERE player = unique_player_ids.player
|
||||
ORDER BY "end" DESC
|
||||
LIMIT 1
|
||||
) AS name
|
||||
FROM unique_player_ids
|
||||
),
|
||||
unique_world_ids AS (
|
||||
SELECT
|
||||
DISTINCT to_world AS world
|
||||
FROM world_changes
|
||||
),
|
||||
world_names AS (
|
||||
SELECT
|
||||
world,
|
||||
(
|
||||
SELECT to_world_name
|
||||
FROM world_changes
|
||||
WHERE world = world_changes.to_world
|
||||
ORDER BY time DESC
|
||||
LIMIT 1
|
||||
) AS name
|
||||
FROM unique_world_ids
|
||||
),
|
||||
player_calculated_positions AS (
|
||||
SELECT
|
||||
player,
|
||||
world,
|
||||
AVG(x) AS avg_x,
|
||||
AVG(y) AS avg_y,
|
||||
AVG(z) AS avg_z,
|
||||
MAX(x) AS max_x,
|
||||
MAX(y) AS max_y,
|
||||
MAX(z) AS max_z,
|
||||
MIN(x) AS min_x,
|
||||
MIN(y) AS min_y,
|
||||
MIN(z) AS min_z,
|
||||
COUNT(*) AS count,
|
||||
MODE() WITHIN GROUP (ORDER BY x) AS mode_x,
|
||||
MODE() WITHIN GROUP (ORDER BY y) AS mode_y,
|
||||
MODE() WITHIN GROUP (ORDER BY z) AS mode_z
|
||||
FROM player_positions
|
||||
GROUP BY player, world
|
||||
)
|
||||
SELECT
|
||||
player_names.name AS player_name,
|
||||
world_names.name AS world_name,
|
||||
player_calculated_positions.*
|
||||
FROM player_calculated_positions
|
||||
JOIN player_names
|
||||
ON player_names.player = player_calculated_positions.player
|
||||
JOIN world_names
|
||||
ON world_names.world = player_calculated_positions.world
|
Reference in New Issue
Block a user