Class ProtocolVersion

java.lang.Object
com.viaversion.viaversion.api.protocol.version.ProtocolVersion
All Implemented Interfaces:
Comparable<ProtocolVersion>

public class ProtocolVersion extends Object implements Comparable<ProtocolVersion>
  • Field Details

  • Constructor Details

    • ProtocolVersion

      public ProtocolVersion(VersionType versionType, int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange)
      Constructs a new ProtocolVersion instance.
      Parameters:
      versionType - protocol version type
      version - protocol version
      snapshotVersion - actual snapshot protocol version, -1 if not a snapshot
      name - version name
      versionRange - range of versions that are supported by this protocol version, null if not a range
  • Method Details

    • register

      public static ProtocolVersion register(int version, String name)
    • register

      public static ProtocolVersion register(int version, int snapshotVersion, String name)
    • register

      public static ProtocolVersion register(int version, String name, @Nullable SubVersionRange versionRange)
    • register

      public static void register(ProtocolVersion protocolVersion)
      Registers a protocol version.
      Parameters:
      protocolVersion - protocol version to register
    • isRegistered

      public static boolean isRegistered(VersionType versionType, int version)
      Returns whether a protocol with the given protocol version is registered.
      Parameters:
      version - protocol version
      Returns:
      true if this protocol version has been registered
    • isRegistered

      public static boolean isRegistered(int version)
    • getProtocol

      public static @NonNull ProtocolVersion getProtocol(VersionType versionType, int version)
      Returns a ProtocolVersion instance, even if this protocol version has not been registered. See isRegistered(VersionType, int) beforehand or isKnown().
      Parameters:
      versionType - protocol version type
      version - protocol version
      Returns:
      registered or unknown ProtocolVersion
    • getProtocol

      public static @NonNull ProtocolVersion getProtocol(int version)
    • getIndex

      @Deprecated(forRemoval=true) public static int getIndex(ProtocolVersion version)
      Deprecated, for removal: This API element is subject to removal in a future version.
      comparison should be done via the comparison methods
      Returns the internal index of the stored protocol version.
      Parameters:
      version - protocol version instance
      Returns:
      internal index of the stored protocol version
    • getProtocols

      public static List<ProtocolVersion> getProtocols()
      Returns an immutable list of registered protocol versions.
      Returns:
      immutable list of registered protocol versions
    • getClosest

      public static @Nullable ProtocolVersion getClosest(String protocol)
      Returns the registered protocol version if present, else null. This accepts the actual registered names (like "1.16.4/1.16.5") as well as included versions for version ranges and wildcards.
      Parameters:
      protocol - version name, e.g. "1.16.3"
      Returns:
      registered protocol version if present, else null
    • getVersionType

      public VersionType getVersionType()
      Returns the type of version (excluding whether it is a snapshot).
      Returns:
      version type
      See Also:
    • getVersion

      public int getVersion()
      Returns the release protocol version.
      Returns:
      release version
    • getSnapshotVersion

      public int getSnapshotVersion()
      Returns the snapshot protocol version without the snapshot indicator bit if this is a snapshot protocol version.
      Returns:
      snapshot protocol version without the snapshot indicator bit
      Throws:
      IllegalArgumentException - if the version is not a snapshot version
      See Also:
    • getFullSnapshotVersion

      public int getFullSnapshotVersion()
      Returns the snapshot protocol version with the snapshot indicator bit if this is a snapshot protocol version.
      Returns:
      snapshot protocol version with the snapshot indicator bit
      Throws:
      IllegalArgumentException - if the version is not a snapshot version
      See Also:
    • getOriginalVersion

      public int getOriginalVersion()
      Returns the release version if release, snapshot version (with the snapshot indicator bit) if snapshot.
      Returns:
      release version if release, snapshot version (with the snapshot indicator bit) if snapshot
    • isKnown

      public boolean isKnown()
      Returns whether the protocol version is unknown. For checking if the protocol version is registered, use isRegistered(VersionType, int)
      Returns:
      true if the protocol version is unknown
    • isRange

      public boolean isRange()
      Returns whether the protocol includes a range of versions (but not an entire major version range), for example 1.7-1.7.5.
      Returns:
      true if the protocol includes a range of versions
      See Also:
    • getIncludedVersions

      public Set<String> getIncludedVersions()
      Returns an immutable set of all included versions if the protocol is a version range. If the protocol only includes a single Minecraft version or the entire major version as a wildcard (isVersionWildcard()), the set will only contain the string given in getName().
      Returns:
      immutable set of all included versions if the protocol is a version range
      See Also:
    • isVersionWildcard

      public boolean isVersionWildcard()
      Returns whether the protocol includes an entire major version range (for example 1.8.x).
      Returns:
      true if the protocol includes an entire major version range
    • getName

      public String getName()
      Returns the version name.
      Returns:
      version name
    • isSnapshot

      public boolean isSnapshot()
      Returns whether this represents a snapshot version.
      Returns:
      true if this represents a snapshot version, false otherwise
    • equalTo

      public boolean equalTo(ProtocolVersion other)
      Returns whether this protocol version is equal to the other protocol version.
      Parameters:
      other - other protocol version
      Returns:
      true if this protocol version is equal to the other protocol version
    • newerThan

      public boolean newerThan(ProtocolVersion other)
      Returns whether this protocol version is higher than the other protocol version.
      Parameters:
      other - other protocol version
      Returns:
      true if this protocol version is higher than the other protocol version
    • newerThanOrEqualTo

      public boolean newerThanOrEqualTo(ProtocolVersion other)
      Returns whether this protocol version is higher than or equal to the other protocol version.
      Parameters:
      other - other protocol version
      Returns:
      true if this protocol version is higher than or equal to the other protocol version
    • olderThan

      public boolean olderThan(ProtocolVersion other)
      Returns whether this protocol version is lower than the other protocol version.
      Parameters:
      other - other protocol version
      Returns:
      true if this protocol version is lower than the other protocol version
    • olderThanOrEqualTo

      public boolean olderThanOrEqualTo(ProtocolVersion other)
      Returns whether this protocol version is lower than or equal to the other protocol version.
      Parameters:
      other - other protocol version
      Returns:
      true if this protocol version is lower than or equal to the other protocol version
    • betweenInclusive

      public boolean betweenInclusive(ProtocolVersion min, ProtocolVersion max)
      Returns whether this protocol version is between the given protocol versions, inclusive.
      Parameters:
      min - minimum version
      max - maximum version
      Returns:
      true if this protocol version is between the given protocol versions, inclusive
    • betweenExclusive

      public boolean betweenExclusive(ProtocolVersion min, ProtocolVersion max)
      Returns whether this protocol version is between the given protocol versions, exclusive.
      Parameters:
      min - minimum version
      max - maximum version
      Returns:
      true if this protocol version is between the given protocol versions, exclusive
    • customComparator

      protected @Nullable Comparator<ProtocolVersion> customComparator()
      Returns a custom comparator used to compare protocol versions. Must be overridden if the version type is VersionType.SPECIAL
      Returns:
      custom comparator
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(ProtocolVersion other)
      Specified by:
      compareTo in interface Comparable<ProtocolVersion>