Class ClientVersion

java.lang.Object
me.croabeast.prismatic.ClientVersion

public final class ClientVersion extends Object
Provides a mapping between Minecraft client protocol versions and a simplified major version.

The ClientVersion class is used to determine the major client version from a player's protocol version, which is helpful when implementing version-specific features or handling legacy clients. It maintains an internal list of ClientVersion instances, each corresponding to a range of protocol numbers. If no matching version is found, it returns an unknown version.

This class also offers utility methods to check if a client is considered legacy.

Example usage:


 int majorVersion = ClientVersion.getClientVersion(player);
 boolean isLegacy = ClientVersion.isLegacy(player);
 System.out.println("Player client major version: " + majorVersion);
 

See Also:
  • Via
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    getClientVersion(org.bukkit.entity.Player player)
    Determines the major client version for the given player based on their protocol version.
    static boolean
    isLegacy(org.bukkit.entity.Player player)
    Checks whether the specified player's client is considered legacy.
    Returns a string representation of the client version.
    static ClientVersion[]
    Returns an array containing all registered ClientVersion instances.

    Methods inherited from class java.lang.Object

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

    • toString

      public String toString()
      Returns a string representation of the client version.

      For unknown versions, it returns "UNKNOWN_CLIENT:0". Otherwise, it returns "CLIENT:" followed by the major version number.

      Overrides:
      toString in class Object
      Returns:
      a string representing the client version
    • values

      public static ClientVersion[] values()
      Returns an array containing all registered ClientVersion instances.
      Returns:
      an array of ClientVersion objects
    • getClientVersion

      public static int getClientVersion(org.bukkit.entity.Player player)
      Determines the major client version for the given player based on their protocol version.

      If ViaVersion is not enabled or the player is null, the server's version is returned. Otherwise, the player's protocol version is retrieved, and the corresponding major version is determined.

      Parameters:
      player - the player whose client version is to be determined; may be null
      Returns:
      the major client version number, or 0 for unknown versions
    • isLegacy

      public static boolean isLegacy(org.bukkit.entity.Player player)
      Checks whether the specified player's client is considered legacy.

      A legacy client is defined as one with a major version of 15 or lower.

      Parameters:
      player - the player whose client version is to be checked
      Returns:
      true if the player's client is legacy; false otherwise