3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-16 04:50:08 +01:00

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
Dieser Commit ist enthalten in:
EnZaXD 2024-07-27 19:53:33 +02:00 committet von GitHub
Ursprung b1f64fd081
Commit c9d6fbfcd0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -39,6 +39,20 @@ public interface VersionProvider extends Provider {
return null; 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. * Returns the closest server protocol version to the user's protocol version.
* On non-proxy servers, this returns the actual server version. * On non-proxy servers, this returns the actual server version.