diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 203b8e71d..b13b202cc 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -444,7 +444,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, setOnFire(false); refreshHealth(); sendPacket(new RespawnPacket(getDimensionType().toString(), getDimensionType().getName().asString(), - 0, gameMode, gameMode, false, levelFlat, true)); + 0, gameMode, gameMode, false, levelFlat, true)); PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(this); EventDispatcher.call(respawnEvent); @@ -932,9 +932,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, */ public void setDisplayName(@Nullable Component displayName) { this.displayName = displayName; - // TODO - //PacketUtils.broadcastPacket(new PlayerInfoPacket(PlayerInfoPacket.Action.UPDATE_DISPLAY_NAME, - // new PlayerInfoPacket.UpdateDisplayName(getUuid(), displayName))); + PacketUtils.broadcastPacket(new PlayerInfoUpdatePacket(PlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME, infoEntry())); } /** @@ -1289,9 +1287,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, // Condition to prevent sending the packets before spawning the player if (isActive()) { sendPacket(new ChangeGameStatePacket(ChangeGameStatePacket.Reason.CHANGE_GAMEMODE, gameMode.id())); - // TODO - //PacketUtils.broadcastPacket(new PlayerInfoPacket(PlayerInfoPacket.Action.UPDATE_GAMEMODE, - // new PlayerInfoPacket.UpdateGameMode(getUuid(), gameMode))); + PacketUtils.broadcastPacket(new PlayerInfoUpdatePacket(PlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE, infoEntry())); } // The client updates their abilities based on the GameMode as follows @@ -1791,9 +1787,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, */ public void refreshLatency(int latency) { this.latency = latency; - // TODO - //PacketUtils.broadcastPacket(new PlayerInfoPacket(PlayerInfoPacket.Action.UPDATE_LATENCY, - // new PlayerInfoPacket.UpdateLatency(getUuid(), latency))); + PacketUtils.broadcastPacket(new PlayerInfoUpdatePacket(PlayerInfoUpdatePacket.Action.UPDATE_LATENCY, infoEntry())); } public void refreshOnGround(boolean onGround) { @@ -1914,13 +1908,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable, * @return a {@link PlayerInfoUpdatePacket} to add the player */ protected @NotNull PlayerInfoUpdatePacket getAddPlayerToList() { - final PlayerSkin skin = this.skin; - List prop = skin != null ? - List.of(new PlayerInfoUpdatePacket.Property("textures", skin.textures(), skin.signature())) : - List.of(); return new PlayerInfoUpdatePacket(EnumSet.of(PlayerInfoUpdatePacket.Action.ADD_PLAYER, PlayerInfoUpdatePacket.Action.UPDATE_LISTED), - List.of(new PlayerInfoUpdatePacket.Entry(getUuid(), getUsername(), prop, - true, getLatency(), getGameMode(), displayName))); + List.of(infoEntry())); } /** @@ -1932,6 +1921,15 @@ public class Player extends LivingEntity implements CommandSender, Localizable, return new PlayerInfoRemovePacket(List.of(getUuid())); } + private PlayerInfoUpdatePacket.Entry infoEntry() { + final PlayerSkin skin = this.skin; + List prop = skin != null ? + List.of(new PlayerInfoUpdatePacket.Property("textures", skin.textures(), skin.signature())) : + List.of(); + return new PlayerInfoUpdatePacket.Entry(getUuid(), getUsername(), prop, + true, getLatency(), getGameMode(), displayName); + } + /** * Sends all the related packet to have the player sent to another with related data * (create player, spawn position, velocity, metadata, equipments, passengers, team). diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoUpdatePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoUpdatePacket.java index 589e91240..afed22153 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoUpdatePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoUpdatePacket.java @@ -16,6 +16,10 @@ import static net.minestom.server.network.NetworkBuffer.*; public record PlayerInfoUpdatePacket(@NotNull EnumSet<@NotNull Action> actions, @NotNull List<@NotNull Entry> entries) implements ServerPacket { + public PlayerInfoUpdatePacket(@NotNull Action action, @NotNull Entry entry) { + this(EnumSet.of(action), List.of(entry)); + } + public PlayerInfoUpdatePacket { actions = EnumSet.copyOf(actions); entries = List.copyOf(entries); @@ -47,7 +51,7 @@ public record PlayerInfoUpdatePacket(@NotNull EnumSet<@NotNull Action> actions, public record Property(@NotNull String name, @NotNull String value, @Nullable String signature) implements NetworkBuffer.Writer { - public Property(String name, String value) { + public Property(@NotNull String name, @NotNull String value) { this(name, value, null); }