Interface PacketWrapper
public interface PacketWrapper
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Applies a pipeline from an index to the wrapper.default void
cancel()
Cancel this packet from sending.void
Clear the input buffer / readable objectsvoid
Clear the packet, used if you have to change the packet completelycreate
(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.create
(int packetId, PacketHandler handler) Creates a new packet with values.static PacketWrapper
create
(@Nullable PacketType packetType, @Nullable io.netty.buffer.ByteBuf inputBuffer, UserConnection connection) Creates a new packet wrapper instance.static PacketWrapper
create
(@Nullable PacketType packetType, UserConnection connection) Creates a new packet wrapper instance.default PacketWrapper
create
(PacketType packetType) Creates a new packet for the target of this packet.default PacketWrapper
create
(PacketType packetType, PacketHandler handler) Creates a new packet with values.<T> T
Get a part from the outputint
getId()
Returns the raw packet id.@Nullable PacketType
Returns the packet type, or null if not transformed or manually unset.boolean
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 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 this packet to the connection on the current thread, skipping the current protocol.void
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
sendRaw()
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 a currently existing part in the outputvoid
setCancelled
(boolean cancel) Sets the cancellation state of the packet.void
setId
(int id) Deprecated.magic id, loses packet type info; usesetPacketType(PacketType)
void
setPacketType
(@Nullable PacketType packetType) Sets the packet type.user()
Get the user associated with this Packet<T> void
Write a type to the output.void
writeToBuffer
(io.netty.buffer.ByteBuf buffer) Write the current output to a buffer.
-
Field Details
-
PASSTHROUGH_ID
static final int PASSTHROUGH_ID- See Also:
-
-
Method Details
-
create
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 bufferconnection
- user connection- Returns:
- new packet wrapper
-
create
@Deprecated static PacketWrapper create(int packetId, @Nullable io.netty.buffer.ByteBuf inputBuffer, UserConnection connection) Deprecated.magic id; prefer usingcreate(PacketType, ByteBuf, UserConnection)
Creates a new packet wrapper instance.- Parameters:
packetId
- packet id, or -1 if none should be written to the bufferinputBuffer
- input bufferconnection
- user connection- Returns:
- new packet wrapper
-
get
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.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
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
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
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
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
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
Take a value from the input and write to the output, mapping the output type. This only works for types implementingTypeConverter
, 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
Take all the inputs and write them to the output.- Throws:
InformativeException
- If it failed to read or write
-
writeToBuffer
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
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 throughskipCurrentPipeline
- whether transformation of the current protocol should be skipped- Throws:
InformativeException
- if it fails to write
-
scheduleSend
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 throughskipCurrentPipeline
- 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
Sends this packet to the connection. Unlikesend(Class)
, this method does not handle the pipeline with packet id and data changes.- Throws:
InformativeException
- if it fails to write
-
sendFutureRaw
Sends this packet to the associated user, submitted to netty's event loop. UnlikesendFuture(Class)
, this method does not handle the pipeline with packet id and data changes.- Throws:
InformativeException
- if it fails to write
-
scheduleSendRaw
Sends this packet to the associated user, submitted to netty's event loop. Unlikesend(Class)
, this method does not handle the pipeline with packet id and data changes.- Throws:
InformativeException
- if it fails to write
-
create
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 packethandler
- handler to write to the packet- Returns:
- newly created packet wrapper
- Throws:
InformativeException
-
create
Creates a new packet for the target of this packet.- Parameters:
packetId
- id of the packet- Returns:
- newly created packet wrapper
-
create
Creates a new packet with values.- Parameters:
packetId
- id of the packethandler
- 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 directionstate
- protocol statepipeline
- 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
UserConnection 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
Sends this packet to the server. UnlikesendToServer(Class)
, this method does not handle the pipeline with packet id and data changes.- Throws:
InformativeException
- if it fails to write
-
scheduleSendToServerRaw
Sends this packet to the server, submitted to netty's event loop. UnlikesendToServer(Class)
, this method does not handle the pipeline with packet id and data changes.- Throws:
InformativeException
- if it fails to write
-
sendToServer
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 throughskipCurrentPipeline
- whether transformation of the current protocol should be skipped- Throws:
InformativeException
- if it fails to write
-
scheduleSendToServer
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 throughskipCurrentPipeline
- 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
Sets the packet type. If set to null, it will not be written to the buffer withwriteToBuffer(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.magic id, loses packet type info; usesetPacketType(PacketType)
Sets the packet id. If set to -1, it will not be written to the buffer withwriteToBuffer(ByteBuf)
.- Parameters:
id
- packet id
-
create(PacketType, ByteBuf, UserConnection)