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
ConstructorsConstructorDescriptionProtocolVersion(@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 newProtocolVersioninstance. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(@NotNull ProtocolVersion that) Compares this protocol version to another.booleanChecks if this protocol version is equal to another object.inthashCode()Generates a hash code for this protocol version.intmajor()Returns the major version number.intminor()Returns the minor version number.static ProtocolVersionParses a protocol version string using the default dot separator (".").static ProtocolVersionParses a protocol version string using a custom separator.scheme()Returns the scheme associated with this protocol version.final StringtoString()Returns a string representation of this record class.
-
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 newProtocolVersioninstance.- 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
Returns the scheme associated with this protocol version.- Returns:
- The
Schemeof 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
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:
compareToin interfaceComparable<ProtocolVersion>- Parameters:
that- TheProtocolVersionto compare against.- Returns:
-1if this version is older,1if it is newer, and0if they are equal.- Throws:
IllegalStateException- If the schemes are not from the same family.
-
equals
Checks if this protocol version is equal to another object. -
hashCode
public int hashCode()Generates a hash code for this protocol version. -
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
ProtocolVersioninstance. - 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
ProtocolVersioninstance. - Throws:
RuntimeException- If the version string is not a valid format.
-
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.
-