Class MinecraftVersion
The library works with two families of version numbers:
- Classic Java release numbers such as
1.20.6or1.21.11. - Year-based drop numbers such as
25.2or26.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
ConstructorsConstructorDescriptionMinecraftVersion(boolean classic, int major, int minor, int patch) Creates an immutable version descriptor from already parsed numeric parts. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable MinecraftVersionfromProtocol(int protocol) Resolves a canonical version for the supplied protocol number.intgetMajor()The first numeric segment of the parsed version.intgetMinor()The second numeric segment of the parsed version.intgetPatch()The optional third numeric segment of the parsed version.The published network protocol number for this exact identifier, ornullwhen the identifier is only a projected alias and not a known exact release in the built-in tables.@NotNull StringReturns the numeric version string without adding any descriptive prefix.booleanWhether this instance represents a classic Java release number.static @NotNull MinecraftVersionParses a textual version into aMinecraftVersion.static @Nullable IntegerprotocolForIdentifier(@NotNull String identifier) Resolves the published protocol for an arbitrary Mojang version identifier.booleanWhether this version supports RGB / hex chat colors.toString()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.
-
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
classicflag 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()returnsnull.- Parameters:
classic- whether this identifier belongs to the classic Java release familymajor- first numeric segmentminor- second numeric segmentpatch- third numeric segment, or0when omitted
-
-
Method Details
-
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.16line, which corresponds to the year-based drop line20.1. Any later version in either family keeps that support.- Returns:
truewhen hex colors are supported
-
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". -
parse
Parses a textual version into aMinecraftVersion.The parser accepts only dotted numeric values with two or three segments. It then classifies the number using the library's supported families:
1.xor1.x.yis treated as a classic Java release number.11.xthrough99.xis 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 benull- Returns:
- parsed immutable representation of the supplied version
- Throws:
NullPointerException- iftextisnullIllegalArgumentException- 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 as26.2-snapshot-3are looked up through the separate published snapshot protocol table.This method deliberately returns
nullfor projected future releases like26.2or1.22.3until Mojang publishes an exact release protocol.- Parameters:
identifier- dotted release/drop version or Mojang snapshot id- Returns:
- published protocol when known, otherwise
null
-
versionsForProtocol
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
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
754resolves to1.16.5.- Parameters:
protocol- protocol number to resolve- Returns:
- newest known matching version, or
nullwhen 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
The published network protocol number for this exact identifier, ornullwhen 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.22or1.23.
-