From 15fee9293739b89f602a7b6ec3cee1cc8580edd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Old=C5=99ich=20Jedli=C4=8Dka?= Date: Thu, 18 Nov 2021 22:49:01 +0100 Subject: [PATCH] Detect enabled Velocity support in server --- .../games647/fastlogin/bukkit/BungeeManager.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 46321d34..95cd70da 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 @@ -88,9 +88,9 @@ public class BungeeManager { public void initialize() { try { - enabled = detectBungeeCord(); + enabled = detectProxy(); } catch (Exception ex) { - plugin.getLog().warn("Cannot check bungeecord support. Fallback to non-bungee mode", ex); + plugin.getLog().warn("Cannot check proxy support. Fallback to non-proxy mode", ex); } if (enabled) { @@ -99,18 +99,22 @@ public class BungeeManager { } } - private boolean detectBungeeCord() throws Exception { + private boolean isProxySupported(String className, String fieldName) throws Exception { try { - enabled = Class.forName("org.spigotmc.SpigotConfig").getDeclaredField("bungee").getBoolean(null); - return enabled; + return Class.forName(className).getDeclaredField(fieldName).getBoolean(null); } catch (ClassNotFoundException notFoundEx) { - //ignore server has no bungee support + //ignore server has no proxy support return false; } catch (Exception ex) { throw ex; } } + private boolean detectProxy() throws Exception { + return isProxySupported("org.spigotmc.SpigotConfig", "bungee") + || isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport"); + } + private void registerPluginChannels() { Server server = Bukkit.getServer();