public interface PacketWrapper
Modifier and Type | Field and Description |
---|---|
static int |
PASSTHROUGH_ID |
Modifier and Type | Method and Description |
---|---|
PacketWrapper |
apply(Direction direction,
State state,
int index,
java.util.List<Protocol> pipeline) |
PacketWrapper |
apply(Direction direction,
State state,
int index,
java.util.List<Protocol> pipeline,
boolean reverse)
Applies a pipeline from an index to the wrapper.
|
default void |
cancel()
Cancel this packet from sending.
|
void |
clearInputBuffer()
Clear the input buffer / readable objects
|
void |
clearPacket()
Clear the packet, used if you have to change the packet completely
|
PacketWrapper |
create(int packetId)
Creates a new packet for the target of this packet.
|
static PacketWrapper |
create(int packetId,
@Nullable io.netty.buffer.ByteBuf inputBuffer,
UserConnection connection)
Deprecated.
magic id; prefer using
create(PacketType, ByteBuf, UserConnection) |
PacketWrapper |
create(int packetId,
PacketHandler handler)
Creates a new packet with values.
|
default PacketWrapper |
create(PacketType packetType)
Creates a new packet for the target of this packet.
|
static PacketWrapper |
create(@Nullable PacketType packetType,
@Nullable io.netty.buffer.ByteBuf inputBuffer,
UserConnection connection)
Creates a new packet wrapper instance.
|
default PacketWrapper |
create(PacketType packetType,
PacketHandler handler)
Creates a new packet with values.
|
static PacketWrapper |
create(@Nullable PacketType packetType,
UserConnection connection)
Creates a new packet wrapper instance.
|
<T> T |
get(Type<T> type,
int index)
Get a part from the output
|
int |
getId()
Returns the raw packet id.
|
@Nullable PacketType |
getPacketType()
Returns the packet type.
|
boolean |
is(Type type,
int index)
Check if a type is at an index
|
boolean |
isCancelled()
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 |
passthroughAll()
Take all the inputs and write them to the output.
|
<T> T |
read(Type<T> type)
Read a type from the input.
|
void |
resetReader()
Reset the reader, so that it can be read again.
|
default void |
scheduleSend(java.lang.Class<? extends Protocol> protocol)
Send this packet to the connection, submitted to netty's event loop and skipping the current protocol.
|
void |
scheduleSend(java.lang.Class<? extends Protocol> protocol,
boolean skipCurrentPipeline)
Send this packet to the connection, submitted to netty's event loop.
|
void |
scheduleSendRaw()
Sends this packet to the associated user, submitted to netty's event loop.
|
default void |
scheduleSendToServer(java.lang.Class<? extends Protocol> protocol)
Send this packet to the server, submitted to netty's event loop and skipping the current protocol.
|
void |
scheduleSendToServer(java.lang.Class<? extends Protocol> protocol,
boolean skipCurrentPipeline)
Send this packet to the server, submitted to netty's event loop.
|
void |
scheduleSendToServerRaw()
Sends this packet to the server, submitted to netty's event loop.
|
default void |
send()
Deprecated.
misleading; use
sendRaw() . This method will be removed in 5.0.0 |
default void |
send(java.lang.Class<? extends Protocol> protocol)
Send this packet to the connection on the current thread, skipping the current protocol.
|
void |
send(java.lang.Class<? extends Protocol> protocol,
boolean skipCurrentPipeline)
Send this packet to the connection on the current thread.
|
io.netty.channel.ChannelFuture |
sendFuture(java.lang.Class<? extends Protocol> packetProtocol)
Send this packet to the associated user.
|
void |
sendRaw()
Sends this packet to the connection.
|
default void |
sendToServer()
Deprecated.
misleading; use
sendToServerRaw() . This method will be removed in 5.0.0 |
default void |
sendToServer(java.lang.Class<? extends Protocol> protocol)
Send this packet to the server on the current thread, skipping the current protocol.
|
void |
sendToServer(java.lang.Class<? extends Protocol> protocol,
boolean skipCurrentPipeline)
Send this packet to the server on the current thread.
|
void |
sendToServerRaw()
Sends this packet to the server.
|
<T> void |
set(Type<T> type,
int index,
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) |
default void |
setId(PacketType packetType)
Deprecated.
use
setPacketType(PacketType) . This method will be removed in 5.0.0 |
void |
setPacketType(@Nullable PacketType packetType)
Sets the packet type.
|
UserConnection |
user()
Get the user associated with this Packet
|
<T> void |
write(Type<T> type,
T value)
Write a type to the output.
|
void |
writeToBuffer(io.netty.buffer.ByteBuf buffer)
Write the current output to a buffer.
|
static final int PASSTHROUGH_ID
static PacketWrapper create(@Nullable PacketType packetType, UserConnection connection)
packetType
- packet type, or null if none should be written to the buffer (raw id = -1)connection
- user connectionstatic PacketWrapper create(@Nullable PacketType packetType, @Nullable io.netty.buffer.ByteBuf inputBuffer, UserConnection connection)
packetType
- packet type, or null if none should be written to the buffer (raw id = -1)inputBuffer
- input bufferconnection
- user connection@Deprecated static PacketWrapper create(int packetId, @Nullable io.netty.buffer.ByteBuf inputBuffer, UserConnection connection)
create(PacketType, ByteBuf, UserConnection)
packetId
- packet id, or -1 if none should be written to the bufferinputBuffer
- input bufferconnection
- user connection<T> T get(Type<T> type, int index) throws java.lang.Exception
T
- The return type of the type you wish to get.type
- The type of the part you wish to get.index
- The index of the part (relative to the type)InformativeException
- If it fails to find it, an exception will be thrown.java.lang.Exception
boolean is(Type type, int index)
type
- The type of the part you wish to get.index
- The index of the part (relative to the type)boolean isReadable(Type type, int index)
type
- The type of the part you wish to get.index
- The index of the part (relative to the type)<T> void set(Type<T> type, int index, T value) throws java.lang.Exception
T
- The return type of the type you wish to set.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.InformativeException
- If it fails to set it, an exception will be thrown.java.lang.Exception
<T> T read(Type<T> type) throws java.lang.Exception
T
- The return type of the type you wish to read.type
- The type you wish to readInformativeException
- If it fails to readjava.lang.Exception
<T> void write(Type<T> type, T value)
T
- The return type of the type you wish to write.type
- The type to write.value
- The value of the type to write.<T> T passthrough(Type<T> type) throws java.lang.Exception
T
- The return type of the type you wish to pass through.type
- The type to read and write.java.lang.Exception
- If it failed to read or writevoid passthroughAll() throws java.lang.Exception
java.lang.Exception
- If it failed to read or writevoid writeToBuffer(io.netty.buffer.ByteBuf buffer) throws java.lang.Exception
buffer
- The buffer to write to.InformativeException
- Throws an exception if it fails to write a value.java.lang.Exception
void clearInputBuffer()
void clearPacket()
default void send(java.lang.Class<? extends Protocol> protocol) throws java.lang.Exception
protocol
- protocol to be sent throughjava.lang.Exception
- if it fails to writevoid send(java.lang.Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws java.lang.Exception
protocol
- protocol to be sent throughskipCurrentPipeline
- whether transformation of the current protocol should be skippedjava.lang.Exception
- if it fails to writedefault void scheduleSend(java.lang.Class<? extends Protocol> protocol) throws java.lang.Exception
protocol
- protocol to be sent throughjava.lang.Exception
- if it fails to writevoid scheduleSend(java.lang.Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws java.lang.Exception
protocol
- protocol to be sent throughskipCurrentPipeline
- whether transformation of the current protocol should be skippedjava.lang.Exception
- if it fails to writeio.netty.channel.ChannelFuture sendFuture(java.lang.Class<? extends Protocol> packetProtocol) throws java.lang.Exception
packetProtocol
- The protocol version of the packet.java.lang.Exception
- if it fails to write@Deprecated default void send() throws java.lang.Exception
sendRaw()
. This method will be removed in 5.0.0java.lang.Exception
void sendRaw() throws java.lang.Exception
send(Class)
, this method does not handle the pipeline with packet id and data changes.java.lang.Exception
- if it fails to writevoid scheduleSendRaw() throws java.lang.Exception
send(Class)
, this method does not handle the pipeline with packet id and data changes.java.lang.Exception
- if it fails to writedefault PacketWrapper create(PacketType packetType)
packetType
- packet type of the new packetdefault PacketWrapper create(PacketType packetType, PacketHandler handler) throws java.lang.Exception
packetType
- packet type of the new packethandler
- handler to write to the packetjava.lang.Exception
- if it failed to write the values from the ValueCreatorPacketWrapper create(int packetId)
packetId
- id of the packetPacketWrapper create(int packetId, PacketHandler handler) throws java.lang.Exception
packetId
- id of the packethandler
- handler to write to the packetjava.lang.Exception
- if it failed to write the values from the ValueCreatorPacketWrapper apply(Direction direction, State state, int index, java.util.List<Protocol> pipeline, boolean reverse) throws java.lang.Exception
direction
- protocol directionstate
- protocol stateindex
- index to start from, will be reversed depending on the reverse parameterpipeline
- protocol pipelinereverse
- whether the array should be looped in reverse, will also reverse the given indexjava.lang.Exception
- If it fails to transform a packet, exception will be thrownPacketWrapper apply(Direction direction, State state, int index, java.util.List<Protocol> pipeline) throws java.lang.Exception
java.lang.Exception
apply(Direction, State, int, List, boolean)
boolean isCancelled()
default void cancel()
void setCancelled(boolean cancel)
cancel
- whether the packet should be cancelledUserConnection user()
void resetReader()
@Deprecated default void sendToServer() throws java.lang.Exception
sendToServerRaw()
. This method will be removed in 5.0.0java.lang.Exception
- If it failed to writevoid sendToServerRaw() throws java.lang.Exception
sendToServer(Class)
, this method does not handle the pipeline with packet id and data changes.java.lang.Exception
- if it fails to writevoid scheduleSendToServerRaw() throws java.lang.Exception
sendToServer(Class)
, this method does not handle the pipeline with packet id and data changes.java.lang.Exception
- if it fails to writedefault void sendToServer(java.lang.Class<? extends Protocol> protocol) throws java.lang.Exception
protocol
- protocol to be sent throughjava.lang.Exception
- if it fails to writevoid sendToServer(java.lang.Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws java.lang.Exception
protocol
- protocol to be sent throughskipCurrentPipeline
- whether transformation of the current protocol should be skippedjava.lang.Exception
- if it fails to writedefault void scheduleSendToServer(java.lang.Class<? extends Protocol> protocol) throws java.lang.Exception
protocol
- protocol to be sent throughjava.lang.Exception
- if it fails to writevoid scheduleSendToServer(java.lang.Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws java.lang.Exception
protocol
- protocol to be sent throughskipCurrentPipeline
- whether transformation of the current protocol should be skippedjava.lang.Exception
- if it fails to write@Nullable PacketType getPacketType()
void setPacketType(@Nullable PacketType packetType)
writeToBuffer(ByteBuf)
.
Setting the type to null also sets the raw packet id to -1.packetType
- packet typeint getId()
@Deprecated default void setId(PacketType packetType)
setPacketType(PacketType)
. This method will be removed in 5.0.0packetType
- packet type@Deprecated void setId(int id)
setPacketType(PacketType)
writeToBuffer(ByteBuf)
.id
- packet id