mirror of
https://github.com/ceratic/project_vollidioten_mod.git
synced 2026-05-14 00:16:47 +02:00
enhance player data logging with detailed statistics collection
This commit is contained in:
@@ -9,8 +9,14 @@ import net.minecraft.advancement.PlayerAdvancementTracker;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.stat.Stat;
|
||||
import net.minecraft.stat.Stats;
|
||||
import net.minecraft.stat.StatType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import net.minecraft.entity.EntityType;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
@@ -47,16 +53,61 @@ public class PlayerDataLogger {
|
||||
stats.addProperty("maxHealth", player.getMaxHealth());
|
||||
stats.addProperty("foodLevel", player.getHungerManager().getFoodLevel());
|
||||
stats.addProperty("xpLevel", player.experienceLevel);
|
||||
stats.addProperty("gameMode", player.interactionManager.getGameMode().asString());
|
||||
|
||||
|
||||
JsonObject position = new JsonObject();
|
||||
position.addProperty("x", player.getX());
|
||||
position.addProperty("y", player.getY());
|
||||
position.addProperty("z", player.getZ());
|
||||
//position.addProperty("dimension", player.getWorld().getRegistryKey().getValue().toString());
|
||||
stats.add("position", position);
|
||||
|
||||
payload.add("stats", stats);
|
||||
payload.add("char", stats);
|
||||
|
||||
|
||||
// 3. Statistics (Kills, Deaths, Killed By, etc.)
|
||||
// We iterate over all registered StatTypes to get every possible stat
|
||||
|
||||
|
||||
|
||||
|
||||
// 3. Statistics (General, Kills, Killed By)
|
||||
// Only collect heavy stats on Join/Leave to save bandwidth, or if specifically requested
|
||||
JsonObject statsObj = new JsonObject();
|
||||
|
||||
// General Stats (Jumps, Play time, etc.)
|
||||
JsonObject generalStats = new JsonObject();
|
||||
Registries.CUSTOM_STAT.forEach(stat -> {
|
||||
int value = player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(stat));
|
||||
if (value > 0) {
|
||||
generalStats.addProperty(Registries.CUSTOM_STAT.getId(stat).toString(), value);
|
||||
}
|
||||
});
|
||||
statsObj.add("general", generalStats);
|
||||
|
||||
// Mob Kills
|
||||
JsonObject killsStats = new JsonObject();
|
||||
Registries.ENTITY_TYPE.forEach(entityType -> {
|
||||
int value = player.getStatHandler().getStat(Stats.KILLED.getOrCreateStat(entityType));
|
||||
if (value > 0) {
|
||||
killsStats.addProperty(EntityType.getId(entityType).toString(), value);
|
||||
}
|
||||
});
|
||||
statsObj.add("kills", killsStats);
|
||||
|
||||
// Killed By
|
||||
JsonObject killedByStats = new JsonObject();
|
||||
Registries.ENTITY_TYPE.forEach(entityType -> {
|
||||
int value = player.getStatHandler().getStat(Stats.KILLED_BY.getOrCreateStat(entityType));
|
||||
if (value > 0) {
|
||||
killedByStats.addProperty(EntityType.getId(entityType).toString(), value);
|
||||
}
|
||||
});
|
||||
statsObj.add("killed_by", killedByStats);
|
||||
|
||||
payload.add("statistics", statsObj);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Advancements (Only completed ones with a display)
|
||||
JsonArray advancementsArray = new JsonArray();
|
||||
@@ -104,4 +155,5 @@ public class PlayerDataLogger {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user