Package dev.jorel.commandapi.network
Enum Class CommandAPIProtocol
- All Implemented Interfaces:
Serializable,Comparable<CommandAPIProtocol>,Constable
An enum that defines the different channels of the network protocol of the CommandAPI. It handles converting bytes off
the network into
CommandAPIPackets.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionACommandAPIProtocolfor thecommandapi:handshakechannel.ACommandAPIProtocolfor thecommandapi:playchannel. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe current version of the protocol. -
Method Summary
Modifier and TypeMethodDescriptioncreatePacket(int id, FriendlyByteBuffer buffer) Reads aFriendlyByteBufferto create aCommandAPIPacket.Set<Class<? extends CommandAPIPacket>> intgetId(Class<? extends CommandAPIPacket> clazz) Gets the id for the givenCommandAPIPacketclass.static CommandAPIProtocolgetProtocolForChannel(String channelIdentifier) Gets theCommandAPIProtocolthat handlesCommandAPIPackets on the given channel.static CommandAPIProtocolgetProtocolForPacket(Class<? extends CommandAPIPacket> clazz) Gets theCommandAPIProtocolthat can send the givenCommandAPIPacketpacket type.static CommandAPIProtocolReturns the enum constant of this class with the specified name.static CommandAPIProtocol[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
HANDSHAKE
ACommandAPIProtocolfor thecommandapi:handshakechannel. The packets in this protocol help instances of the CommandAPI communicate the network data they understand. -
PLAY
ACommandAPIProtocolfor thecommandapi:playchannel. The packets in this protocol handle events that happen while a server is running.
-
-
Field Details
-
PROTOCOL_VERSION
public static final int PROTOCOL_VERSIONThe current version of the protocol. This should be incremented when the protocol is updated to indicate a large change. A connection without a communicating instance of the CommandAPI (either no CommandAPI instance or a version before 10.0.0) should be treated as protocol version 0.This version number is used to communicate the capabilities of the CommandAPI instance on the other end of the connection. The instance with the higher version should take responsibility to not send anything the lower version cannot understand.
For example, say PV2 adds packet A, which PV1 doesn't know about. When PV2 communicates with PV1, it should not send packet A, since PV1 would not know what to do with that packet.
- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getAllChannelIdentifiers
-
getProtocolForPacket
@Nullable public static CommandAPIProtocol getProtocolForPacket(Class<? extends CommandAPIPacket> clazz) Gets theCommandAPIProtocolthat can send the givenCommandAPIPacketpacket type.- Parameters:
clazz- The packet type.- Returns:
- The protocol for this packet, or null if the packet is unknown.
-
getProtocolForChannel
Gets theCommandAPIProtocolthat handlesCommandAPIPackets on the given channel.- Parameters:
channelIdentifier- The channel identifier as a String.- Returns:
- The protocol for this channel, or null if the channel is unknown.
-
getChannelIdentifier
- Returns:
- The identifier for the plugin message channel of this protocol.
-
getAllPacketTypes
- Returns:
- A set of all
CommandAPIPacketclasses that can be sent on this protocol.
-
createPacket
Reads aFriendlyByteBufferto create aCommandAPIPacket.- Parameters:
id- The id for this packet type. Used to select the appropriate deserialize method.buffer- The bytes of this packet.- Returns:
- The deserialized packet, or null if the given id could not be found.
- Throws:
IllegalStateException- when there is a problem deserializing the packet.
-
getId
Gets the id for the givenCommandAPIPacketclass.- Parameters:
clazz- The packet type.- Returns:
- The id of the given packet, or -1 if the packet could not be found.
-