From c9d6fbfcd0dc6a62e4b665fd54ae98d3aa26ac08 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Sat, 27 Jul 2024 19:53:33 +0200 Subject: [PATCH] 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 --- .../api/protocol/version/VersionProvider.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/VersionProvider.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/VersionProvider.java index 347d0ae0f..06f1fd76c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/VersionProvider.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/VersionProvider.java @@ -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.