From 47045252e5b1159b5ca4073fd6ea54cdf4fef444 Mon Sep 17 00:00:00 2001 From: themode Date: Fri, 13 Nov 2020 09:17:53 +0100 Subject: [PATCH] PacketUtils comment --- .../minestom/server/network/netty/NettyServer.java | 6 +++--- .../net/minestom/server/utils/PacketUtils.java | 14 +++++++++++--- .../minestom/server/utils/binary/BinaryReader.java | 3 ++- .../minestom/server/utils/binary/BinaryWriter.java | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/minestom/server/network/netty/NettyServer.java b/src/main/java/net/minestom/server/network/netty/NettyServer.java index 6ca8ce4a3..d4314ef80 100644 --- a/src/main/java/net/minestom/server/network/netty/NettyServer.java +++ b/src/main/java/net/minestom/server/network/netty/NettyServer.java @@ -52,9 +52,9 @@ public class NettyServer { channel = NioServerSocketChannel.class; } - bootstrap = new ServerBootstrap(); - bootstrap.group(boss, worker); - bootstrap.channel(channel); + bootstrap = new ServerBootstrap() + .group(boss, worker) + .channel(channel); bootstrap.childHandler(new ChannelInitializer() { protected void initChannel(@NotNull SocketChannel ch) { diff --git a/src/main/java/net/minestom/server/utils/PacketUtils.java b/src/main/java/net/minestom/server/utils/PacketUtils.java index d0ebab32e..91a764282 100644 --- a/src/main/java/net/minestom/server/utils/PacketUtils.java +++ b/src/main/java/net/minestom/server/utils/PacketUtils.java @@ -10,7 +10,8 @@ import org.jetbrains.annotations.NotNull; import java.util.Collection; /** - * Class used to write packets. + * Utils class for packets. Including writing a {@link ServerPacket} into a {@link ByteBuf} + * for network processing. */ public final class PacketUtils { @@ -18,7 +19,15 @@ public final class PacketUtils { } - public static void sendGroupedPacket(Collection players, ServerPacket packet) { + /** + * Sends a {@link ServerPacket} to multiple players. Mostly used for convenience. + *

+ * Be aware that this will cause the send packet listeners to be given the exact same packet object. + * + * @param players the players to send the packet to + * @param packet the packet to send to the players + */ + public static void sendGroupedPacket(@NotNull Collection players, @NotNull ServerPacket packet) { for (Player player : players) { player.getPlayerConnection().sendPacket(packet); } @@ -31,7 +40,6 @@ public final class PacketUtils { * @param packet the packet to write into {@code buf} */ public static void writePacket(@NotNull ByteBuf buf, @NotNull ServerPacket packet) { - final ByteBuf packetBuffer = getPacketBuffer(packet); writePacket(buf, packetBuffer, packet.getId()); diff --git a/src/main/java/net/minestom/server/utils/binary/BinaryReader.java b/src/main/java/net/minestom/server/utils/binary/BinaryReader.java index eb3f62b08..d4ba4711b 100644 --- a/src/main/java/net/minestom/server/utils/binary/BinaryReader.java +++ b/src/main/java/net/minestom/server/utils/binary/BinaryReader.java @@ -11,6 +11,7 @@ import net.minestom.server.utils.NBTUtils; import net.minestom.server.utils.SerializerUtils; import net.minestom.server.utils.Utils; import net.minestom.server.utils.validate.Check; +import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBT; import org.jglrxavpok.hephaistos.nbt.NBTException; import org.jglrxavpok.hephaistos.nbt.NBTReader; @@ -29,7 +30,7 @@ public class BinaryReader extends InputStream { private final ByteBuf buffer; private final NBTReader nbtReader = new NBTReader(this, false); - public BinaryReader(ByteBuf buffer) { + public BinaryReader(@NotNull ByteBuf buffer) { this.buffer = buffer; } diff --git a/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java index 0169af600..08acba53c 100644 --- a/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java +++ b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java @@ -26,7 +26,7 @@ public class BinaryWriter extends OutputStream { private final NBTWriter nbtWriter = new NBTWriter(this, false); /** - * Creates a {@link BinaryWriter} with a custom initial capacity. + * Creates a {@link BinaryWriter} using a heap buffer with a custom initial capacity. * * @param initialCapacity the initial capacity of the binary writer */