PacketUtils comment

This commit is contained in:
themode 2020-11-13 09:17:53 +01:00
parent 2d009e19a7
commit 47045252e5
4 changed files with 17 additions and 8 deletions

View File

@ -52,9 +52,9 @@ public class NettyServer {
channel = NioServerSocketChannel.class; channel = NioServerSocketChannel.class;
} }
bootstrap = new ServerBootstrap(); bootstrap = new ServerBootstrap()
bootstrap.group(boss, worker); .group(boss, worker)
bootstrap.channel(channel); .channel(channel);
bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(@NotNull SocketChannel ch) { protected void initChannel(@NotNull SocketChannel ch) {

View File

@ -10,7 +10,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collection; 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 { public final class PacketUtils {
@ -18,7 +19,15 @@ public final class PacketUtils {
} }
public static void sendGroupedPacket(Collection<Player> players, ServerPacket packet) { /**
* Sends a {@link ServerPacket} to multiple players. Mostly used for convenience.
* <p>
* 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<Player> players, @NotNull ServerPacket packet) {
for (Player player : players) { for (Player player : players) {
player.getPlayerConnection().sendPacket(packet); player.getPlayerConnection().sendPacket(packet);
} }
@ -31,7 +40,6 @@ public final class PacketUtils {
* @param packet the packet to write into {@code buf} * @param packet the packet to write into {@code buf}
*/ */
public static void writePacket(@NotNull ByteBuf buf, @NotNull ServerPacket packet) { public static void writePacket(@NotNull ByteBuf buf, @NotNull ServerPacket packet) {
final ByteBuf packetBuffer = getPacketBuffer(packet); final ByteBuf packetBuffer = getPacketBuffer(packet);
writePacket(buf, packetBuffer, packet.getId()); writePacket(buf, packetBuffer, packet.getId());

View File

@ -11,6 +11,7 @@ import net.minestom.server.utils.NBTUtils;
import net.minestom.server.utils.SerializerUtils; import net.minestom.server.utils.SerializerUtils;
import net.minestom.server.utils.Utils; import net.minestom.server.utils.Utils;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBT; import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTException; import org.jglrxavpok.hephaistos.nbt.NBTException;
import org.jglrxavpok.hephaistos.nbt.NBTReader; import org.jglrxavpok.hephaistos.nbt.NBTReader;
@ -29,7 +30,7 @@ public class BinaryReader extends InputStream {
private final ByteBuf buffer; private final ByteBuf buffer;
private final NBTReader nbtReader = new NBTReader(this, false); private final NBTReader nbtReader = new NBTReader(this, false);
public BinaryReader(ByteBuf buffer) { public BinaryReader(@NotNull ByteBuf buffer) {
this.buffer = buffer; this.buffer = buffer;
} }

View File

@ -26,7 +26,7 @@ public class BinaryWriter extends OutputStream {
private final NBTWriter nbtWriter = new NBTWriter(this, false); 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 * @param initialCapacity the initial capacity of the binary writer
*/ */