From cd23975d62b24ba08738c7e513ca27baefb71a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noel=20N=C3=A9meth?= Date: Sun, 19 Jun 2022 01:26:52 +0200 Subject: [PATCH] Use nullable methods --- .../packet/server/play/PlayerInfoPacket.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoPacket.java index 767a63e47..a1c18a938 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoPacket.java @@ -139,7 +139,7 @@ public record PlayerInfoPacket(@NotNull Action action, this(uuid, reader.readSizedString(), reader.readVarIntList(Property::new), GameMode.values()[reader.readVarInt()], reader.readVarInt(), - reader.readBoolean() ? reader.readComponent() : null, reader.readBoolean() ? new PlayerPublicKey(reader) : null); + reader.readNullableComponent(), reader.readNullable(() -> new PlayerPublicKey(reader))); } @Override @@ -148,8 +148,7 @@ public record PlayerInfoPacket(@NotNull Action action, writer.writeVarIntList(properties, BinaryWriter::write); writer.writeVarInt(gameMode.id()); writer.writeVarInt(ping); - writer.writeBoolean(displayName != null); - if (displayName != null) writer.writeComponent(displayName); + writer.writeNullableComponent(displayName); writer.writeNullable(playerPublicKey); } @@ -171,16 +170,14 @@ public record PlayerInfoPacket(@NotNull Action action, } public Property(BinaryReader reader) { - this(reader.readSizedString(), reader.readSizedString(), - reader.readBoolean() ? reader.readSizedString() : null); + this(reader.readSizedString(), reader.readSizedString(), reader.readNullableSizedString()); } @Override public void write(BinaryWriter writer) { writer.writeSizedString(name); writer.writeSizedString(value); - writer.writeBoolean(signature != null); - if (signature != null) writer.writeSizedString(signature); + writer.writeNullableSizedString(signature); } } } @@ -210,13 +207,12 @@ public record PlayerInfoPacket(@NotNull Action action, public record UpdateDisplayName(@NotNull UUID uuid, @Nullable Component displayName) implements Entry, ComponentHolder { public UpdateDisplayName(UUID uuid, BinaryReader reader) { - this(uuid, reader.readBoolean() ? reader.readComponent() : null); + this(uuid, reader.readNullableComponent()); } @Override public void write(BinaryWriter writer) { - writer.writeBoolean(displayName != null); - if (displayName != null) writer.writeComponent(displayName); + writer.writeNullableComponent(displayName); } @Override