diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BungeeManager.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BungeeManager.java index a47715aa..49ff879c 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BungeeManager.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BungeeManager.java @@ -33,6 +33,7 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; @@ -102,18 +103,37 @@ public class BungeeManager { private boolean isProxySupported(String className, String fieldName) { try { return Class.forName(className).getDeclaredField(fieldName).getBoolean(null); - } catch (ClassNotFoundException notFoundEx) { + } catch (ClassNotFoundException | NoSuchFieldException notFoundEx) { //ignore server has no proxy support - } catch (NoSuchFieldException | IllegalAccessException noSuchFieldException) { + } catch (IllegalAccessException noSuchFieldException) { plugin.getLog().warn("Cannot access proxy field", noSuchFieldException); } 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() { return isProxySupported("org.spigotmc.SpigotConfig", "bungee") - || isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport"); + || isVelocityEnabled(); } private void registerPluginChannels() {