From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Flo0 Date: Sat, 6 Apr 2024 23:15:24 +0200 Subject: [PATCH] Add listing API for PlayerProfile diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java index 56eddd28429cf42c02d88b8bf79f8b616fa45289..ba3dde833e073a9979af5b3554f669b9ec0ccf7e 100644 --- a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java +++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java @@ -16,6 +16,7 @@ import net.minecraft.network.protocol.Packet; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.GameType; + public class ClientboundPlayerInfoUpdatePacket implements Packet { private final EnumSet actions; private final List entries; @@ -68,6 +69,35 @@ public class ClientboundPlayerInfoUpdatePacket implements Packet enumSet = EnumSet.of( + ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, + ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED, + ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY, + ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE + ); + + if(displayName != null) { + enumSet.add(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME); + } + + UUID profileId = profile.getId(); + return new ClientboundPlayerInfoUpdatePacket(enumSet, new ClientboundPlayerInfoUpdatePacket.Entry(profileId, profile, true, latency, gameMode, displayName, null)); + } + public static ClientboundPlayerInfoUpdatePacket updateLatency(UUID playerInfoId, int latency) { + EnumSet enumSet = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY); + return new ClientboundPlayerInfoUpdatePacket(enumSet, new ClientboundPlayerInfoUpdatePacket.Entry(playerInfoId, true, latency, GameType.DEFAULT_MODE, null)); + } + public static ClientboundPlayerInfoUpdatePacket updateGameMode(UUID playerInfoId, GameType gameMode) { + EnumSet enumSet = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE); + return new ClientboundPlayerInfoUpdatePacket(enumSet, new ClientboundPlayerInfoUpdatePacket.Entry(playerInfoId, true, 0, gameMode, null)); + } + public static ClientboundPlayerInfoUpdatePacket updateDisplayName(UUID playerInfoId, Component displayName) { + EnumSet enumSet = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME); + return new ClientboundPlayerInfoUpdatePacket(enumSet, new ClientboundPlayerInfoUpdatePacket.Entry(playerInfoId, true, 0, GameType.DEFAULT_MODE, displayName)); + } + // Paper end - Add Listing API for PlayerProfile public ClientboundPlayerInfoUpdatePacket(FriendlyByteBuf buf) { this.actions = buf.readEnumSet(ClientboundPlayerInfoUpdatePacket.Action.class); @@ -188,6 +218,11 @@ public class ClientboundPlayerInfoUpdatePacket implements Packet serialize() { Map result = new LinkedHashMap();