Fix info update

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-12-07 18:10:31 +01:00
parent 7ba55fdfef
commit 1a606285c0
2 changed files with 19 additions and 17 deletions

View File

@ -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<PlayerInfoUpdatePacket.Property> 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<PlayerInfoUpdatePacket.Property> 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).

View File

@ -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);
}