From 8f680343086d08d228fd4eb86d74f80526a5205e Mon Sep 17 00:00:00 2001 From: THEMPGUYActions <324142696+THEMPGUYActions@users.noreply.github.com> Date: Tue, 20 Oct 2026 19:46:38 +0000 Subject: [PATCH 1/3] Register Floodgate bypass after plugin enable --- bungeeguard-backend/pom.xml | 2 +- bungeeguard-bungee/pom.xml | 2 +- bungeeguard-spigot/pom.xml | 4 +- .../spigot/BungeeGuardBackendPlugin.java | 22 ++++++++++- .../spigot/FloodgateHandshakeIntegration.java | 37 +++++++++++++++++-- bungeeguard-sponge/pom.xml | 2 +- bungeeguard-universal/pom.xml | 4 +- pom.xml | 2 +- 8 files changed, 63 insertions(+), 12 deletions(-) diff --git a/bungeeguard-backend/pom.xml b/bungeeguard-backend/pom.xml index f30c0c2..8c5fbbc 100644 --- a/bungeeguard-backend/pom.xml +++ b/bungeeguard-backend/pom.xml @@ -7,7 +7,7 @@ me.lucko bungeeguard - 1.4.11 + 1.4.12 bungeeguard-backend diff --git a/bungeeguard-bungee/pom.xml b/bungeeguard-bungee/pom.xml index dc42bb0..787596a 100644 --- a/bungeeguard-bungee/pom.xml +++ b/bungeeguard-bungee/pom.xml @@ -7,7 +7,7 @@ me.lucko bungeeguard - 1.4.11 + 1.4.12 bungeeguard-bungee diff --git a/bungeeguard-spigot/pom.xml b/bungeeguard-spigot/pom.xml index 3e08bd4..22f0c16 100644 --- a/bungeeguard-spigot/pom.xml +++ b/bungeeguard-spigot/pom.xml @@ -7,11 +7,11 @@ me.lucko bungeeguard - 1.4.11 + 1.4.12 bungeeguard-spigot - 1.4.11 + 1.4.12 diff --git a/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java b/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java index cdf5d71..a80f55c 100644 --- a/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java +++ b/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java @@ -57,7 +57,7 @@ public void onEnable() { saveDefaultConfig(); this.tokenStore = new TokenStore(this); this.tokenStore.load(); - FloodgateHandshakeIntegration.register(getLogger()); + registerFloodgateIntegrationWhenAvailable(); if (hasSpigotConfigMethod() && !isBungeeEnabled()) { getLogger().severe("*-----------------------------------------------------------*"); @@ -107,6 +107,26 @@ public void onEnable() { getServer().getPluginManager().registerEvents(new ExtraProtectionListener(logger), this); } + private void registerFloodgateIntegrationWhenAvailable() { + if (FloodgateHandshakeIntegration.register(getLogger())) { + return; + } + + getLogger().info("Floodgate is not enabled yet; waiting for Floodgate/EduFloodgate before registering the Bedrock/Education token bypass."); + Listener enableListener = new Listener() { + @EventHandler + public void onPluginEnable(PluginEnableEvent event) { + if (!FloodgateHandshakeIntegration.isFloodgatePlugin(event.getPlugin())) { + return; + } + if (FloodgateHandshakeIntegration.register(event.getPlugin(), getLogger())) { + HandlerList.unregisterAll(this); + } + } + }; + getServer().getPluginManager().registerEvents(enableListener, this); + } + @Override public void onDisable() { FloodgateHandshakeIntegration.unregister(); diff --git a/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/FloodgateHandshakeIntegration.java b/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/FloodgateHandshakeIntegration.java index 3521faa..f530a18 100644 --- a/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/FloodgateHandshakeIntegration.java +++ b/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/FloodgateHandshakeIntegration.java @@ -10,6 +10,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.security.SecureRandom; +import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -37,10 +38,40 @@ public final class FloodgateHandshakeIntegration { private FloodgateHandshakeIntegration() { } - /** Register a Floodgate handshake callback if Floodgate is installed and exposes its 2.x API. */ + /** + * Detect Floodgate / EduFloodgate without assuming the plugin's declared casing or name. + * The API class is the strongest signal; the name check also lets the enable-event listener + * recognize the plugin before testing whether its API has finished initializing. + */ + public static boolean isFloodgatePlugin(Plugin candidate) { + if (candidate == null) { + return false; + } + String name = candidate.getDescription().getName(); + if (name != null && name.toLowerCase(Locale.ROOT).contains("floodgate")) { + return true; + } + try { + candidate.getClass().getClassLoader().loadClass("org.geysermc.floodgate.api.InstanceHolder"); + return true; + } catch (ClassNotFoundException | LinkageError ignored) { + return false; + } + } + + /** Register Floodgate's callback if a compatible, enabled instance is already available. */ public static synchronized boolean register(Logger logger) { - Plugin floodgate = Bukkit.getPluginManager().getPlugin("floodgate"); - if (floodgate == null || !floodgate.isEnabled()) { + for (Plugin candidate : Bukkit.getPluginManager().getPlugins()) { + if (candidate.isEnabled() && isFloodgatePlugin(candidate)) { + return register(candidate, logger); + } + } + return false; + } + + /** Register a callback against the exact Floodgate plugin that has just enabled. */ + public static synchronized boolean register(Plugin floodgate, Logger logger) { + if (floodgate == null || !floodgate.isEnabled() || !isFloodgatePlugin(floodgate)) { return false; } if (handlerId >= 0) { diff --git a/bungeeguard-sponge/pom.xml b/bungeeguard-sponge/pom.xml index 64b8ca3..6028be6 100644 --- a/bungeeguard-sponge/pom.xml +++ b/bungeeguard-sponge/pom.xml @@ -7,7 +7,7 @@ me.lucko bungeeguard - 1.4.11 + 1.4.12 bungeeguard-sponge diff --git a/bungeeguard-universal/pom.xml b/bungeeguard-universal/pom.xml index 94c0d29..03d9d21 100644 --- a/bungeeguard-universal/pom.xml +++ b/bungeeguard-universal/pom.xml @@ -7,11 +7,11 @@ me.lucko bungeeguard - 1.4.11 + 1.4.12 bungeeguard-universal - 1.4.11 + 1.4.12 clean package diff --git a/pom.xml b/pom.xml index fd56a98..eb09a78 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lucko bungeeguard - 1.4.11 + 1.4.12 pom From 16ca1eb9c5cbdf6627474cf4a6b00bd100c51240 Mon Sep 17 00:00:00 2001 From: THEMPGUYActions <324142696+THEMPGUYActions@users.noreply.github.com> Date: Tue, 20 Oct 2026 19:47:56 +0000 Subject: [PATCH 2/3] Require valid Floodgate payload length before bypass --- .../spigot/FloodgateHandshakeIntegration.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/FloodgateHandshakeIntegration.java b/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/FloodgateHandshakeIntegration.java index f530a18..fc4c085 100644 --- a/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/FloodgateHandshakeIntegration.java +++ b/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/FloodgateHandshakeIntegration.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; +import java.lang.reflect.Field; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; @@ -119,7 +120,9 @@ public static synchronized boolean register(Plugin floodgate, Logger logger) { private static void handleValidatedFloodgateHandshake(Object data, Logger logger) { try { boolean isFloodgatePlayer = Boolean.TRUE.equals(data.getClass().getMethod("isFloodgatePlayer").invoke(data)); - if (!isFloodgatePlayer) { + if (!isFloodgatePlayer || !hasExpectedFloodgateDataLength(data)) { + // Floodgate also calls custom handlers for decrypt / malformed-data failures. + // Only valid payload lengths may mint a BungeeGuard bypass marker. return; } @@ -152,6 +155,24 @@ private static void handleValidatedFloodgateHandshake(Object data, Logger logger } } + private static boolean hasExpectedFloodgateDataLength(Object handshakeData) throws ReflectiveOperationException { + Object bedrockData = handshakeData.getClass().getMethod("getBedrockData").invoke(handshakeData); + if (bedrockData == null) { + return false; + } + + Method getDataLength = bedrockData.getClass().getMethod("getDataLength"); + int actualLength = ((Number) getDataLength.invoke(bedrockData)).intValue(); + + // EXPECTED_LENGTH is an implementation constant in Floodgate's BedrockData class rather + // than part of the public API. Read it reflectively to avoid a compile-time dependency; + // fail closed if a future Floodgate version removes or changes this validation contract. + Field expectedLengthField = bedrockData.getClass().getDeclaredField("EXPECTED_LENGTH"); + expectedLengthField.setAccessible(true); + int expectedLength = expectedLengthField.getInt(null); + return actualLength == expectedLength; + } + static String insertMarkerAfterHostname(String hostname, String marker) { if (hostname == null || marker == null) { return null; From 94b4c62883e5c4caa4450c746c2386ef0bf6322b Mon Sep 17 00:00:00 2001 From: THEMPGUYActions <324142696+THEMPGUYActions@users.noreply.github.com> Date: Tue, 20 Oct 2026 19:48:38 +0000 Subject: [PATCH 3/3] Import Bukkit plugin enable listener types --- .../me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java b/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java index a80f55c..0bbdb97 100644 --- a/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java +++ b/bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java @@ -35,6 +35,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.java.JavaPlugin; import java.io.File;