public abstract class NetworkMarker extends 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,
ByteBuffer inputBuffer,
PacketType type)
Construct a new network marker.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract ByteBuffer |
addHeader(ByteBuffer buffer,
PacketType type)
Return the byte buffer prepended with the packet header.
|
protected abstract DataInputStream |
addHeader(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.
|
boolean |
addPostListener(PacketPostListener listener)
Add a listener that is invoked after a packet has been successfully sent to the client, or received
by the server.
|
static byte[] |
getByteBuffer(NetworkMarker marker)
Retrieve the byte buffer stored in the given marker.
|
ByteBuffer |
getInputBuffer()
Retrieve the serialized packet data (excluding the header by default) from the network input stream.
|
ByteBuffer |
getInputBuffer(boolean excludeHeader)
Retrieve the serialized packet data from the network input stream.
|
DataInputStream |
getInputStream()
Retrieve the serialized packet data (excluding the header by default) as an input stream.
|
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.
|
Collection<PacketOutputHandler> |
getOutputHandlers()
Retrieve every registered output handler in no particular order.
|
List<PacketPostListener> |
getPostListeners()
Retrieve an immutable view of all the listeners that will be invoked once the packet has been sent or received.
|
List<ScheduledPacket> |
getScheduledPackets()
Retrieve a list of packets that will be schedule (in-order) when the current packet has been successfully transmitted.
|
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.
|
static boolean |
hasPostListeners(NetworkMarker marker)
Determine if the given marker has any post listeners.
|
static List<ScheduledPacket> |
readScheduledPackets(NetworkMarker marker)
Retrieve the scheduled packets of a particular network marker without constructing the list.
|
boolean |
removeOutputHandler(PacketOutputHandler handler)
Remove a given output handler from the serialization queue.
|
boolean |
removePostListener(PacketPostListener listener)
Remove the first instance of the given listener.
|
boolean |
requireOutputHeader()
Whether or not the output handlers have to write a packet header.
|
protected ByteBuffer |
skipHeader(ByteBuffer buffer)
Return a byte buffer without the header in the current packet.
|
protected abstract DataInputStream |
skipHeader(DataInputStream input)
Return an input stream without the header in the current packet.
|
public NetworkMarker(@Nonnull ConnectionSide side, ByteBuffer inputBuffer, PacketType type)
side - - which side this marker belongs to.inputBuffer - - the read serialized packet data.type - - packet typepublic NetworkMarker(@Nonnull ConnectionSide side, byte[] inputBuffer, PacketType type)
The input buffer is only non-null for client-side packets.
side - - which side this marker belongs to.inputBuffer - - the read serialized packet data.type - - packet typepublic ConnectionSide getSide()
public StreamSerializer getSerializer()
public 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 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 DataInputStream getInputStream()
The data is exactly the same as in getInputBuffer().
getInputBuffer()public 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 Collection<PacketOutputHandler> getOutputHandlers()
public boolean addPostListener(PacketPostListener listener)
Received packets are not guarenteed to have been fully processed, but packets passed
to PacketStream.recieveClientPacket(Player, PacketContainer) will be processed after the
current packet event.
Note that post listeners will be executed asynchronously off the main thread. They are not executed in any defined order.
listener - - the listener that will be invoked.public boolean removePostListener(PacketPostListener listener)
listener - - listener to remove.public List<PacketPostListener> getPostListeners()
public List<ScheduledPacket> getScheduledPackets()
This list is modifiable.
protected ByteBuffer skipHeader(ByteBuffer buffer) throws IOException
It's safe to modify the position of the buffer.
buffer - - a read-only byte source.IOException - If integer reading failsprotected abstract DataInputStream skipHeader(DataInputStream input) throws IOException
It's safe to modify the input stream.
input - - input streamIOException - If integer reading failsprotected abstract ByteBuffer addHeader(ByteBuffer buffer, PacketType type)
buffer - - the read-only byte buffer.type - - the current packet.protected abstract DataInputStream addHeader(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 boolean hasPostListeners(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.public static List<ScheduledPacket> readScheduledPackets(NetworkMarker marker)
This is an internal method that should not be used by API users.
marker - - the marker.Copyright © 2012–2017 Comphenix and dmulloy2. Licensed under the GNU GPL v2.