Class ServerVersion
- All Implemented Interfaces:
Comparable<ServerVersion>
The version triple is parsed from Bukkit.getBukkitVersion() (e.g.
"1.21.4-R0.1-SNAPSHOT") with an open numeric scheme — every major.minor.patch
is accepted, so no per-release code change is ever needed. The optional legacy CraftBukkit
package suffix (e.g. v1_19_R3) is also captured; it is empty on modern un-versioned
servers (Paper 1.20.5+) and on renumbered schemes.
Ordering and equality are defined over the (major, minor, patch) triple only; the
package suffix is metadata and does not participate.
When the version string cannot be parsed the components are -1 and
isAtLeast(int, int) always returns false; construction never throws. As a
consequence an unparseable version also reports isOlderThan(int, int) true for
every argument, so code gating behavior on the running version should prefer
isAtLeast(int, int) (which fails safe to false) over isOlderThan. Under
compareTo(ServerVersion) an unparseable version sorts below every parseable one.
-
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(@NotNull ServerVersion other) static @NotNull ServerVersioncurrent()booleanintgetMajor()intgetMinor()intgetPatch()@NotNull StringinthashCode()booleanbooleanisAtLeast(int major, int minor) booleanisAtLeast(int major, int minor, int patch) booleanisOlderThan(int major, int minor) toString()
-
Method Details
-
current
- Returns:
- the version of the running server, computed once and cached. Never throws — an
unparseable version yields a
ServerVersionwhose components are-1.
-
getMajor
public int getMajor()- Returns:
- the major version component (the
1in1.21.4), or-1if the version could not be parsed
-
getMinor
public int getMinor()- Returns:
- the minor version component (the
21in1.21.4), or-1if the version could not be parsed
-
getPatch
public int getPatch()- Returns:
- the patch version component (the
4in1.21.4;0when the version omits a patch), or-1if the version could not be parsed
-
getRawVersion
- Returns:
- the raw
Bukkit.getBukkitVersion()string this was parsed from (empty string when the source wasnull)
-
getNmsPackageSuffix
- Returns:
- the legacy CraftBukkit package suffix (e.g.
v1_19_R3), or an emptyOptionalon un-versioned modern servers
-
hasVersionedNmsPackage
public boolean hasVersionedNmsPackage()- Returns:
truewhen the server relocates CraftBukkit into a versionedvX_Y_RZpackage (pre-Paper-1.20.5 style)
-
isAtLeast
public boolean isAtLeast(int major, int minor) - Parameters:
major- the major version to compare againstminor- the minor version to compare against- Returns:
trueif this version is at leastmajor.minor.0; alwaysfalsewhen this version could not be parsed
-
isAtLeast
public boolean isAtLeast(int major, int minor, int patch) - Parameters:
major- the major version to compare againstminor- the minor version to compare againstpatch- the patch version to compare against- Returns:
trueif this version is at leastmajor.minor.patch; alwaysfalsewhen this version could not be parsed
-
isOlderThan
public boolean isOlderThan(int major, int minor) - Parameters:
major- the major version to compare againstminor- the minor version to compare against- Returns:
- the logical complement of
isAtLeast(int, int)—truewhen this version is strictly older thanmajor.minor.0(and when it is unparseable)
-
compareTo
- Specified by:
compareToin interfaceComparable<ServerVersion>
-
equals
-
hashCode
public int hashCode() -
toString
-