From 6b644d613038a9aef462c54d65344dfb86ecaa13 Mon Sep 17 00:00:00 2001 From: themode Date: Fri, 26 Mar 2021 20:10:42 +0100 Subject: [PATCH] Fix BenchmarkManager not returning a Component --- .../minestom/server/benchmark/BenchmarkManager.java | 4 ++-- src/test/java/demo/PlayerInit.java | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/minestom/server/benchmark/BenchmarkManager.java b/src/main/java/net/minestom/server/benchmark/BenchmarkManager.java index 906c26e62..41bf61dd3 100644 --- a/src/main/java/net/minestom/server/benchmark/BenchmarkManager.java +++ b/src/main/java/net/minestom/server/benchmark/BenchmarkManager.java @@ -107,7 +107,7 @@ public final class BenchmarkManager { } @NotNull - public String getCpuMonitoringMessage() { + public Component getCpuMonitoringMessage() { Check.stateCondition(!enabled, "CPU monitoring is only possible when the benchmark manager is enabled."); TextComponent.Builder benchmarkMessage = Component.text(); for (Map.Entry resultEntry : resultMap.entrySet()) { @@ -127,7 +127,7 @@ public final class BenchmarkManager { benchmarkMessage.append(Component.newline()); } - return AdventureSerializer.serialize(benchmarkMessage.build()); + return benchmarkMessage.build(); } private void refreshData() { diff --git a/src/test/java/demo/PlayerInit.java b/src/test/java/demo/PlayerInit.java index b8e1fb779..6c64eeebf 100644 --- a/src/test/java/demo/PlayerInit.java +++ b/src/test/java/demo/PlayerInit.java @@ -4,6 +4,7 @@ import demo.generator.ChunkGeneratorDemo; import demo.generator.NoiseTestGenerator; import net.kyori.adventure.text.Component; import net.minestom.server.MinecraftServer; +import net.minestom.server.adventure.audience.Audiences; import net.minestom.server.benchmark.BenchmarkManager; import net.minestom.server.chat.ColoredText; import net.minestom.server.entity.Entity; @@ -28,9 +29,7 @@ import net.minestom.server.inventory.PlayerInventory; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; import net.minestom.server.network.ConnectionManager; -import net.minestom.server.network.packet.server.play.PlayerListHeaderAndFooterPacket; import net.minestom.server.ping.ResponseDataConsumer; -import net.minestom.server.utils.PacketUtils; import net.minestom.server.utils.Position; import net.minestom.server.utils.Vector; import net.minestom.server.utils.inventory.PlayerInventoryUtils; @@ -80,13 +79,8 @@ public class PlayerInit { ramUsage /= 1e6; // bytes to MB final Component header = Component.text("RAM USAGE: " + ramUsage + " MB"); - final Component footer = Component.text(benchmarkManager.getCpuMonitoringMessage()); - - { - PlayerListHeaderAndFooterPacket playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket(header, footer); - - PacketUtils.sendGroupedPacket(players, playerListHeaderAndFooterPacket); - } + final Component footer = benchmarkManager.getCpuMonitoringMessage(); + Audiences.audiences().players().sendPlayerListHeaderAndFooter(header, footer); }).repeat(10, TimeUnit.TICK).schedule();