Class PacketConstructor

java.lang.Object
com.comphenix.protocol.injector.PacketConstructor

public class PacketConstructor extends Object
A packet constructor that uses an internal Minecraft.
  • Field Details

    • DEFAULT

      public static final PacketConstructor DEFAULT
      A packet constructor that automatically converts Bukkit types to their NMS conterpart.

      Remember to call withPacket().

  • Method Details

    • getClass

      public static Class<?> getClass(Object obj)
      Retrieve the class of an object, or just the class if it already is a class object.
      Parameters:
      obj - - the object.
      Returns:
      The class of an object.
    • getUnwrappers

      public com.google.common.collect.ImmutableList<PacketConstructor.Unwrapper> getUnwrappers()
    • getPacketID

      @Deprecated public int getPacketID()
      Deprecated.
      Retrieve the id of the packets this constructor creates.

      Deprecated: Use getType() instead.

      Returns:
      The ID of the packets this constructor will create.
    • getType

      public PacketType getType()
      Retrieve the type of the packets this constructor creates.
      Returns:
      The type of the created packets.
    • withUnwrappers

      public PacketConstructor withUnwrappers(List<PacketConstructor.Unwrapper> unwrappers)
      Return a copy of the current constructor with a different list of unwrappers.
      Parameters:
      unwrappers - - list of unwrappers that convert Bukkit wrappers into the equivalent NMS classes.
      Returns:
      A constructor with a different set of unwrappers.
    • withPacket

      public PacketConstructor withPacket(PacketType type, Object[] values)
      Create a packet constructor that creates packets using the given types.

      Note that if you pass a Class as a value, it will use its type directly.

      Parameters:
      type - - the type of the packet to create.
      values - - the values that will match each parameter in the desired constructor.
      Returns:
      A packet constructor with these types.
      Throws:
      IllegalArgumentException - If no packet constructor could be created with these types.
    • createPacket

      public PacketContainer createPacket(Object... values) throws FieldAccessException
      Construct a packet using the special builtin Minecraft constructors.
      Parameters:
      values - - values containing Bukkit wrapped items to pass to Minecraft.
      Returns:
      The created packet.
      Throws:
      FieldAccessException - Failure due to a security limitation.
      IllegalArgumentException - Arguments doesn't match the constructor.
      RuntimeException - Minecraft threw an exception.