Record Class ProtocolVersion

java.lang.Object
java.lang.Record
de.craftsblock.craftsnet.api.utils.ProtocolVersion
All Implemented Interfaces:
Comparable<ProtocolVersion>

public record ProtocolVersion(@NotNull Scheme scheme, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int major, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int minor) extends Record implements Comparable<ProtocolVersion>
Represents a specific version of a protocol, including its scheme, major version, and minor version.

This class is useful for managing different protocol versions and supports comparison, parsing, and equality checks.

Since:
3.3.2-SNAPSHOT
  • Constructor Summary

    Constructors
    Constructor
    Description
    ProtocolVersion(@NotNull Scheme scheme, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int major, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int minor)
    Constructs a new ProtocolVersion instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(@NotNull ProtocolVersion that)
    Compares this protocol version to another.
    boolean
    Checks if this protocol version is equal to another object.
    int
    Generates a hash code for this protocol version.
    int
    Returns the major version number.
    int
    Returns the minor version number.
    parse(@NotNull Scheme scheme, @NotNull String version)
    Parses a protocol version string using the default dot separator (".").
    parse(@NotNull Scheme scheme, @NotNull String version, @NotNull String separator)
    Parses a protocol version string using a custom separator.
    Returns the scheme associated with this protocol version.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ProtocolVersion

      public ProtocolVersion(@NotNull @NotNull Scheme scheme, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int major, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int minor)
      Constructs a new ProtocolVersion instance.
      Parameters:
      scheme - The protocol scheme.
      major - The major version number (must be non-negative).
      minor - The minor version number (must be non-negative).
  • Method Details

    • scheme

      public Scheme scheme()
      Returns the scheme associated with this protocol version.
      Returns:
      The Scheme of the protocol.
    • major

      public int major()
      Returns the major version number.
      Returns:
      The major version.
    • minor

      public int minor()
      Returns the minor version number.
      Returns:
      The minor version.
    • compareTo

      public int compareTo(@NotNull @NotNull ProtocolVersion that)
      Compares this protocol version to another.

      A protocol version is considered greater if its major version is higher. If major versions are equal, the minor version is compared.

      Specified by:
      compareTo in interface Comparable<ProtocolVersion>
      Parameters:
      that - The ProtocolVersion to compare against.
      Returns:
      -1 if this version is older, 1 if it is newer, and 0 if they are equal.
      Throws:
      IllegalStateException - If the schemes are not from the same family.
    • equals

      public boolean equals(Object o)
      Checks if this protocol version is equal to another object.
      Specified by:
      equals in class Record
      Parameters:
      o - The object to compare against.
      Returns:
      true if both objects represent the same protocol version, otherwise false.
    • hashCode

      public int hashCode()
      Generates a hash code for this protocol version.
      Specified by:
      hashCode in class Record
      Returns:
      The hash code value.
    • parse

      public static ProtocolVersion parse(@NotNull @NotNull Scheme scheme, @NotNull @NotNull String version)
      Parses a protocol version string using the default dot separator (".").
      Parameters:
      scheme - The protocol scheme.
      version - The version string.
      Returns:
      A new ProtocolVersion instance.
      Throws:
      RuntimeException - If the version string is not a valid format.
    • parse

      public static ProtocolVersion parse(@NotNull @NotNull Scheme scheme, @NotNull @NotNull String version, @NotNull @NotNull String separator)
      Parses a protocol version string using a custom separator.
      Parameters:
      scheme - The protocol scheme.
      version - The version string.
      separator - The separator used in the version string.
      Returns:
      A new ProtocolVersion instance.
      Throws:
      RuntimeException - If the version string is not a valid format.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object