Add support for checking velocity support with newer paper configs

Fixes #802
This commit is contained in:
games647
2022-06-18 21:23:17 +02:00
parent 57b7fe949f
commit 6f9e8a49f1

View File

@ -33,6 +33,7 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
@ -102,18 +103,37 @@ public class BungeeManager {
private boolean isProxySupported(String className, String fieldName) { private boolean isProxySupported(String className, String fieldName) {
try { try {
return Class.forName(className).getDeclaredField(fieldName).getBoolean(null); return Class.forName(className).getDeclaredField(fieldName).getBoolean(null);
} catch (ClassNotFoundException notFoundEx) { } catch (ClassNotFoundException | NoSuchFieldException notFoundEx) {
//ignore server has no proxy support //ignore server has no proxy support
} catch (NoSuchFieldException | IllegalAccessException noSuchFieldException) { } catch (IllegalAccessException noSuchFieldException) {
plugin.getLog().warn("Cannot access proxy field", noSuchFieldException); plugin.getLog().warn("Cannot access proxy field", noSuchFieldException);
} }
return false; return false;
} }
private boolean isVelocityEnabled() {
if (isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport")) {
return true;
}
try {
Object global = Class.forName("io.papermc.paper.configuration.GlobalConfiguration").getDeclaredMethod("get").invoke(null);
Object proxiesConfiguration = global.getClass().getDeclaredField("proxies").get(global);
Object velocityConfig = proxiesConfiguration.getClass().getDeclaredField("velocity").get(proxiesConfiguration);
return velocityConfig.getClass().getDeclaredField("enabled").getBoolean(velocityConfig);
} catch (NoSuchMethodException | ClassNotFoundException | InvocationTargetException | IllegalAccessException |
NoSuchFieldException e) {
plugin.getLog().info("Errror", e);
}
return false;
}
private boolean detectProxy() { private boolean detectProxy() {
return isProxySupported("org.spigotmc.SpigotConfig", "bungee") return isProxySupported("org.spigotmc.SpigotConfig", "bungee")
|| isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport"); || isVelocityEnabled();
} }
private void registerPluginChannels() { private void registerPluginChannels() {