1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-27 02:39:15 +00:00

Move config loading to GeyserBootstrap interface

This commit is contained in:
onebeastchris
2025-04-26 02:12:10 +02:00
parent 7b55ade516
commit 20e02b99c2
7 changed files with 54 additions and 65 deletions

View File

@@ -40,7 +40,6 @@ import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.command.CommandRegistry;
import org.geysermc.geyser.command.CommandSourceConverter;
import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.network.GameProtocol;
@@ -97,7 +96,8 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
geyserLogger.warning("Unable to check the versions supported by this proxy! " + e.getMessage());
}
if (!this.loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
return;
}
this.geyser = GeyserImpl.load(this);
@@ -161,7 +161,8 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
public void onGeyserEnable() {
if (GeyserImpl.getInstance().isReloading()) {
if (!loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
return;
}
}
@@ -223,7 +224,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
}
@Override
public PlatformType platformType() {
public @NonNull PlatformType platformType() {
return PlatformType.BUNGEECORD;
}
@@ -312,10 +313,4 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
.map(info -> (InetSocketAddress) info.getSocketAddress())
.findFirst();
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
this.geyserConfig = new ConfigLoader(this).createFolder().load(GeyserPluginConfig.class);
return this.geyserConfig != null;
}
}

View File

@@ -37,7 +37,6 @@ import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.command.CommandRegistry;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.level.WorldManager;
@@ -79,7 +78,8 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
instance = this;
dataFolder = this.platform.dataFolder(this.platform.configPath());
GeyserLocale.init(this);
if (!loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
return;
}
this.geyser = GeyserImpl.load(this);
@@ -92,7 +92,8 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
}
if (GeyserImpl.getInstance().isReloading()) {
if (!loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
return;
}
}
@@ -140,7 +141,7 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
}
@Override
public PlatformType platformType() {
public @NonNull PlatformType platformType() {
return this.platform.platformType();
}
@@ -225,10 +226,4 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
public InputStream getResourceOrNull(String resource) {
return this.platform.resolveResource(resource);
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
this.geyserConfig = new ConfigLoader(this).createFolder().load(GeyserPluginConfig.class);
return this.geyserConfig != null;
}
}

View File

@@ -52,7 +52,6 @@ import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.command.CommandRegistry;
import org.geysermc.geyser.command.CommandSourceConverter;
import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.level.WorldManager;
@@ -161,7 +160,9 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
// no-op
}
if (!loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
// We'll disable ourselves later
return;
}
@@ -224,7 +225,9 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
// Configs are loaded once early - so we can create the logger, then load extensions and finally register
// extension commands in #onEnable. To ensure reloading geyser also reloads the geyser config, this exists
if (GeyserImpl.getInstance().isReloading()) {
if (!loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
Bukkit.getPluginManager().disablePlugin(this);
return;
}
}
@@ -359,7 +362,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
}
@Override
public PlatformType platformType() {
public @NonNull PlatformType platformType() {
return PlatformType.SPIGOT;
}
@@ -468,16 +471,6 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
return new SpigotMetrics(this);
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
this.geyserConfig = new ConfigLoader(this).createFolder().load(GeyserPluginConfig.class);
if (this.geyserConfig == null) {
Bukkit.getPluginManager().disablePlugin(this);
return false;
}
return true;
}
private void warnInvalidProxySetups(String platform) {
geyserLogger.error("*********************************************");
geyserLogger.error("");

View File

@@ -151,9 +151,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
@Override
public void onGeyserEnable() {
this.geyserConfig = new ConfigLoader(this, configFilename)
.transformer(this::handleArgsConfigOptions)
.load(GeyserRemoteConfig.class);
this.geyserConfig = loadConfig(GeyserRemoteConfig.class);
if (this.geyserConfig == null) {
if (gui == null) {
System.exit(1);
@@ -193,6 +191,13 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
geyserLogger.start();
}
@Override
public <T extends GeyserConfig> T loadConfig(Class<T> configClass) {
return new ConfigLoader(this, configFilename)
.transformer(this::handleArgsConfigOptions)
.load(configClass);
}
/**
* Check using {@link java.awt.GraphicsEnvironment} that we are a headless client
*
@@ -221,7 +226,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
}
@Override
public PlatformType platformType() {
public @NonNull PlatformType platformType() {
return PlatformType.STANDALONE;
}

View File

@@ -46,7 +46,6 @@ import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.command.CommandRegistry;
import org.geysermc.geyser.command.CommandSourceConverter;
import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.network.GameProtocol;
@@ -102,7 +101,8 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
geyserLogger.error("/_____________\\");
}
if (!loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
return;
}
@@ -133,7 +133,8 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
return;
}
if (GeyserImpl.getInstance().isReloading()) {
if (!loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
return;
}
}
@@ -170,7 +171,7 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
}
@Override
public PlatformType platformType() {
public @NonNull PlatformType platformType() {
return PlatformType.VELOCITY;
}
@@ -264,10 +265,4 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
return null;
}
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
this.geyserConfig = new ConfigLoader(this).createFolder().load(GeyserPluginConfig.class);
return this.geyserConfig != null;
}
}

View File

@@ -49,6 +49,7 @@ import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.command.CommandRegistry;
import org.geysermc.geyser.command.standalone.StandaloneCloudCommandManager;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserConfig;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
@@ -71,7 +72,7 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserBootst
private static final File ROOT_FOLDER = new File(PluginManager.PLUGINS_DIR, "Geyser");
private final GeyserViaProxyLogger logger = new GeyserViaProxyLogger(LogManager.getLogger("Geyser"));
private GeyserPluginConfig config;
private GeyserPluginConfig geyserConfig;
private GeyserImpl geyser;
private StandaloneCloudCommandManager cloud;
private CommandRegistry commandRegistry;
@@ -148,7 +149,8 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserBootst
@Override
public void onGeyserInitialize() {
if (!this.loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
return;
}
@@ -165,7 +167,8 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserBootst
}
boolean reloading = geyser.isReloading();
if (reloading) {
if (!this.loadConfig()) {
geyserConfig = loadConfig(GeyserPluginConfig.class);
if (geyserConfig == null) {
return;
}
} else {
@@ -186,7 +189,7 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserBootst
// Only initialize the ping passthrough if the protocol version is above beta 1.7.3, as that's when the status protocol was added
this.pingPassthrough = GeyserLegacyPingPassthrough.init(this.geyser);
}
if (this.config.java().authType() == AuthType.FLOODGATE) {
if (this.geyserConfig.java().authType() == AuthType.FLOODGATE) {
ViaProxy.getConfig().setPassthroughBungeecordPlayerInfo(true);
}
}
@@ -202,13 +205,13 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserBootst
}
@Override
public PlatformType platformType() {
public @NonNull PlatformType platformType() {
return PlatformType.VIAPROXY;
}
@Override
public GeyserPluginConfig config() {
return this.config;
return this.geyserConfig;
}
@Override
@@ -262,12 +265,12 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserBootst
@Override
public Path getFloodgateKeyPath() {
return new File(ROOT_FOLDER, config.advanced().floodgateKeyFile()).toPath();
return new File(ROOT_FOLDER, geyserConfig.advanced().floodgateKeyFile()).toPath();
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
this.config = new ConfigLoader(this)
@Override
public <T extends GeyserConfig> T loadConfig(Class<T> configClass) {
T config = new ConfigLoader(this)
.transformer(node -> {
try {
if (!ViaProxy.getConfig().getWildcardDomainHandling().equals(ViaProxyConfig.WildcardDomainHandling.NONE)) {
@@ -285,12 +288,10 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserBootst
}
})
.configFile(new File(ROOT_FOLDER, "config.yml"))
.load(GeyserPluginConfig.class);
if (this.config == null) {
return false;
.load(configClass);
if (config != null) {
config.java().authType(Files.isRegularFile(getFloodgateKeyPath()) ? AuthType.FLOODGATE : AuthType.OFFLINE);
}
this.config.java().authType(Files.isRegularFile(getFloodgateKeyPath()) ? AuthType.FLOODGATE : AuthType.OFFLINE);
return true;
return config;
}
}

View File

@@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.command.CommandRegistry;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.level.GeyserWorldManager;
@@ -73,7 +74,7 @@ public interface GeyserBootstrap {
/**
* Returns the platform type this Geyser instance is running on.
*
* @return The current PlatformType
* @return the PlatformType this Geyser instance is running on.
*/
@NonNull
PlatformType platformType();
@@ -210,4 +211,8 @@ public interface GeyserBootstrap {
default MetricsPlatform createMetricsPlatform() {
return new ProvidedMetricsPlatform();
}
default <T extends GeyserConfig> T loadConfig(Class<T> configClass) {
return new ConfigLoader(this).createFolder().load(configClass);
}
}