Fix SpongeViaInjector#getServerProtocolVersion() for Sponge API-10+ (#3337)

This commit is contained in:
Ossi Erkkilä 2023-06-09 12:29:55 +03:00 committed by GitHub
parent 28ba4afc27
commit bf825d5ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,7 +32,13 @@ public class SpongeViaInjector extends LegacyViaInjector {
@Override
public int getServerProtocolVersion() throws ReflectiveOperationException {
MinecraftVersion version = Sponge.platform().minecraftVersion();
return (int) version.getClass().getDeclaredMethod("getProtocol").invoke(version);
// 'protocolVersion' method was exposed to the API in a 1.19.4 build and 'getProtocol' no longer exists in the impl.
try {
return (int) version.getClass().getDeclaredMethod("getProtocol").invoke(version);
} catch (NoSuchMethodException e) {
return (int) version.getClass().getDeclaredMethod("protocolVersion").invoke(version);
}
}
@Override