Class ProtocolVersion


  • public class ProtocolVersion
    extends java.lang.Object
    • Constructor Detail

      • ProtocolVersion

        public ProtocolVersion​(int version,
                               java.lang.String name)
        Parameters:
        version - protocol version
        name - version name
      • ProtocolVersion

        public ProtocolVersion​(int version,
                               int snapshotVersion,
                               java.lang.String name,
                               @Nullable VersionRange versionRange)
        Parameters:
        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 Detail

      • register

        public static ProtocolVersion register​(int version,
                                               java.lang.String name)
      • register

        public static ProtocolVersion register​(int version,
                                               int snapshotVersion,
                                               java.lang.String name)
      • register

        public static ProtocolVersion register​(int version,
                                               int snapshotVersion,
                                               java.lang.String name,
                                               @Nullable VersionRange versionRange)
        Registers a protocol version.
        Parameters:
        version - release protocol version
        snapshotVersion - snapshot protocol version, or -1 if not a snapshot
        name - version name
        versionRange - range of versions that are supported by this protocol version, null if not a range
        Returns:
        registered ProtocolVersion
      • isRegistered

        public static boolean isRegistered​(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
      • getIndex

        public static int getIndex​(ProtocolVersion version)
        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 java.util.List<ProtocolVersion> getProtocols()
        Returns an immutable list of registered protocol versions.
        Returns:
        immutable list of registered protocol versions
      • getClosest

        public static @Nullable ProtocolVersion getClosest​(java.lang.String protocol)
        Returns the registered protocol version if present, else null. This accepts the actual registered names (like "1.16.4/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
      • 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:
        java.lang.IllegalArgumentException - if the version if not a snapshot version
        See Also:
        isSnapshot()
      • 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:
        java.lang.IllegalArgumentException - if the version if not a snapshot version
        See Also:
        isSnapshot()
      • 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 is set. Should only be unknown for unregistered protocols returned by getProtocol(int).
        Returns:
        true if the protocol is set
      • 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()
      • getIncludedVersions

        public java.util.Set<java.lang.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:
        isRange()
      • 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 java.lang.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
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object