From c8afd3436dc1d699393476917ea2dfb51df562cc Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:11:26 -0400 Subject: [PATCH] Fix Floodgate autodetection --- .../platform/bungeecord/GeyserBungeePlugin.java | 11 ++++++----- .../geyser/platform/fabric/GeyserFabricMod.java | 11 ++++++++--- .../platform/spigot/GeyserSpigotPlugin.java | 15 +++++++++------ .../platform/sponge/GeyserSpongePlugin.java | 2 +- .../standalone/GeyserStandaloneBootstrap.java | 2 +- .../platform/velocity/GeyserVelocityPlugin.java | 12 +++++++----- .../org/geysermc/geyser/FloodgateKeyLoader.java | 5 ----- .../java/org/geysermc/geyser/GeyserBootstrap.java | 5 ++++- .../main/java/org/geysermc/geyser/GeyserImpl.java | 5 +++-- .../geyser/network/netty/GeyserServer.java | 2 -- 10 files changed, 39 insertions(+), 31 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java index 4122cf547..4141a8dbc 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java @@ -36,7 +36,6 @@ import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.extension.Extension; -import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.command.GeyserCommandManager; import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.dump.BootstrapDumpInfo; @@ -136,8 +135,6 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { } } - geyserConfig.loadFloodgate(this); - // Big hack - Bungee does not provide us an event to listen to, so schedule a repeating // task that waits for a field to be filled which is set after the plugin enable // process is complete @@ -260,8 +257,12 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { } @Override - public boolean isFloodgatePluginPresent() { - return getProxy().getPluginManager().getPlugin("floodgate") != null; + public boolean testFloodgatePluginPresent() { + if (getProxy().getPluginManager().getPlugin("floodgate") != null) { + geyserConfig.loadFloodgate(this); + return true; + } + return false; } private Optional findCompatibleListener() { diff --git a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java index 8f39b3850..fdc820b19 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java @@ -60,6 +60,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; import java.util.Map; +import java.util.Optional; import java.util.UUID; public class GeyserFabricMod implements ModInitializer, GeyserBootstrap { @@ -138,7 +139,6 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap { */ public void startGeyser(MinecraftServer server) { this.server = server; - geyserConfig.loadFloodgate(this, FabricLoader.getInstance().getModContainer("floodgate").orElse(null)); GeyserImpl.start(); @@ -229,8 +229,13 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap { } @Override - public boolean isFloodgatePluginPresent() { - return FabricLoader.getInstance().getModContainer("floodgate").isPresent(); + public boolean testFloodgatePluginPresent() { + Optional floodgate = FabricLoader.getInstance().getModContainer("floodgate"); + if (floodgate.isPresent()) { + geyserConfig.loadFloodgate(this, floodgate.orElse(null)); + return true; + } + return false; } @Nullable diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java index d9b27e668..a660d735b 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java @@ -49,7 +49,6 @@ import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.adapters.spigot.SpigotAdapters; import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.extension.Extension; -import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.command.GeyserCommandManager; import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.dump.BootstrapDumpInfo; @@ -62,7 +61,9 @@ import org.geysermc.geyser.platform.spigot.command.GeyserSpigotCommandExecutor; import org.geysermc.geyser.platform.spigot.command.GeyserSpigotCommandManager; import org.geysermc.geyser.platform.spigot.world.GeyserPistonListener; import org.geysermc.geyser.platform.spigot.world.GeyserSpigotBlockPlaceListener; -import org.geysermc.geyser.platform.spigot.world.manager.*; +import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotLegacyNativeWorldManager; +import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotNativeWorldManager; +import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotWorldManager; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.FileUtils; import org.jetbrains.annotations.NotNull; @@ -171,8 +172,6 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { return; } - geyserConfig.loadFloodgate(this); - this.geyserCommandManager = new GeyserSpigotCommandManager(geyser); this.geyserCommandManager.init(); @@ -451,7 +450,11 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { } @Override - public boolean isFloodgatePluginPresent() { - return Bukkit.getPluginManager().getPlugin("floodgate") != null; + public boolean testFloodgatePluginPresent() { + if (Bukkit.getPluginManager().getPlugin("floodgate") != null) { + geyserConfig.loadFloodgate(this); + return true; + } + return false; } } diff --git a/bootstrap/sponge/src/main/java/org/geysermc/geyser/platform/sponge/GeyserSpongePlugin.java b/bootstrap/sponge/src/main/java/org/geysermc/geyser/platform/sponge/GeyserSpongePlugin.java index 718c53ce8..dd84bf31c 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/geyser/platform/sponge/GeyserSpongePlugin.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/geyser/platform/sponge/GeyserSpongePlugin.java @@ -241,7 +241,7 @@ public class GeyserSpongePlugin implements GeyserBootstrap { } @Override - public boolean isFloodgatePluginPresent() { + public boolean testFloodgatePluginPresent() { return false; } } diff --git a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java index f410370d7..c4271be4c 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java @@ -304,7 +304,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap { } @Override - public boolean isFloodgatePluginPresent() { + public boolean testFloodgatePluginPresent() { return false; } diff --git a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java index 8b4d9e82c..92b3a71a7 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java @@ -41,7 +41,6 @@ import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.extension.Extension; -import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.command.GeyserCommandManager; import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.dump.BootstrapDumpInfo; @@ -125,8 +124,6 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { return; } catch (ClassNotFoundException ignored) { } - - geyserConfig.loadFloodgate(this, proxyServer, configFolder.toFile()); } private void postStartup() { @@ -233,7 +230,12 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { } @Override - public boolean isFloodgatePluginPresent() { - return proxyServer.getPluginManager().getPlugin("floodgate").isPresent(); + public boolean testFloodgatePluginPresent() { + var floodgate = proxyServer.getPluginManager().getPlugin("floodgate"); + if (floodgate.isPresent()) { + geyserConfig.loadFloodgate(this, proxyServer, configFolder.toFile()); + return true; + } + return false; } } diff --git a/core/src/main/java/org/geysermc/geyser/FloodgateKeyLoader.java b/core/src/main/java/org/geysermc/geyser/FloodgateKeyLoader.java index 8b51228c8..761e67a67 100644 --- a/core/src/main/java/org/geysermc/geyser/FloodgateKeyLoader.java +++ b/core/src/main/java/org/geysermc/geyser/FloodgateKeyLoader.java @@ -25,7 +25,6 @@ package org.geysermc.geyser; -import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.configuration.GeyserJacksonConfiguration; import org.geysermc.geyser.text.GeyserLocale; @@ -34,10 +33,6 @@ import java.nio.file.Path; public class FloodgateKeyLoader { public static Path getKeyPath(GeyserJacksonConfiguration config, Path floodgateDataFolder, Path geyserDataFolder, GeyserLogger logger) { - if (config.getRemote().authType() != AuthType.FLOODGATE) { - return geyserDataFolder.resolve(config.getFloodgateKeyFile()); - } - // Always prioritize Floodgate's key, if it is installed. // This mostly prevents people from trying to copy the key and corrupting it in the process if (floodgateDataFolder != null) { diff --git a/core/src/main/java/org/geysermc/geyser/GeyserBootstrap.java b/core/src/main/java/org/geysermc/geyser/GeyserBootstrap.java index e31c6bd10..e4baeebb5 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserBootstrap.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserBootstrap.java @@ -170,5 +170,8 @@ public interface GeyserBootstrap { */ int getServerPort(); - boolean isFloodgatePluginPresent(); + /** + * Tests if Floodgate is installed, loads the Floodgate key if so, and returns the result of Floodgate installed. + */ + boolean testFloodgatePluginPresent(); } diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index 73fbe6323..45321163b 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -324,11 +324,12 @@ public class GeyserImpl implements GeyserApi { } } - if (config.getRemote().authType() == AuthType.FLOODGATE && !bootstrap.isFloodgatePluginPresent()) { + boolean floodgatePresent = bootstrap.testFloodgatePluginPresent(); + if (config.getRemote().authType() == AuthType.FLOODGATE && !floodgatePresent) { logger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling")); return; - } else if (config.isAutoconfiguredRemote() && bootstrap.isFloodgatePluginPresent()) { + } else if (config.isAutoconfiguredRemote() && floodgatePresent) { // Floodgate installed means that the user wants Floodgate authentication logger.debug("Auto-setting to Floodgate authentication."); config.getRemote().setAuthType(AuthType.FLOODGATE); diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java b/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java index 83be9ea6e..2b1523cf3 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java @@ -148,8 +148,6 @@ public final class GeyserServer { } private ServerBootstrap createBootstrap(EventLoopGroup group) { - // TODO - boolean enableProxyProtocol = this.geyser.getConfig().getBedrock().isEnableProxyProtocol(); if (this.geyser.getConfig().isDebugMode()) { this.geyser.getLogger().debug("EventLoop type: " + TRANSPORT.datagramChannel()); if (TRANSPORT.datagramChannel() == NioDatagramChannel.class) {