public abstract class NetworkMarker
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
NetworkMarker.EmptyBufferMarker |
Constructor and Description |
---|
NetworkMarker(ConnectionSide side,
byte[] inputBuffer,
PacketType type)
Construct a new network marker.
|
NetworkMarker(ConnectionSide side,
java.nio.ByteBuffer inputBuffer,
PacketType type)
Construct a new network marker.
|
Modifier and Type | Method and Description |
---|---|
protected abstract java.nio.ByteBuffer |
addHeader(java.nio.ByteBuffer buffer,
PacketType type)
Return the byte buffer prepended with the packet header.
|
protected abstract java.io.DataInputStream |
addHeader(java.io.DataInputStream input,
PacketType type)
Return the input stream prepended with the packet header.
|
boolean |
addOutputHandler(PacketOutputHandler handler)
Enqueue the given output handler for managing how the current packet will be written to the network stream.
|
static byte[] |
getByteBuffer(NetworkMarker marker)
Retrieve the byte buffer stored in the given marker.
|
java.nio.ByteBuffer |
getInputBuffer()
Retrieve the serialized packet data (excluding the header by default) from the network input stream.
|
java.nio.ByteBuffer |
getInputBuffer(boolean excludeHeader)
Retrieve the serialized packet data from the network input stream.
|
java.io.DataInputStream |
getInputStream()
Retrieve the serialized packet data (excluding the header by default) as an input stream.
|
java.io.DataInputStream |
getInputStream(boolean excludeHeader)
Retrieve the serialized packet data as an input stream.
|
static NetworkMarker |
getNetworkMarker(PacketEvent event)
Retrieve the network marker of a particular event without creating it.
|
java.util.Collection<PacketOutputHandler> |
getOutputHandlers()
Retrieve every registered output handler in no particular order.
|
StreamSerializer |
getSerializer()
Retrieve a utility class for serializing and deserializing Minecraft objects.
|
ConnectionSide |
getSide()
Retrieve whether or not this marker belongs to a client or a server side packet.
|
static boolean |
hasOutputHandlers(NetworkMarker marker)
Determine if the given marker has any output handlers.
|
boolean |
removeOutputHandler(PacketOutputHandler handler)
Remove a given output handler from the serialization queue.
|
boolean |
requireOutputHeader()
Whether or not the output handlers have to write a packet header.
|
protected java.nio.ByteBuffer |
skipHeader(java.nio.ByteBuffer buffer)
Return a byte buffer without the header in the current packet.
|
protected abstract java.io.DataInputStream |
skipHeader(java.io.DataInputStream input)
Return an input stream without the header in the current packet.
|
public NetworkMarker(@Nonnull ConnectionSide side, java.nio.ByteBuffer inputBuffer, PacketType type)
side
- - whether or not this marker belongs to a client or server packet.inputBuffer
- - the read serialized packet data.public NetworkMarker(@Nonnull ConnectionSide side, byte[] inputBuffer, PacketType type)
The input buffer is only non-null for client-side packets.
side
- - whether or not this marker belongs to a client or server packet.inputBuffer
- - the read serialized packet data.handler
- - handle skipping headers.public ConnectionSide getSide()
public StreamSerializer getSerializer()
public java.nio.ByteBuffer getInputBuffer()
The returned buffer is read-only. If the parent event is a server side packet this
method throws IllegalStateException
.
It returns NULL if the packet was transmitted by a plugin locally.
public java.nio.ByteBuffer getInputBuffer(boolean excludeHeader)
The returned buffer is read-only. If the parent event is a server side packet this
method throws IllegalStateException
.
It returns NULL if the packet was transmitted by a plugin locally.
excludeHeader
- - whether or not to exclude the packet ID header.public java.io.DataInputStream getInputStream()
The data is exactly the same as in getInputBuffer()
.
excludeHeader
- - whether or not to exclude the packet ID header.getInputBuffer()
public java.io.DataInputStream getInputStream(boolean excludeHeader)
The data is exactly the same as in getInputBuffer()
.
excludeHeader
- - whether or not to exclude the packet ID header.getInputBuffer()
public boolean requireOutputHeader()
public boolean addOutputHandler(@Nonnull PacketOutputHandler handler)
Note that output handlers are not serialized, as most consumers will probably implement them using anonymous classes. It is not safe to serialize anonymous classes, as their name depend on the order in which they are declared in the parent class.
This can only be invoked on server side packet events.
handler
- - the handler that will take part in serializing the packet.public boolean removeOutputHandler(@Nonnull PacketOutputHandler handler)
This can only be invoked on server side packet events.
handler
- - the handler to remove.@Nonnull public java.util.Collection<PacketOutputHandler> getOutputHandlers()
protected java.nio.ByteBuffer skipHeader(java.nio.ByteBuffer buffer) throws java.io.IOException
It's safe to modify the position of the buffer.
buffer
- - a read-only byte source.java.io.IOException
protected abstract java.io.DataInputStream skipHeader(java.io.DataInputStream input) throws java.io.IOException
It's safe to modify the input stream.
java.io.IOException
protected abstract java.nio.ByteBuffer addHeader(java.nio.ByteBuffer buffer, PacketType type)
buffer
- - the read-only byte buffer.type
- - the current packet.protected abstract java.io.DataInputStream addHeader(java.io.DataInputStream input, PacketType type)
input
- - the input stream.type
- - the current packet.public static boolean hasOutputHandlers(NetworkMarker marker)
marker
- - the marker to check.public static byte[] getByteBuffer(NetworkMarker marker)
marker
- - the marker.public static NetworkMarker getNetworkMarker(PacketEvent event)
This is an internal method that should not be used by API users.
event
- - the event.