Enum Class CommandAPIProtocol

java.lang.Object
java.lang.Enum<CommandAPIProtocol>
dev.jorel.commandapi.network.CommandAPIProtocol
All Implemented Interfaces:
Serializable, Comparable<CommandAPIProtocol>, Constable

public enum CommandAPIProtocol extends Enum<CommandAPIProtocol>
An enum that defines the different channels of the network protocol of the CommandAPI. It handles converting bytes off the network into CommandAPIPackets.
  • Enum Constant Details

    • HANDSHAKE

      public static final CommandAPIProtocol HANDSHAKE
      A CommandAPIProtocol for the commandapi:handshake channel. The packets in this protocol help instances of the CommandAPI communicate the network data they understand.
    • PLAY

      public static final CommandAPIProtocol PLAY
      A CommandAPIProtocol for the commandapi:play channel. The packets in this protocol handle events that happen while a server is running.
  • Field Details

    • PROTOCOL_VERSION

      public static final int PROTOCOL_VERSION
      The 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

      public static CommandAPIProtocol[] 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

      public static CommandAPIProtocol valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getAllChannelIdentifiers

      public static Set<String> getAllChannelIdentifiers()
      Returns:
      A Set of all the channel identifiers used by this protocol.
    • getProtocolForPacket

      @Nullable public static CommandAPIProtocol getProtocolForPacket(Class<? extends CommandAPIPacket> clazz)
      Gets the CommandAPIProtocol that can send the given CommandAPIPacket packet type.
      Parameters:
      clazz - The packet type.
      Returns:
      The protocol for this packet, or null if the packet is unknown.
    • getProtocolForChannel

      @Nullable public static CommandAPIProtocol getProtocolForChannel(String channelIdentifier)
      Gets the CommandAPIProtocol that handles CommandAPIPackets 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

      public String getChannelIdentifier()
      Returns:
      The identifier for the plugin message channel of this protocol.
    • getAllPacketTypes

      public Set<Class<? extends CommandAPIPacket>> getAllPacketTypes()
      Returns:
      A set of all CommandAPIPacket classes that can be sent on this protocol.
    • createPacket

      @Nullable public CommandAPIPacket createPacket(int id, FriendlyByteBuffer buffer)
      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

      public int getId(Class<? extends CommandAPIPacket> clazz)
      Gets the id for the given CommandAPIPacket class.
      Parameters:
      clazz - The packet type.
      Returns:
      The id of the given packet, or -1 if the packet could not be found.