java.lang.Object
tech.guilhermekaua.spigotboot.core.spigot.version.ServerVersion
All Implemented Interfaces:
Comparable<ServerVersion>

public final class ServerVersion extends Object implements Comparable<ServerVersion>
Immutable, comparable view of the running Minecraft server's version.

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 Details

    • current

      @NotNull public static @NotNull ServerVersion current()
      Returns:
      the version of the running server, computed once and cached. Never throws — an unparseable version yields a ServerVersion whose components are -1.
    • getMajor

      public int getMajor()
      Returns:
      the major version component (the 1 in 1.21.4), or -1 if the version could not be parsed
    • getMinor

      public int getMinor()
      Returns:
      the minor version component (the 21 in 1.21.4), or -1 if the version could not be parsed
    • getPatch

      public int getPatch()
      Returns:
      the patch version component (the 4 in 1.21.4; 0 when the version omits a patch), or -1 if the version could not be parsed
    • getRawVersion

      @NotNull public @NotNull String getRawVersion()
      Returns:
      the raw Bukkit.getBukkitVersion() string this was parsed from (empty string when the source was null)
    • getNmsPackageSuffix

      @NotNull public @NotNull Optional<String> getNmsPackageSuffix()
      Returns:
      the legacy CraftBukkit package suffix (e.g. v1_19_R3), or an empty Optional on un-versioned modern servers
    • hasVersionedNmsPackage

      public boolean hasVersionedNmsPackage()
      Returns:
      true when the server relocates CraftBukkit into a versioned vX_Y_RZ package (pre-Paper-1.20.5 style)
    • isAtLeast

      public boolean isAtLeast(int major, int minor)
      Parameters:
      major - the major version to compare against
      minor - the minor version to compare against
      Returns:
      true if this version is at least major.minor.0; always false when this version could not be parsed
    • isAtLeast

      public boolean isAtLeast(int major, int minor, int patch)
      Parameters:
      major - the major version to compare against
      minor - the minor version to compare against
      patch - the patch version to compare against
      Returns:
      true if this version is at least major.minor.patch; always false when this version could not be parsed
    • isOlderThan

      public boolean isOlderThan(int major, int minor)
      Parameters:
      major - the major version to compare against
      minor - the minor version to compare against
      Returns:
      the logical complement of isAtLeast(int, int)true when this version is strictly older than major.minor.0 (and when it is unparseable)
    • compareTo

      public int compareTo(@NotNull @NotNull ServerVersion other)
      Specified by:
      compareTo in interface Comparable<ServerVersion>
    • 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