From fee2e76cd0ec9ee80608afd3edebea582ba877b9 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Mon, 21 Jul 2025 17:04:51 +0800 Subject: [PATCH] Fix servux hud data (1/3) --- .../servux/ServuxHudDataProtocol.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxHudDataProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxHudDataProtocol.java index 404de7f2..70325ded 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxHudDataProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxHudDataProtocol.java @@ -59,6 +59,11 @@ public class ServuxHudDataProtocol implements LeavesProtocol { } } + @ProtocolHandler.PlayerJoin + private static void onPlayerJoin(ServerPlayer player) { + sendHudMetadata(player); + } + @ProtocolHandler.PlayerLeave private static void onPlayerLeave(ServerPlayer player) { players.remove(player); @@ -70,22 +75,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol { switch (payload.packetType) { case PACKET_C2S_METADATA_REQUEST -> { players.add(player); - - CompoundTag metadata = new CompoundTag(); - metadata.putString("name", "hud_metadata"); - metadata.putString("id", HudDataPayload.CHANNEL.toString()); - metadata.putInt("version", PROTOCOL_VERSION); - metadata.putString("servux", ServuxProtocol.SERVUX_STRING); - if (LeavesConfig.protocol.servux.hudLoggerProtocol) { - CompoundTag nbt = new CompoundTag(); - for (DataLogger.Type type : DataLogger.Type.VALUES) { - nbt.putBoolean(type.getSerializedName(), isLoggerTypeEnabled(type)); - } - metadata.put("Loggers", nbt); - } - putWorldData(metadata); - - sendPacket(player, new HudDataPayload(HudDataPayloadType.PACKET_S2C_METADATA, metadata)); + sendHudMetadata(player); } case PACKET_C2S_SPAWN_DATA_REQUEST -> refreshSpawnMetadata(player); case PACKET_C2S_RECIPE_MANAGER_REQUEST -> refreshRecipeManager(player); @@ -93,6 +83,24 @@ public class ServuxHudDataProtocol implements LeavesProtocol { } } + public static void sendHudMetadata(ServerPlayer player) { + CompoundTag metadata = new CompoundTag(); + metadata.putString("name", "hud_metadata"); + metadata.putString("id", HudDataPayload.CHANNEL.toString()); + metadata.putInt("version", PROTOCOL_VERSION); + metadata.putString("servux", ServuxProtocol.SERVUX_STRING); + if (LeavesConfig.protocol.servux.hudLoggerProtocol) { + CompoundTag nbt = new CompoundTag(); + for (DataLogger.Type type : DataLogger.Type.VALUES) { + nbt.putBoolean(type.getSerializedName(), isLoggerTypeEnabled(type)); + } + metadata.put("Loggers", nbt); + } + putWorldData(metadata); + + sendPacket(player, new HudDataPayload(HudDataPayloadType.PACKET_S2C_METADATA, metadata)); + } + public static void refreshSpawnMetadata(ServerPlayer player) { CompoundTag metadata = new CompoundTag(); metadata.putString("id", HudDataPayload.CHANNEL.toString()); @@ -125,7 +133,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol { public static void refreshWeatherData(ServerPlayer player) { ServerLevel level = MinecraftServer.getServer().overworld(); - if (level.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE)) { + if (!level.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE)) { return; }