Class MinecraftVersion

java.lang.Object
me.croabeast.vnc.MinecraftVersion

public final class MinecraftVersion extends Object
Immutable representation of a Minecraft version identifier.

The library works with two families of version numbers:

  • Classic Java release numbers such as 1.20.6 or 1.21.11.
  • Year-based drop numbers such as 25.2 or 26.1.1.

A MinecraftVersion stores only the parsed numeric structure and a flag that tells callers which family the original value belongs to. It also exposes the published network protocol number when the parsed identifier corresponds to an exact release covered by the library's built-in tables.

Projected aliases that depend on a conversion scheme, such as 1.22 under VersionScheme.MOJANG or 1.23 under VersionScheme.CROA_CUSTOM, intentionally do not invent a protocol number here. Conversion rules remain delegated to VersionScheme implementations so this value object can stay scheme-agnostic.

  • Constructor Summary

    Constructors
    Constructor
    Description
    MinecraftVersion(boolean classic, int major, int minor, int patch)
    Creates an immutable version descriptor from already parsed numeric parts.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable MinecraftVersion
    fromProtocol(int protocol)
    Resolves a canonical version for the supplied protocol number.
    int
    The first numeric segment of the parsed version.
    int
    The second numeric segment of the parsed version.
    int
    The optional third numeric segment of the parsed version.
    The published network protocol number for this exact identifier, or null when the identifier is only a projected alias and not a known exact release in the built-in tables.
    @NotNull String
    Returns the numeric version string without adding any descriptive prefix.
    boolean
    Whether this instance represents a classic Java release number.
    static @NotNull MinecraftVersion
    parse(@NotNull String text)
    Parses a textual version into a MinecraftVersion.
    static @Nullable Integer
    protocolForIdentifier(@NotNull String identifier)
    Resolves the published protocol for an arbitrary Mojang version identifier.
    boolean
    Whether this version supports RGB / hex chat colors.
    Returns a readable description that includes the numbering family and the normalized numeric value.
    static @NotNull List<MinecraftVersion>
    versionsForProtocol(int protocol)
    Returns every known version that uses the supplied protocol number.

    Methods inherited from class java.lang.Object

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

    • MinecraftVersion

      public MinecraftVersion(boolean classic, int major, int minor, int patch)
      Creates an immutable version descriptor from already parsed numeric parts.

      The constructor does not infer the numbering family. Callers are responsible for supplying the correct classic flag for the numeric segments they provide.

      When the supplied identifier matches an exact release known by the built-in tables, the corresponding protocol number is resolved automatically. Otherwise, getProtocol() returns null.

      Parameters:
      classic - whether this identifier belongs to the classic Java release family
      major - first numeric segment
      minor - second numeric segment
      patch - third numeric segment, or 0 when omitted
  • Method Details

    • getVersion

      @NotNull public @NotNull String getVersion()
      Returns the numeric version string without adding any descriptive prefix.

      The returned text preserves the same three-segment model used by this value object: the patch segment is omitted when it is 0.

      Returns:
      normalized numeric version text
    • supportsHex

      public boolean supportsHex()
      Whether this version supports RGB / hex chat colors.

      Hex colors were introduced in the classic 1.16 line, which corresponds to the year-based drop line 20.1. Any later version in either family keeps that support.

      Returns:
      true when hex colors are supported
    • toString

      public String toString()
      Returns a readable description that includes the numbering family and the normalized numeric value.

      Examples: "classic 1.21.6" or "drop 25.2.1".

      Overrides:
      toString in class Object
      Returns:
      descriptive representation of this instance
    • parse

      @NotNull public static @NotNull MinecraftVersion parse(@NotNull @NotNull String text)
      Parses a textual version into a MinecraftVersion.

      The parser accepts only dotted numeric values with two or three segments. It then classifies the number using the library's supported families:

      • 1.x or 1.x.y is treated as a classic Java release number.
      • 11.x through 99.x is treated as a year-based drop number.

      Whitespace around the input is ignored. Any other shape is rejected so the conversion layer can operate on a well-defined model.

      Parameters:
      text - version text to parse; must not be null
      Returns:
      parsed immutable representation of the supplied version
      Throws:
      NullPointerException - if text is null
      IllegalArgumentException - if the text does not match a supported version format
    • protocolForIdentifier

      @Nullable public static @Nullable Integer protocolForIdentifier(@NotNull @NotNull String identifier)
      Resolves the published protocol for an arbitrary Mojang version identifier.

      Dotted classic/drop identifiers are resolved through parse(String) and the built-in release tables. Snapshot identifiers such as 26.2-snapshot-3 are looked up through the separate published snapshot protocol table.

      This method deliberately returns null for projected future releases like 26.2 or 1.22.3 until Mojang publishes an exact release protocol.

      Parameters:
      identifier - dotted release/drop version or Mojang snapshot id
      Returns:
      published protocol when known, otherwise null
    • versionsForProtocol

      @NotNull public static @NotNull List<MinecraftVersion> versionsForProtocol(int protocol)
      Returns every known version that uses the supplied protocol number.

      The returned list is ordered from the earliest known matching release to the latest one. When the protocol only exists in Mojang's year-based drop numbering, the list contains the corresponding projected classic aliases produced by VersionScheme.MOJANG.

      Parameters:
      protocol - protocol number to inspect
      Returns:
      immutable list of known versions for that protocol; empty when none are known
    • fromProtocol

      @Nullable public static @Nullable MinecraftVersion fromProtocol(int protocol)
      Resolves a canonical version for the supplied protocol number.

      Because Mojang often reused the same protocol across multiple hotfix releases, the resolver returns the newest known matching version. For example, protocol 754 resolves to 1.16.5.

      Parameters:
      protocol - protocol number to resolve
      Returns:
      newest known matching version, or null when the protocol is unknown
    • isClassic

      public boolean isClassic()
      Whether this instance represents a classic Java release number.
    • getMajor

      public int getMajor()
      The first numeric segment of the parsed version.
    • getMinor

      public int getMinor()
      The second numeric segment of the parsed version.
    • getPatch

      public int getPatch()
      The optional third numeric segment of the parsed version.
    • getProtocol

      public Integer getProtocol()
      The published network protocol number for this exact identifier, or null when the identifier is only a projected alias and not a known exact release in the built-in tables.

      The value is available for exact historic mappings and for official drop identifiers that appear in the built-in protocol table. It is absent for scheme-dependent projected aliases such as 1.22 or 1.23.