Class ClientVersion
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:
-
Method Summary
Modifier and TypeMethodDescriptionstatic intgetClientVersion(org.bukkit.entity.Player player) Determines the major client version for the given player based on their protocol version.static booleanisLegacy(org.bukkit.entity.Player player) Checks whether the specified player's client is considered legacy.toString()Returns a string representation of the client version.static ClientVersion[]values()Returns an array containing all registeredClientVersioninstances.
-
Method Details
-
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.
-
values
Returns an array containing all registeredClientVersioninstances.- Returns:
- an array of
ClientVersionobjects
-
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 benull- Returns:
- the major client version number, or
0for 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:
trueif the player's client is legacy;falseotherwise
-