9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00

Fix servux hud data (1/3)

This commit is contained in:
violetc
2025-07-21 17:04:51 +08:00
parent 7cf5f57d5a
commit fee2e76cd0

View File

@@ -59,6 +59,11 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
} }
} }
@ProtocolHandler.PlayerJoin
private static void onPlayerJoin(ServerPlayer player) {
sendHudMetadata(player);
}
@ProtocolHandler.PlayerLeave @ProtocolHandler.PlayerLeave
private static void onPlayerLeave(ServerPlayer player) { private static void onPlayerLeave(ServerPlayer player) {
players.remove(player); players.remove(player);
@@ -70,22 +75,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
switch (payload.packetType) { switch (payload.packetType) {
case PACKET_C2S_METADATA_REQUEST -> { case PACKET_C2S_METADATA_REQUEST -> {
players.add(player); players.add(player);
sendHudMetadata(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));
} }
case PACKET_C2S_SPAWN_DATA_REQUEST -> refreshSpawnMetadata(player); case PACKET_C2S_SPAWN_DATA_REQUEST -> refreshSpawnMetadata(player);
case PACKET_C2S_RECIPE_MANAGER_REQUEST -> refreshRecipeManager(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) { public static void refreshSpawnMetadata(ServerPlayer player) {
CompoundTag metadata = new CompoundTag(); CompoundTag metadata = new CompoundTag();
metadata.putString("id", HudDataPayload.CHANNEL.toString()); metadata.putString("id", HudDataPayload.CHANNEL.toString());
@@ -125,7 +133,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
public static void refreshWeatherData(ServerPlayer player) { public static void refreshWeatherData(ServerPlayer player) {
ServerLevel level = MinecraftServer.getServer().overworld(); ServerLevel level = MinecraftServer.getServer().overworld();
if (level.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE)) { if (!level.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE)) {
return; return;
} }