Class NetworkMarker
- Direct Known Subclasses:
NettyNetworkMarker,NetworkMarker.EmptyBufferMarker
- Author:
- Kristian
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionNetworkMarker(ConnectionSide side, byte[] inputBuffer, PacketType type)Construct a new network marker.NetworkMarker(ConnectionSide side, ByteBuffer inputBuffer, PacketType type)Construct a new network marker. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract DataInputStreamaddHeader(DataInputStream input, PacketType type)Return the input stream prepended with the packet header.protected abstract ByteBufferaddHeader(ByteBuffer buffer, PacketType type)Return the byte buffer prepended with the packet header.booleanaddOutputHandler(PacketOutputHandler handler)Enqueue the given output handler for managing how the current packet will be written to the network stream.booleanaddPostListener(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.Retrieve the serialized packet data (excluding the header by default) from the network input stream.getInputBuffer(boolean excludeHeader)Retrieve the serialized packet data from the network input stream.Retrieve the serialized packet data (excluding the header by default) as an input stream.getInputStream(boolean excludeHeader)Retrieve the serialized packet data as an input stream.static NetworkMarkergetNetworkMarker(PacketEvent event)Retrieve the network marker of a particular event without creating it.Retrieve every registered output handler in no particular order.Retrieve an immutable view of all the listeners that will be invoked once the packet has been sent or received.Retrieve a list of packets that will be schedule (in-order) when the current packet has been successfully transmitted.Retrieve a utility class for serializing and deserializing Minecraft objects.getSide()Retrieve whether or not this marker belongs to a client or a server side packet.static booleanhasOutputHandlers(NetworkMarker marker)Determine if the given marker has any output handlers.static booleanhasPostListeners(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.booleanremoveOutputHandler(PacketOutputHandler handler)Remove a given output handler from the serialization queue.booleanremovePostListener(PacketPostListener listener)Remove the first instance of the given listener.booleanWhether or not the output handlers have to write a packet header.protected abstract DataInputStreamskipHeader(DataInputStream input)Return an input stream without the header in the current packet.protected ByteBufferskipHeader(ByteBuffer buffer)Return a byte buffer without the header in the current packet.
-
Constructor Details
-
NetworkMarker
Construct a new network marker.- Parameters:
side- - which side this marker belongs to.inputBuffer- - the read serialized packet data.type- - packet type
-
NetworkMarker
Construct a new network marker.The input buffer is only non-null for client-side packets.
- Parameters:
side- - which side this marker belongs to.inputBuffer- - the read serialized packet data.type- - packet type
-
-
Method Details
-
getSide
Retrieve whether or not this marker belongs to a client or a server side packet.- Returns:
- The side the parent packet belongs to.
-
getSerializer
Retrieve a utility class for serializing and deserializing Minecraft objects.- Returns:
- Serialization utility class.
-
getInputBuffer
Retrieve the serialized packet data (excluding the header by default) from the network input stream.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.
- Returns:
- A byte buffer containing the raw packet data read from the network.
-
getInputBuffer
Retrieve the serialized packet data from the network input stream.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.
- Parameters:
excludeHeader- - whether or not to exclude the packet ID header.- Returns:
- A byte buffer containing the raw packet data read from the network.
-
getInputStream
Retrieve the serialized packet data (excluding the header by default) as an input stream.The data is exactly the same as in
getInputBuffer().- Returns:
- The incoming serialized packet data as a stream, or NULL if the packet was transmitted locally.
- See Also:
getInputBuffer()
-
getInputStream
Retrieve the serialized packet data as an input stream.The data is exactly the same as in
getInputBuffer().- Parameters:
excludeHeader- - whether or not to exclude the packet ID header.- Returns:
- The incoming serialized packet data as a stream, or NULL if the packet was transmitted locally.
- See Also:
getInputBuffer()
-
requireOutputHeader
public boolean requireOutputHeader()Whether or not the output handlers have to write a packet header.- Returns:
- TRUE if they do, FALSE otherwise.
-
addOutputHandler
Enqueue the given output handler for managing how the current packet will be written to the network stream.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.
- Parameters:
handler- - the handler that will take part in serializing the packet.- Returns:
- TRUE if it was added, FALSE if it has already been added.
-
removeOutputHandler
Remove a given output handler from the serialization queue.This can only be invoked on server side packet events.
- Parameters:
handler- - the handler to remove.- Returns:
- TRUE if the handler was removed, FALSE otherwise.
-
getOutputHandlers
Retrieve every registered output handler in no particular order.- Returns:
- Every registered output handler.
-
addPostListener
Add a listener that is invoked after a packet has been successfully sent to the client, or received by the server.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.
- Parameters:
listener- - the listener that will be invoked.- Returns:
- TRUE if it was added.
-
removePostListener
Remove the first instance of the given listener.- Parameters:
listener- - listener to remove.- Returns:
- TRUE if it was removed, FALSE otherwise.
-
getPostListeners
Retrieve an immutable view of all the listeners that will be invoked once the packet has been sent or received.- Returns:
- Every post packet listener. Never NULL.
-
getScheduledPackets
Retrieve a list of packets that will be schedule (in-order) when the current packet has been successfully transmitted.This list is modifiable.
- Returns:
- List of packets that will be scheduled.
-
skipHeader
Return a byte buffer without the header in the current packet.It's safe to modify the position of the buffer.
- Parameters:
buffer- - a read-only byte source.- Returns:
- A byte buffer without the header in the current packet.
- Throws:
IOException- If integer reading fails
-
skipHeader
Return an input stream without the header in the current packet.It's safe to modify the input stream.
- Parameters:
input- - input stream- Returns:
- An input stream without the header
- Throws:
IOException- If integer reading fails
-
addHeader
Return the byte buffer prepended with the packet header.- Parameters:
buffer- - the read-only byte buffer.type- - the current packet.- Returns:
- The byte buffer.
-
addHeader
Return the input stream prepended with the packet header.- Parameters:
input- - the input stream.type- - the current packet.- Returns:
- The byte buffer.
-
hasOutputHandlers
Determine if the given marker has any output handlers.- Parameters:
marker- - the marker to check.- Returns:
- TRUE if it does, FALSE otherwise.
-
hasPostListeners
Determine if the given marker has any post listeners.- Parameters:
marker- - the marker to check.- Returns:
- TRUE if it does, FALSE otherwise.
-
getByteBuffer
Retrieve the byte buffer stored in the given marker.- Parameters:
marker- - the marker.- Returns:
- The byte buffer, or NULL if not found.
-
getNetworkMarker
Retrieve the network marker of a particular event without creating it.This is an internal method that should not be used by API users.
- Parameters:
event- - the event.- Returns:
- The network marker.
-
readScheduledPackets
Retrieve the scheduled packets of a particular network marker without constructing the list.This is an internal method that should not be used by API users.
- Parameters:
marker- - the marker.- Returns:
- The list, or NULL if not found or initialized.
-