Class PacketUtils

java.lang.Object
net.minestom.server.utils.PacketUtils

public final class PacketUtils
extends java.lang.Object
Utils class for packets. Including writing a ServerPacket into a ByteBuf for network processing.
  • Method Summary

    Modifier and Type Method Description
    static void sendGroupedPacket​(java.util.Collection<Player> players, ServerPacket packet)
    Sends a ServerPacket to multiple players.
    static void writePacket​(io.netty.buffer.ByteBuf buf, ServerPacket packet)
    Writes a ServerPacket into a ByteBuf.
    static io.netty.buffer.ByteBuf writePacket​(ServerPacket packet)
    Writes a ServerPacket into a newly created ByteBuf.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • sendGroupedPacket

      public static void sendGroupedPacket​(@NotNull java.util.Collection<Player> players, @NotNull ServerPacket packet)
      Sends a 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.

      Parameters:
      players - the players to send the packet to
      packet - the packet to send to the players
    • writePacket

      public static void writePacket​(@NotNull io.netty.buffer.ByteBuf buf, @NotNull ServerPacket packet)
      Writes a ServerPacket into a ByteBuf.
      Parameters:
      buf - the recipient of packet
      packet - the packet to write into buf
    • writePacket

      @NotNull public static io.netty.buffer.ByteBuf writePacket​(@NotNull ServerPacket packet)
      Writes a ServerPacket into a newly created ByteBuf.
      Parameters:
      packet - the packet to write
      Returns:
      a ByteBuf containing packet