Fix Floodgate autodetection

This commit is contained in:
Camotoy 2023-04-26 21:11:26 -04:00
parent 8a257181b9
commit c8afd3436d
10 changed files with 39 additions and 31 deletions

View file

@ -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<InetSocketAddress> findCompatibleListener() {

View file

@ -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<ModContainer> floodgate = FabricLoader.getInstance().getModContainer("floodgate");
if (floodgate.isPresent()) {
geyserConfig.loadFloodgate(this, floodgate.orElse(null));
return true;
}
return false;
}
@Nullable

View file

@ -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;
}
}

View file

@ -241,7 +241,7 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
}
@Override
public boolean isFloodgatePluginPresent() {
public boolean testFloodgatePluginPresent() {
return false;
}
}

View file

@ -304,7 +304,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
}
@Override
public boolean isFloodgatePluginPresent() {
public boolean testFloodgatePluginPresent() {
return false;
}

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -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();
}

View file

@ -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);

View file

@ -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) {