Class WirePacket

java.lang.Object
com.comphenix.protocol.injector.netty.WirePacket

public class WirePacket extends Object
A packet represented only by its id and bytes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    WirePacket(int id, byte[] bytes)
    Constructs a new WirePacket with a given id and contents
    WirePacket(PacketType type, byte[] bytes)
    Constructs a new WirePacket with a given type and contents
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    Creates a byte array from an existing PacketContainer containing all the bytes from that packet
    boolean
     
    static WirePacket
    Creates a WirePacket from an existing PacketContainer
    static WirePacket
    Creates a WirePacket from an existing Minecraft packet
    byte[]
    Gets this packet's contents as a byte array
    int
    Gets this packet's ID
    int
     
    static int
    readVarInt(io.netty.buffer.ByteBuf input)
     
    io.netty.buffer.ByteBuf
    Serializes this packet into a byte buffer
     
    void
    writeBytes(io.netty.buffer.ByteBuf output)
    Writes the contents of this packet to a given output
    void
    writeFully(io.netty.buffer.ByteBuf output)
    Fully writes the ID and contents of this packet to a given output
    void
    writeId(io.netty.buffer.ByteBuf output)
    Writes the id of this packet to a given output
    static void
    writeVarInt(io.netty.buffer.ByteBuf output, int value)
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • WirePacket

      public WirePacket(PacketType type, byte[] bytes)
      Constructs a new WirePacket with a given type and contents
      Parameters:
      type - Type of the packet
      bytes - Contents of the packet
    • WirePacket

      public WirePacket(int id, byte[] bytes)
      Constructs a new WirePacket with a given id and contents
      Parameters:
      id - ID of the packet
      bytes - Contents of the packet
  • Method Details

    • fromPacket

      public static WirePacket fromPacket(PacketContainer packet)
      Creates a WirePacket from an existing PacketContainer
      Parameters:
      packet - Existing packet
      Returns:
      The resulting WirePacket
    • bytesFromPacket

      public static byte[] bytesFromPacket(PacketContainer packet)
      Creates a byte array from an existing PacketContainer containing all the bytes from that packet
      Parameters:
      packet - Existing packet
      Returns:
      the byte array
    • fromPacket

      public static WirePacket fromPacket(Object packet)
      Creates a WirePacket from an existing Minecraft packet
      Parameters:
      packet - Existing Minecraft packet
      Returns:
      The resulting WirePacket
      Throws:
      IllegalArgumentException - If the packet is null or not a Minecraft packet
    • writeVarInt

      public static void writeVarInt(io.netty.buffer.ByteBuf output, int value)
    • readVarInt

      public static int readVarInt(io.netty.buffer.ByteBuf input)
    • getId

      public int getId()
      Gets this packet's ID
      Returns:
      The ID
    • getBytes

      public byte[] getBytes()
      Gets this packet's contents as a byte array
      Returns:
      The contents
    • writeId

      public void writeId(io.netty.buffer.ByteBuf output)
      Writes the id of this packet to a given output
      Parameters:
      output - Output to write to
    • writeBytes

      public void writeBytes(io.netty.buffer.ByteBuf output)
      Writes the contents of this packet to a given output
      Parameters:
      output - Output to write to
    • writeFully

      public void writeFully(io.netty.buffer.ByteBuf output)
      Fully writes the ID and contents of this packet to a given output
      Parameters:
      output - Output to write to
    • serialize

      public io.netty.buffer.ByteBuf serialize()
      Serializes this packet into a byte buffer
      Returns:
      The buffer
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object