From e1f6bfcf0b45ea6c3bc8d347717875cc1d0d6927 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 11 Jul 2024 18:38:52 +0200 Subject: [PATCH] stat --- src/main/java/net/pivipi/Main.java | 8 ++- src/main/java/net/pivipi/Stats.java | 49 +++++++++++++++++++ .../net/pivipi/world/SoccerGenerator.java | 2 +- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/pivipi/Stats.java diff --git a/src/main/java/net/pivipi/Main.java b/src/main/java/net/pivipi/Main.java index 6a412a0..b0f78b8 100644 --- a/src/main/java/net/pivipi/Main.java +++ b/src/main/java/net/pivipi/Main.java @@ -3,6 +3,7 @@ package net.pivipi; import net.minestom.server.MinecraftServer; import net.minestom.server.event.GlobalEventHandler; +import net.minestom.server.extras.velocity.VelocityProxy; import net.minestom.server.instance.InstanceContainer; import net.minestom.server.instance.InstanceManager; import net.minestom.server.instance.LightingChunk; @@ -23,6 +24,7 @@ public class Main { InstanceManager instanceManager = MinecraftServer.getInstanceManager(); GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); + SchedulerManager schedulerManager = MinecraftServer.getSchedulerManager(); Key dimension = FancyDimension.create(); InstanceContainer instanceContainer = instanceManager.createInstanceContainer(dimension); @@ -36,14 +38,16 @@ public class Main { WorldConstraints worldConstraints = new WorldConstraints(); worldConstraints.setup(globalEventHandler); + + new Stats(instanceManager).start(schedulerManager); /* done */ MinecraftServer.setCompressionThreshold(0); MinecraftServer.setBrandName("PiViPi"); - minecraftServer.start("0.0.0.0", 25565); - System.out.println("started"); + minecraftServer.start("127.0.0.1", 25565); + System.out.println("Listening on port 25565"); } } \ No newline at end of file diff --git a/src/main/java/net/pivipi/Stats.java b/src/main/java/net/pivipi/Stats.java new file mode 100644 index 0000000..ad1a080 --- /dev/null +++ b/src/main/java/net/pivipi/Stats.java @@ -0,0 +1,49 @@ +package net.pivipi; + +import java.time.Duration; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentBuilder; +import net.minestom.server.MinecraftServer; +import net.minestom.server.instance.Instance; +import net.minestom.server.instance.InstanceManager; +import net.minestom.server.monitoring.BenchmarkManager; +import net.minestom.server.network.packet.server.play.DeclareRecipesPacket.Ingredient; +import net.minestom.server.timer.SchedulerManager; +import net.minestom.server.timer.TaskSchedule; + +public class Stats implements Runnable { + private int tickDelay = 10; + private InstanceManager instanceManager; + private BenchmarkManager benchmarkManager; + + private long lastRun; + + public Stats(InstanceManager instanceManager) { + this.instanceManager = instanceManager; + } + + public void start(SchedulerManager schedulerManager) { + this.benchmarkManager = MinecraftServer.getBenchmarkManager(); + schedulerManager.scheduleTask(this, TaskSchedule.immediate(), TaskSchedule.tick(tickDelay)); + } + + @Override + public void run() { + long now = System.currentTimeMillis(); + long delay = now - lastRun; + lastRun = now; + + double mspt = (double)delay / tickDelay; + double tps = 1000 / mspt; + long mem = benchmarkManager.getUsedMemory() / 1024 / 1024; + + Component footer = Component.text("MSPT: %f | TPS: %f | Mem: %dMB".formatted(mspt, tps, mem)).appendNewline().append(benchmarkManager.getCpuMonitoringMessage()); + + instanceManager.getInstances().forEach(instance -> { + instance.getPlayers().forEach(player -> { + player.sendPlayerListFooter(footer); + }); + }); + } +} diff --git a/src/main/java/net/pivipi/world/SoccerGenerator.java b/src/main/java/net/pivipi/world/SoccerGenerator.java index d751a9a..062cc9c 100644 --- a/src/main/java/net/pivipi/world/SoccerGenerator.java +++ b/src/main/java/net/pivipi/world/SoccerGenerator.java @@ -14,7 +14,7 @@ public class SoccerGenerator implements Generator { public void generate(@NotNull GenerationUnit unit) { UnitModifier modifier = unit.modifier(); - modifier.fillBiome(Biome.CRIMSON_FOREST); + modifier.fillBiome(Biome.PLAINS); modifier.fillHeight(63, 64, Block.WHITE_WOOL); modifier.fill(unit.absoluteStart().withY(63).add(1, 0, 1), unit.absoluteEnd().withY(64), Block.GREEN_CONCRETE_POWDER);