Class Server

java.lang.Object
valorless.valorlessutils.Server

public class Server extends Object
Utility class for handling and comparing Minecraft server versions.

Provides methods to resolve the current server version, compare versions, and check version relationships (higher/equal). Versions are represented as the Server.Version enum.

Example versions: 1_19_4, 1_21, etc.
  • Constructor Details

    • Server

      public Server()
  • Method Details

    • VersionCompare

      public static int VersionCompare(Server.Version version, Server.Version compareTo)
      Compares two Server.Version enums based on their ordinal order.

      Useful for determining if one version comes before, after, or is equal to another.

      Parameters:
      version - The version to compare.
      compareTo - The version to compare against.
      Returns:
      -1 if version is lower than compareTo, 1 if version is higher, or 0 if equal.
    • ResolveVersion

      public static Server.Version ResolveVersion()
      Attempts to resolve the current running server version.

      Uses Bukkit.getBukkitVersion() to determine the server version and converts it to the corresponding Server.Version enum value.

      Returns:
      The resolved Server.Version, or Server.Version.NULL if the resolution fails.
    • VersionHigherOrEqualTo

      public static Boolean VersionHigherOrEqualTo(Server.Version version)
      Checks if the current server version is higher than or equal to a specified version.
      Parameters:
      version - The version to compare against.
      Returns:
      true if the current server version is higher than or equal to version; false otherwise.
    • VersionHigherThan

      public static Boolean VersionHigherThan(Server.Version version)
      Checks if the current server version is strictly higher than a specified version.
      Parameters:
      version - The version to compare against.
      Returns:
      true if the current server version is higher than version; false otherwise.
    • VersionLowerOrEqualTo

      public static Boolean VersionLowerOrEqualTo(Server.Version version)
      Checks if the current server version is lower than or equal to a specified version.
      Parameters:
      version - The version to compare against.
      Returns:
      true if the current server version is lower than or equal to version; false otherwise.
    • VersionLowerThan

      public static Boolean VersionLowerThan(Server.Version version)
      Checks if the current server version is strictly lower than a specified version.
      Parameters:
      version - The version to compare against.
      Returns:
      true if the current server version is lower than version; false otherwise.
    • VersionEqualTo

      public static Boolean VersionEqualTo(Server.Version version)
      Checks if the current server version is exactly equal to a specified version.
      Parameters:
      version - The version to compare against.
      Returns:
      true if the current server version equals version; false otherwise.
    • isServerLikelyLoaded

      public static boolean isServerLikelyLoaded()
      Determines if the server has been fully loaded, hinting that the plugin was most likely enabled after startup rather than on initial server start.

      Uses a 60-second threshold to detect if the server has been running long enough to be considered fully loaded.

      Returns:
      true if the server has been up longer than 60 seconds; false otherwise
    • serverHasBeenUpLongerThan

      public static boolean serverHasBeenUpLongerThan(long millis)
      Checks if the server JVM has been running longer than the specified milliseconds.

      Used to infer whether the server is fully loaded by checking the JVM uptime against a threshold value.

      Parameters:
      millis - the threshold in milliseconds to check against
      Returns:
      true if the server uptime exceeds the specified threshold; false otherwise