feat: track entity kills by player
Build / build (push) Successful in 1m45s

This commit is contained in:
dmg
2026-01-27 22:41:32 -05:00
parent dc539e83d1
commit aca7a81ad3
3 changed files with 32 additions and 0 deletions
@@ -51,6 +51,7 @@ public final class MetricsRegistry {
private final ConcurrentHashMap<String, LongAdder> commandsBlocked = new ConcurrentHashMap<>();
private final ConcurrentHashMap<LabelPair, LongAdder> commandsExecuted = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, LongAdder> itemsCraftedByMaterial = new ConcurrentHashMap<>();
private final ConcurrentHashMap<LabelPair, LongAdder> entityKills = new ConcurrentHashMap<>();
public MetricsRegistry(Server server, boolean enableJvm, boolean enableProcess) {
this.server = server;
@@ -133,6 +134,12 @@ public final class MetricsRegistry {
incrementLabeledCounter(itemsCraftedByMaterial, material.name());
}
public void incrementEntityKill(EntityType entityType, String killer) {
String normalizedEntity = normalizeLabel(entityType.name());
String normalizedKiller = normalizeLabel(killer);
entityKills.computeIfAbsent(new LabelPair(normalizedEntity, normalizedKiller), key -> new LongAdder()).increment();
}
public void refreshEntitySnapshots() {
Map<String, Long> entityCounts = new HashMap<>();
Map<String, Long> tileCounts = new HashMap<>();
@@ -184,6 +191,7 @@ public final class MetricsRegistry {
appendLabeledCounterAdder(builder, "spigot_commands_blocked_total", "Blocked commands by name", "command", commandsBlocked);
appendLabeledCounterAdder(builder, "spigot_commands_executed_total", "Commands executed by source", "command", "source", commandsExecuted);
appendLabeledCounterAdder(builder, "spigot_items_crafted_total", "Items crafted by material", "material", itemsCraftedByMaterial);
appendLabeledCounterAdder(builder, "spigot_entities_killed_total", "Entities killed by player", "entity", "killer", entityKills);
appendGauge(builder, "spigot_players_online", "Online player count", server.getOnlinePlayers().size());
appendGauge(builder, "spigot_players_max", "Max player slots", server.getMaxPlayers());