Add VersionProvider#getServerProtocol (#4049)

Most platforms won't ever throw an error and usually ViaVersion shouldn't even load when the server version can't be found. Therefore, I added this bouncer function, so I don't need to try catch my code in ViaLoader/VFP where an exception is never thrown
This commit is contained in:
EnZaXD 2024-07-27 19:53:33 +02:00 committed by GitHub
parent b1f64fd081
commit c9d6fbfcd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,6 +39,20 @@ public interface VersionProvider extends Provider {
return null;
}
/**
* Calls {@link #getClosestServerProtocol(UserConnection)} and catches any exceptions by returning null.
*
* @param connection connection
* @return closest server protocol version to the user's protocol version
*/
default ProtocolVersion getServerProtocol(UserConnection connection) {
try {
return getClosestServerProtocol(connection);
} catch (Exception e) {
return null;
}
}
/**
* Returns the closest server protocol version to the user's protocol version.
* On non-proxy servers, this returns the actual server version.