Interface PacketWrapper


public interface PacketWrapper
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(Direction direction, State state, List<Protocol> pipeline)
    Applies a pipeline from an index to the wrapper.
    default void
    Cancel this packet from sending.
    void
    Clear the input buffer / readable objects
    void
    Clear the packet, used if you have to change the packet completely
    create(int packetId)
    Creates a new packet for the target of this packet.
    create(int packetId, @Nullable io.netty.buffer.ByteBuf inputBuffer, UserConnection connection)
    Deprecated.
    create(int packetId, PacketHandler handler)
    Creates a new packet with values.
    create(@Nullable PacketType packetType, @Nullable io.netty.buffer.ByteBuf inputBuffer, UserConnection connection)
    Creates a new packet wrapper instance.
    create(@Nullable PacketType packetType, UserConnection connection)
    Creates a new packet wrapper instance.
    create(PacketType packetType)
    Creates a new packet for the target of this packet.
    create(PacketType packetType, PacketHandler handler)
    Creates a new packet with values.
    <T> T
    get(Type<T> type, int index)
    Get a part from the output
    int
    Returns the raw packet id.
    @Nullable PacketType
    Returns the packet type, or null if not transformed or manually unset.
    boolean
    is(Type type, int index)
    Deprecated.
    boolean
    Check if this packet is cancelled.
    boolean
    isReadable(Type type, int index)
    Check if a type is at an index
    <T> T
    passthrough(Type<T> type)
    Take a value from the input and write to the output.
    void
    Take all the inputs and write them to the output.
    <T> T
    passthroughAndMap(Type<?> type, Type<T> mappedType)
    Take a value from the input and write to the output, mapping the output type.
    <T> T
    read(Type<T> type)
    Read a type from the input.
    void
    Reset the reader, so that it can be read again.
    default void
    scheduleSend(Class<? extends Protocol> protocol)
    Send this packet to the connection, submitted to netty's event loop and skipping the current protocol.
    void
    scheduleSend(Class<? extends Protocol> protocol, boolean skipCurrentPipeline)
    Send this packet to the connection, submitted to netty's event loop.
    void
    Sends this packet to the associated user, submitted to netty's event loop.
    default void
    scheduleSendToServer(Class<? extends Protocol> protocol)
    Send this packet to the server, submitted to netty's event loop and skipping the current protocol.
    void
    scheduleSendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline)
    Send this packet to the server, submitted to netty's event loop.
    void
    Sends this packet to the server, submitted to netty's event loop.
    default void
    send(Class<? extends Protocol> protocol)
    Send this packet to the connection on the current thread, skipping the current protocol.
    void
    send(Class<? extends Protocol> protocol, boolean skipCurrentPipeline)
    Send this packet to the connection on the current thread.
    io.netty.channel.ChannelFuture
    sendFuture(Class<? extends Protocol> protocolClass)
    Sends this packet to the associated user.
    io.netty.channel.ChannelFuture
    Sends this packet to the associated user, submitted to netty's event loop.
    void
    Sends this packet to the connection.
    default void
    sendToServer(Class<? extends Protocol> protocol)
    Send this packet to the server on the current thread, skipping the current protocol.
    void
    sendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline)
    Send this packet to the server on the current thread.
    void
    Sends this packet to the server.
    <T> void
    set(Type<T> type, int index, @Nullable T value)
    Set a currently existing part in the output
    void
    setCancelled(boolean cancel)
    Sets the cancellation state of the packet.
    void
    setId(int id)
    Deprecated.
    magic id, loses packet type info; use setPacketType(PacketType)
    void
    setPacketType(@Nullable PacketType packetType)
    Sets the packet type.
    Get the user associated with this Packet
    <T> void
    write(Type<T> type, @Nullable T value)
    Write a type to the output.
    void
    writeToBuffer(io.netty.buffer.ByteBuf buffer)
    Write the current output to a buffer.
  • Field Details

  • Method Details

    • create

      static PacketWrapper create(@Nullable PacketType packetType, UserConnection connection)
      Creates a new packet wrapper instance.
      Parameters:
      packetType - packet type, or null if none should be written to the buffer (raw id = -1)
      connection - user connection
      Returns:
      new packet wrapper
    • create

      static PacketWrapper create(@Nullable PacketType packetType, @Nullable io.netty.buffer.ByteBuf inputBuffer, UserConnection connection)
      Creates a new packet wrapper instance.
      Parameters:
      packetType - packet type, or null if none should be written to the buffer (raw id = -1)
      inputBuffer - input buffer
      connection - user connection
      Returns:
      new packet wrapper
    • create

      @Deprecated static PacketWrapper create(int packetId, @Nullable io.netty.buffer.ByteBuf inputBuffer, UserConnection connection)
      Deprecated.
      Creates a new packet wrapper instance.
      Parameters:
      packetId - packet id, or -1 if none should be written to the buffer
      inputBuffer - input buffer
      connection - user connection
      Returns:
      new packet wrapper
    • get

      <T> T get(Type<T> type, int index) throws InformativeException
      Get a part from the output
      Type Parameters:
      T - The return type of the type you wish to get.
      Parameters:
      type - The type of the part you wish to get.
      index - The index of the part (relative to the type)
      Returns:
      The requested type or throws ArrayIndexOutOfBounds
      Throws:
      InformativeException - If it fails to find it, an exception will be thrown.
    • is

      @Deprecated boolean is(Type type, int index)
      Deprecated.
      Check if a type is at an index
      Parameters:
      type - The type of the part you wish to get.
      index - The index of the part (relative to the type)
      Returns:
      True if the type is at the index
    • isReadable

      boolean isReadable(Type type, int index)
      Check if a type is at an index
      Parameters:
      type - The type of the part you wish to get.
      index - The index of the part (relative to the type)
      Returns:
      True if the type is at the index
    • set

      <T> void set(Type<T> type, int index, @Nullable T value) throws InformativeException
      Set a currently existing part in the output
      Type Parameters:
      T - The return type of the type you wish to set.
      Parameters:
      type - The type of the part you wish to set.
      index - The index of the part (relative to the type)
      value - The value of the part you wish to set it to.
      Throws:
      InformativeException - If it fails to set it, an exception will be thrown.
    • read

      <T> T read(Type<T> type) throws InformativeException
      Read a type from the input.
      Type Parameters:
      T - The return type of the type you wish to read.
      Parameters:
      type - The type you wish to read
      Returns:
      The requested type
      Throws:
      InformativeException - If it fails to read
    • write

      <T> void write(Type<T> type, @Nullable T value)
      Write a type to the output.
      Type Parameters:
      T - The return type of the type you wish to write.
      Parameters:
      type - The type to write.
      value - The value of the type to write.
    • passthrough

      <T> T passthrough(Type<T> type) throws InformativeException
      Take a value from the input and write to the output.
      Type Parameters:
      T - The return type of the type you wish to pass through.
      Parameters:
      type - The type to read and write.
      Returns:
      The type which was read/written.
      Throws:
      InformativeException - If it failed to read or write
    • passthroughAndMap

      <T> T passthroughAndMap(Type<?> type, Type<T> mappedType) throws InformativeException
      Take a value from the input and write to the output, mapping the output type. This only works for types implementing TypeConverter, which is generally only the primitive wrapper types.
      Type Parameters:
      T - The return type of the type you wish to pass through.
      Parameters:
      type - The type to read.
      mappedType - The type to write.
      Returns:
      The type which was read/written.
      Throws:
      InformativeException - If it failed to read or write
    • passthroughAll

      void passthroughAll() throws InformativeException
      Take all the inputs and write them to the output.
      Throws:
      InformativeException - If it failed to read or write
    • writeToBuffer

      void writeToBuffer(io.netty.buffer.ByteBuf buffer) throws InformativeException
      Write the current output to a buffer.
      Parameters:
      buffer - The buffer to write to.
      Throws:
      InformativeException - Throws an exception if it fails to write a value.
    • clearInputBuffer

      void clearInputBuffer()
      Clear the input buffer / readable objects
    • clearPacket

      void clearPacket()
      Clear the packet, used if you have to change the packet completely
    • send

      default void send(Class<? extends Protocol> protocol) throws InformativeException
      Send this packet to the connection on the current thread, skipping the current protocol.
      Parameters:
      protocol - protocol to be sent through
      Throws:
      InformativeException - if it fails to write
    • send

      void send(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws InformativeException
      Send this packet to the connection on the current thread.
      Parameters:
      protocol - protocol to be sent through
      skipCurrentPipeline - whether transformation of the current protocol should be skipped
      Throws:
      InformativeException - if it fails to write
    • scheduleSend

      default void scheduleSend(Class<? extends Protocol> protocol) throws InformativeException
      Send this packet to the connection, submitted to netty's event loop and skipping the current protocol.
      Parameters:
      protocol - protocol to be sent through
      Throws:
      InformativeException - if it fails to write
    • scheduleSend

      void scheduleSend(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws InformativeException
      Send this packet to the connection, submitted to netty's event loop.
      Parameters:
      protocol - protocol to be sent through
      skipCurrentPipeline - whether transformation of the current protocol should be skipped
      Throws:
      InformativeException
    • sendFuture

      io.netty.channel.ChannelFuture sendFuture(Class<? extends Protocol> protocolClass) throws InformativeException
      Sends this packet to the associated user. The ChannelFuture fails exceptionally if the packet is cancelled during construction.
      Parameters:
      protocolClass - the protocol class to start from in the pipeline
      Returns:
      new ChannelFuture for the write operation
      Throws:
      InformativeException
    • sendRaw

      void sendRaw() throws InformativeException
      Sends this packet to the connection. Unlike send(Class), this method does not handle the pipeline with packet id and data changes.
      Throws:
      InformativeException - if it fails to write
    • sendFutureRaw

      io.netty.channel.ChannelFuture sendFutureRaw() throws InformativeException
      Sends this packet to the associated user, submitted to netty's event loop. Unlike sendFuture(Class), this method does not handle the pipeline with packet id and data changes.
      Throws:
      InformativeException - if it fails to write
    • scheduleSendRaw

      void scheduleSendRaw() throws InformativeException
      Sends this packet to the associated user, submitted to netty's event loop. Unlike send(Class), this method does not handle the pipeline with packet id and data changes.
      Throws:
      InformativeException - if it fails to write
    • create

      default PacketWrapper create(PacketType packetType)
      Creates a new packet for the target of this packet.
      Parameters:
      packetType - packet type of the new packet
      Returns:
      The newly created packet wrapper
    • create

      default PacketWrapper create(PacketType packetType, PacketHandler handler) throws InformativeException
      Creates a new packet with values.
      Parameters:
      packetType - packet type of the new packet
      handler - handler to write to the packet
      Returns:
      newly created packet wrapper
      Throws:
      InformativeException
    • create

      PacketWrapper create(int packetId)
      Creates a new packet for the target of this packet.
      Parameters:
      packetId - id of the packet
      Returns:
      newly created packet wrapper
    • create

      PacketWrapper create(int packetId, PacketHandler handler) throws InformativeException
      Creates a new packet with values.
      Parameters:
      packetId - id of the packet
      handler - handler to write to the packet
      Returns:
      newly created packet wrapper
      Throws:
      InformativeException
    • apply

      void apply(Direction direction, State state, List<Protocol> pipeline) throws InformativeException, CancelException
      Applies a pipeline from an index to the wrapper.
      Parameters:
      direction - protocol direction
      state - protocol state
      pipeline - protocol pipeline
      Throws:
      InformativeException
      CancelException
    • isCancelled

      boolean isCancelled()
      Check if this packet is cancelled.
      Returns:
      True if the packet won't be sent.
    • cancel

      default void cancel()
      Cancel this packet from sending.
    • setCancelled

      void setCancelled(boolean cancel)
      Sets the cancellation state of the packet.
      Parameters:
      cancel - whether the packet should be cancelled
    • user

      Get the user associated with this Packet
      Returns:
      The user
    • resetReader

      void resetReader()
      Reset the reader, so that it can be read again.
    • sendToServerRaw

      void sendToServerRaw() throws InformativeException
      Sends this packet to the server. Unlike sendToServer(Class), this method does not handle the pipeline with packet id and data changes.
      Throws:
      InformativeException - if it fails to write
    • scheduleSendToServerRaw

      void scheduleSendToServerRaw() throws InformativeException
      Sends this packet to the server, submitted to netty's event loop. Unlike sendToServer(Class), this method does not handle the pipeline with packet id and data changes.
      Throws:
      InformativeException - if it fails to write
    • sendToServer

      default void sendToServer(Class<? extends Protocol> protocol) throws InformativeException
      Send this packet to the server on the current thread, skipping the current protocol.
      Parameters:
      protocol - protocol to be sent through
      Throws:
      InformativeException - if it fails to write
    • sendToServer

      void sendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws InformativeException
      Send this packet to the server on the current thread.
      Parameters:
      protocol - protocol to be sent through
      skipCurrentPipeline - whether transformation of the current protocol should be skipped
      Throws:
      InformativeException - if it fails to write
    • scheduleSendToServer

      default void scheduleSendToServer(Class<? extends Protocol> protocol) throws InformativeException
      Send this packet to the server, submitted to netty's event loop and skipping the current protocol.
      Parameters:
      protocol - protocol to be sent through
      Throws:
      InformativeException - if it fails to write
    • scheduleSendToServer

      void scheduleSendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws InformativeException
      Send this packet to the server, submitted to netty's event loop.
      Parameters:
      protocol - protocol to be sent through
      skipCurrentPipeline - whether transformation of the current protocol should be skipped
      Throws:
      InformativeException - if it fails to write
    • getPacketType

      @Nullable PacketType getPacketType()
      Returns the packet type, or null if not transformed or manually unset.
      Returns:
      packet type if set
    • setPacketType

      void setPacketType(@Nullable PacketType packetType)
      Sets the packet type. If set to null, it will not be written to the buffer with writeToBuffer(ByteBuf). Setting the type to null also sets the raw packet id to -1.
      Parameters:
      packetType - packet type
    • getId

      int getId()
      Returns the raw packet id.
      Returns:
      raw packet id
    • setId

      @Deprecated void setId(int id)
      Deprecated.
      magic id, loses packet type info; use setPacketType(PacketType)
      Sets the packet id. If set to -1, it will not be written to the buffer with writeToBuffer(ByteBuf).
      Parameters:
      id - packet id