3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Let annotations work

Dieser Commit ist enthalten in:
Camotoy 2024-09-09 20:07:18 -04:00
Ursprung a2e9e702b3
Commit a6c21b1f00
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
23 geänderte Dateien mit 262 neuen und 160 gelöschten Zeilen

Datei anzeigen

@ -37,11 +37,11 @@ import org.geysermc.geyser.FloodgateKeyLoader;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserPluginBootstrap;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
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.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
@ -51,8 +51,6 @@ import org.incendo.cloud.CommandManager;
import org.incendo.cloud.bungee.BungeeCommandManager;
import org.incendo.cloud.execution.ExecutionCoordinator;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@ -97,8 +95,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserPluginBootstrap
if (!this.loadConfig()) {
return;
}
this.geyserLogger.setDebug(geyserConfig.debugMode());
this.geyser = GeyserImpl.load(PlatformType.BUNGEECORD, this);
this.geyser = GeyserImpl.load(this);
this.geyserInjector = new GeyserBungeeInjector(this);
// Registration of listeners occurs only once
@ -162,7 +159,6 @@ public class GeyserBungeePlugin extends Plugin implements GeyserPluginBootstrap
if (!loadConfig()) {
return;
}
this.geyserLogger.setDebug(geyserConfig.debugMode());
}
// Force-disable query if enabled, or else Geyser won't enable
@ -221,6 +217,11 @@ public class GeyserBungeePlugin extends Plugin implements GeyserPluginBootstrap
this.onGeyserShutdown();
}
@Override
public PlatformType platformType() {
return PlatformType.BUNGEECORD;
}
@Override
public GeyserPluginConfig config() {
return this.geyserConfig;
@ -296,16 +297,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserPluginBootstrap
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
try {
if (!getDataFolder().exists()) {
//noinspection ResultOfMethodCallIgnored
getDataFolder().mkdir();
}
this.geyserConfig = ConfigLoader.load(new File(getDataFolder(), "config.yml"), GeyserPluginConfig.class);
} catch (IOException ex) {
geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
return false;
}
return true;
this.geyserConfig = new ConfigLoader(this).createFolder().load(GeyserPluginConfig.class);
return this.geyserConfig != null;
}
}

Datei anzeigen

@ -35,9 +35,10 @@ import org.geysermc.geyser.FloodgateKeyLoader;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.GeyserPluginBootstrap;
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.command.CommandRegistry;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.level.WorldManager;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
@ -46,7 +47,6 @@ import org.geysermc.geyser.platform.mod.platform.GeyserModPlatform;
import org.geysermc.geyser.platform.mod.world.GeyserModWorldManager;
import org.geysermc.geyser.text.GeyserLocale;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketAddress;
import java.nio.file.Path;
@ -82,8 +82,7 @@ public abstract class GeyserModBootstrap implements GeyserPluginBootstrap {
if (!loadConfig()) {
return;
}
this.geyserLogger.setDebug(geyserConfig.debugMode());
this.geyser = GeyserImpl.load(this.platform.platformType(), this);
this.geyser = GeyserImpl.load(this);
}
public void onGeyserEnable() {
@ -96,7 +95,6 @@ public abstract class GeyserModBootstrap implements GeyserPluginBootstrap {
if (!loadConfig()) {
return;
}
this.geyserLogger.setDebug(geyserConfig.debugMode());
}
GeyserImpl.start();
@ -141,6 +139,11 @@ public abstract class GeyserModBootstrap implements GeyserPluginBootstrap {
}
}
@Override
public PlatformType platformType() {
return this.platform.platformType();
}
@Override
public GeyserPluginConfig config() {
return geyserConfig;
@ -226,17 +229,7 @@ public abstract class GeyserModBootstrap implements GeyserPluginBootstrap {
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
try {
if (!dataFolder.toFile().exists()) {
//noinspection ResultOfMethodCallIgnored
dataFolder.toFile().mkdir();
}
this.geyserConfig = ConfigLoader.load(dataFolder.resolve("config.yml").toFile(), GeyserPluginConfig.class);
return true;
} catch (IOException ex) {
geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
return false;
}
this.geyserConfig = new ConfigLoader(this).createFolder().load(GeyserPluginConfig.class);
return this.geyserConfig != null;
}
}

Datei anzeigen

@ -71,8 +71,6 @@ import org.incendo.cloud.bukkit.BukkitCommandManager;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.paper.LegacyPaperCommandManager;
import java.io.File;
import java.io.IOException;
import java.net.SocketAddress;
import java.nio.file.Path;
import java.util.List;
@ -165,12 +163,11 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserPluginBootst
if (!loadConfig()) {
return;
}
this.geyserLogger.setDebug(geyserConfig.debugMode());
// Turn "(MC: 1.16.4)" into 1.16.4.
this.minecraftVersion = Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0];
this.geyser = GeyserImpl.load(PlatformType.SPIGOT, this);
this.geyser = GeyserImpl.load(this);
}
@Override
@ -229,7 +226,6 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserPluginBootst
if (!loadConfig()) {
return;
}
this.geyserLogger.setDebug(this.geyserConfig.debugMode());
}
GeyserImpl.start();
@ -361,6 +357,11 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserPluginBootst
this.onGeyserShutdown();
}
@Override
public PlatformType platformType() {
return PlatformType.SPIGOT;
}
@Override
public GeyserPluginConfig config() {
return this.geyserConfig;
@ -463,20 +464,11 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserPluginBootst
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
// This is manually done instead of using Bukkit methods to save the config because otherwise comments get removed
try {
if (!getDataFolder().exists()) {
//noinspection ResultOfMethodCallIgnored
getDataFolder().mkdir();
}
this.geyserConfig = ConfigLoader.load(new File(getDataFolder(), "config.yml"), GeyserPluginConfig.class);
} catch (IOException ex) {
geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
ex.printStackTrace();
this.geyserConfig = new ConfigLoader(this).createFolder().load(GeyserPluginConfig.class);
if (this.geyserConfig == null) {
Bukkit.getPluginManager().disablePlugin(this);
return false;
}
return true;
}

Datei anzeigen

@ -37,11 +37,11 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl;
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.GeyserRemoteConfig;
import org.geysermc.geyser.command.CommandRegistry;
import org.geysermc.geyser.command.standalone.StandaloneCloudCommandManager;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
@ -53,7 +53,6 @@ import org.spongepowered.configurate.NodePath;
import org.spongepowered.configurate.serialize.SerializationException;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -161,10 +160,10 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
@Override
public void onGeyserEnable() {
try {
geyserConfig = ConfigLoader.load(new File(configFilename), GeyserRemoteConfig.class, this::handleArgsConfigOptions);
} catch (IOException ex) {
geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
this.geyserConfig = new ConfigLoader(this)
.transformer(this::handleArgsConfigOptions)
.load(GeyserRemoteConfig.class);
if (this.geyserConfig == null) {
if (gui == null) {
System.exit(1);
} else {
@ -172,12 +171,11 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
return;
}
}
geyserLogger.setDebug(geyserConfig.debugMode());
// Allow libraries like Protocol to have their debug information passthrough
log4jLogger.get().setLevel(geyserConfig.debugMode() ? Level.DEBUG : Level.INFO);
geyser = GeyserImpl.load(PlatformType.STANDALONE, this);
geyser = GeyserImpl.load(this);
boolean reloading = geyser.isReloading();
if (!reloading) {
@ -232,6 +230,11 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
System.exit(0);
}
@Override
public PlatformType platformType() {
return PlatformType.STANDALONE;
}
@Override
public GeyserConfig config() {
return this.geyserConfig;

Datei anzeigen

@ -42,15 +42,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.FloodgateKeyLoader;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserPluginBootstrap;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.extension.Extension;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
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;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
@ -62,7 +59,6 @@ import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.velocity.VelocityCommandManager;
import org.slf4j.Logger;
import java.io.IOException;
import java.net.SocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -107,9 +103,8 @@ public class GeyserVelocityPlugin implements GeyserPluginBootstrap {
if (!loadConfig()) {
return;
}
this.geyserLogger.setDebug(geyserConfig.debugMode());
this.geyser = GeyserImpl.load(PlatformType.VELOCITY, this);
this.geyser = GeyserImpl.load(this);
this.geyserInjector = new GeyserVelocityInjector(proxyServer);
// We need to register commands here, rather than in onGeyserEnable which is invoked during the appropriate ListenerBoundEvent.
@ -139,7 +134,6 @@ public class GeyserVelocityPlugin implements GeyserPluginBootstrap {
if (!loadConfig()) {
return;
}
this.geyserLogger.setDebug(geyserConfig.debugMode());
}
GeyserImpl.start();
@ -173,6 +167,11 @@ public class GeyserVelocityPlugin implements GeyserPluginBootstrap {
}
}
@Override
public PlatformType platformType() {
return PlatformType.VELOCITY;
}
@Override
public GeyserPluginConfig config() {
return geyserConfig;
@ -253,17 +252,7 @@ public class GeyserVelocityPlugin implements GeyserPluginBootstrap {
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
try {
if (!configFolder.toFile().exists()) {
//noinspection ResultOfMethodCallIgnored
configFolder.toFile().mkdirs();
}
this.geyserConfig = ConfigLoader.load(configFolder.resolve("config.yml").toFile(), GeyserPluginConfig.class);
} catch (IOException ex) {
geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
ex.printStackTrace();
return false;
}
return true;
this.geyserConfig = new ConfigLoader(this).createFolder().load(GeyserPluginConfig.class);
return this.geyserConfig != null;
}
}

Datei anzeigen

@ -42,10 +42,10 @@ import org.geysermc.geyser.GeyserPluginBootstrap;
import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.network.AuthType;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
import org.geysermc.geyser.command.CommandRegistry;
import org.geysermc.geyser.command.standalone.StandaloneCloudCommandManager;
import org.geysermc.geyser.configuration.ConfigLoader;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
@ -56,7 +56,6 @@ import org.geysermc.geyser.util.LoopbackUtil;
import org.spongepowered.configurate.serialize.SerializationException;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Path;
@ -127,7 +126,7 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserPlugin
return;
}
this.geyser = GeyserImpl.load(PlatformType.VIAPROXY, this);
this.geyser = GeyserImpl.load(this);
this.geyser.eventBus().register(this, new GeyserServerTransferListener());
LoopbackUtil.checkAndApplyLoopback(this.logger);
}
@ -176,6 +175,11 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserPlugin
this.geyser.shutdown();
}
@Override
public PlatformType platformType() {
return PlatformType.VIAPROXY;
}
@Override
public GeyserPluginConfig config() {
return this.config;
@ -237,10 +241,10 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserPlugin
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
try {
this.config = ConfigLoader.load(new File(ROOT_FOLDER, "config.yml"), GeyserPluginConfig.class, node -> {
this.config = new ConfigLoader(this)
.transformer(node -> {
try {
if (!ViaProxy.getConfig().getWildcardDomainHandling().equals(ViaProxyConfig.WildcardDomainHandling.NONE)) { // TODO
if (!ViaProxy.getConfig().getWildcardDomainHandling().equals(ViaProxyConfig.WildcardDomainHandling.NONE)) {
node.node("java", "forward-host").set(true);
}
@ -253,13 +257,13 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserPlugin
} catch (SerializationException e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
this.logger.severe(GeyserLocale.getLocaleStringLog("geyser.config.failed"), e);
})
.configFile(new File(ROOT_FOLDER, "config.yml"))
.load(GeyserPluginConfig.class);
if (this.config == null) {
return false;
}
this.config.java().authType(Files.isRegularFile(getFloodgateKeyPath()) ? AuthType.FLOODGATE : AuthType.OFFLINE);
this.logger.setDebug(this.config.debugMode());
return true;
}

Datei anzeigen

@ -27,6 +27,7 @@ package org.geysermc.geyser;
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.GeyserConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
@ -67,6 +68,14 @@ public interface GeyserBootstrap {
*/
void onGeyserShutdown();
/**
* Returns the platform type this Geyser instance is running on.
*
* @return The current PlatformType
*/
@NonNull
PlatformType platformType();
/**
* Returns the current GeyserConfig
*

Datei anzeigen

@ -167,7 +167,6 @@ public class GeyserImpl implements GeyserApi, EventRegistrar {
private ScheduledExecutorService scheduledThread;
private GeyserServer geyserServer;
private final PlatformType platformType;
private final GeyserBootstrap bootstrap;
private final EventBus<EventRegistrar> eventBus;
@ -193,12 +192,11 @@ public class GeyserImpl implements GeyserApi, EventRegistrar {
@Setter
private boolean isEnabled;
private GeyserImpl(PlatformType platformType, GeyserBootstrap bootstrap) {
private GeyserImpl(GeyserBootstrap bootstrap) {
instance = this;
Geyser.set(this);
this.platformType = platformType;
this.bootstrap = bootstrap;
/* Initialize event bus */
@ -270,7 +268,7 @@ public class GeyserImpl implements GeyserApi, EventRegistrar {
message += " " + GeyserLocale.getLocaleStringLog("geyser.core.finish.console");
logger.info(message);
if (platformType == PlatformType.STANDALONE) {
if (platformType() == PlatformType.STANDALONE) {
if (config.java().authType() != AuthType.FLOODGATE) {
// If the auth-type is Floodgate, then this Geyser instance is probably owned by the Java server
logger.warning(GeyserLocale.getLocaleStringLog("geyser.core.movement_warn"));
@ -306,7 +304,7 @@ public class GeyserImpl implements GeyserApi, EventRegistrar {
boolean portPropertyApplied = false;
String pluginUdpAddress = System.getProperty("geyserUdpAddress", System.getProperty("pluginUdpAddress", ""));
if (platformType != PlatformType.STANDALONE) {
if (platformType() != PlatformType.STANDALONE) {
int javaPort = bootstrap.getServerPort();
String serverAddress = bootstrap.getServerBindAddress();
if (!serverAddress.isEmpty() && !"0.0.0.0".equals(serverAddress)) {
@ -360,7 +358,7 @@ public class GeyserImpl implements GeyserApi, EventRegistrar {
}
if (platformType != PlatformType.VIAPROXY) {
if (platformType() != PlatformType.VIAPROXY) {
boolean floodgatePresent = bootstrap.testFloodgatePluginPresent();
if (config.java().authType() == AuthType.FLOODGATE && !floodgatePresent) {
logger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " "
@ -496,7 +494,7 @@ public class GeyserImpl implements GeyserApi, EventRegistrar {
metrics.addCustomChart(new SingleLineChart("players", sessionManager::size));
// Prevent unwanted words best we can
metrics.addCustomChart(new SimplePie("authMode", () -> config.java().authType().toString().toLowerCase(Locale.ROOT)));
metrics.addCustomChart(new SimplePie("platform", platformType::platformName));
metrics.addCustomChart(new SimplePie("platform", platformType()::platformName));
metrics.addCustomChart(new SimplePie("defaultLocale", GeyserLocale::getDefaultLocale));
metrics.addCustomChart(new SimplePie("version", () -> GeyserImpl.VERSION));
metrics.addCustomChart(new AdvancedPie("playerPlatform", () -> {
@ -532,7 +530,7 @@ public class GeyserImpl implements GeyserApi, EventRegistrar {
if (minecraftVersion != null) {
Map<String, Map<String, Integer>> versionMap = new HashMap<>();
Map<String, Integer> platformMap = new HashMap<>();
platformMap.put(platformType.platformName(), 1);
platformMap.put(platformType().platformName(), 1);
versionMap.put(minecraftVersion, platformMap);
metrics.addCustomChart(new DrilldownPie("minecraftServerVersion", () -> {
@ -840,7 +838,7 @@ public class GeyserImpl implements GeyserApi, EventRegistrar {
@Override
@NonNull
public PlatformType platformType() {
return platformType;
return bootstrap.platformType();
}
@Override
@ -871,9 +869,9 @@ public class GeyserImpl implements GeyserApi, EventRegistrar {
return Integer.parseInt(BUILD_NUMBER);
}
public static GeyserImpl load(PlatformType platformType, GeyserBootstrap bootstrap) {
public static GeyserImpl load(GeyserBootstrap bootstrap) {
if (instance == null) {
return new GeyserImpl(platformType, bootstrap);
return new GeyserImpl(bootstrap);
}
return instance;

Datei anzeigen

@ -141,7 +141,7 @@ public class CommandRegistry implements EventRegistrar {
registerBuiltInCommand(new AdvancedTooltipsCommand("tooltips", "geyser.commands.advancedtooltips.desc", "geyser.command.tooltips"));
registerBuiltInCommand(new ConnectionTestCommand(geyser, "connectiontest", "geyser.commands.connectiontest.desc", "geyser.command.connectiontest"));
registerBuiltInCommand(new PingCommand("ping", "geyser.commands.ping.desc", "geyser.command.ping"));
if (this.geyser.getPlatformType() == PlatformType.STANDALONE) {
if (this.geyser.platformType() == PlatformType.STANDALONE) {
registerBuiltInCommand(new StopCommand(geyser, "stop", "geyser.commands.stop.desc", "geyser.command.stop"));
}

Datei anzeigen

@ -73,7 +73,7 @@ public class VersionCommand extends GeyserCommand {
GeyserImpl.NAME, GeyserImpl.VERSION, javaVersions, bedrockVersions));
// Disable update checking in dev mode and for players in Geyser Standalone
if (!GeyserImpl.getInstance().isProductionEnvironment() || (!source.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE)) {
if (!GeyserImpl.getInstance().isProductionEnvironment() || (!source.isConsole() && geyser.platformType() == PlatformType.STANDALONE)) {
return;
}

Datei anzeigen

@ -81,22 +81,22 @@ public interface AdvancedConfig {
int mtu();
@Comment("""
Only for plugin versions of Geyser.
Whether to connect directly into the Java server without creating a TCP connection.
This should only be disabled if a plugin that interfaces with packets or the network does not work correctly with Geyser.
If enabled on plugin versions, the remote address and port sections are ignored
If disabled on plugin versions, expect performance decrease and latency increase
If enabled, the remote address and port sections are ignored
If disabled, expect performance decrease and latency increase
""")
@DefaultBoolean(true)
@PlatformTypeSpecific
boolean useDirectConnection();
@Comment("""
Only for plugin versions of Geyser.
Whether Geyser should attempt to disable compression for Bedrock players. This should be a benefit as there is no need to compress data
when Java packets aren't being handled over the network.
This requires use-direct-connection to be true.
""")
@DefaultBoolean(true)
@PlatformTypeSpecific
boolean disableCompression();
@Comment("Do not touch!")

Datei anzeigen

@ -26,18 +26,23 @@
package org.geysermc.geyser.configuration;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.common.returnsreceiver.qual.This;
import org.geysermc.geyser.Constants;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.text.GeyserLocale;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.NodePath;
import org.spongepowered.configurate.interfaces.InterfaceDefaultOptions;
import org.spongepowered.configurate.objectmapping.meta.Processor;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.nio.file.Path;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Stream;
@ -70,15 +75,58 @@ public final class ConfigLoader {
--------------------------------
""";
public static <T extends GeyserConfig> T load(File file, Class<T> configClass) throws IOException {
return load(file, configClass, null);
private final GeyserBootstrap bootstrap;
private @Nullable Consumer<CommentedConfigurationNode> transformer;
private File configFile;
public ConfigLoader(GeyserBootstrap bootstrap) {
this.bootstrap = bootstrap;
configFile = new File(bootstrap.getConfigFolder().toFile(), "config.yml");
}
public static <T extends GeyserConfig> T load(File file, Class<T> configClass, @Nullable Consumer<CommentedConfigurationNode> transformer) throws IOException {
var loader = createLoader(file, HEADER);
/**
* Creates the directory as indicated by {@link GeyserBootstrap#getConfigFolder()}
*/
@This
public ConfigLoader createFolder() {
Path dataFolder = this.bootstrap.getConfigFolder();
if (!dataFolder.toFile().exists()) {
//noinspection ResultOfMethodCallIgnored
dataFolder.toFile().mkdir();
}
return this;
}
@This
public ConfigLoader transformer(Consumer<CommentedConfigurationNode> transformer) {
this.transformer = transformer;
return this;
}
@This
public ConfigLoader configFile(File configFile) {
this.configFile = configFile;
return this;
}
/**
* @return null if the config failed to load.
*/
@Nullable
public <T extends GeyserConfig> T load(Class<T> configClass) {
try {
return load0(configClass);
} catch (IOException ex) {
bootstrap.getGeyserLogger().error(GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
return null;
}
}
private <T extends GeyserConfig> T load0(Class<T> configClass) throws IOException {
var loader = createLoader(configFile, HEADER);
CommentedConfigurationNode node = loader.load();
boolean originallyEmpty = !file.exists() || node.isNull();
boolean originallyEmpty = !configFile.exists() || node.isNull();
// Note for Tim? Needed or else Configurate breaks.
var migrations = ConfigurationTransformation.versionedBuilder()
@ -157,8 +205,8 @@ public final class ConfigLoader {
newRoot.set(config);
// Create the path in a way that Standalone changing the config name will be fine.
int extensionIndex = file.getName().lastIndexOf(".");
File advancedConfigPath = new File(file.getParent(), file.getName().substring(0, extensionIndex) + "_advanced" + file.getName().substring(extensionIndex));
int extensionIndex = configFile.getName().lastIndexOf(".");
File advancedConfigPath = new File(configFile.getParent(), configFile.getName().substring(0, extensionIndex) + "_advanced" + configFile.getName().substring(extensionIndex));
AdvancedConfig advancedConfig = null;
if (originallyEmpty || currentVersion != newVersion) {
@ -188,13 +236,15 @@ public final class ConfigLoader {
config.advanced(advancedConfig);
bootstrap.getGeyserLogger().setDebug(config.debugMode());
return config;
}
private static AdvancedConfig migrateToAdvancedConfig(File file, ConfigurationNode configRoot) throws IOException {
List<NodePath> copyFromOldConfig = Stream.of("max-visible-custom-skulls", "custom-skull-render-distance", "scoreboard-packet-threshold", "mtu",
private AdvancedConfig migrateToAdvancedConfig(File file, ConfigurationNode configRoot) throws IOException {
Stream<NodePath> copyFromOldConfig = Stream.of("max-visible-custom-skulls", "custom-skull-render-distance", "scoreboard-packet-threshold", "mtu",
"floodgate-key-file", "use-direct-connection", "disable-compression")
.map(NodePath::path).toList();
.map(NodePath::path);
var loader = createLoader(file, ADVANCED_HEADER);
@ -222,7 +272,7 @@ public final class ConfigLoader {
return advancedConfig;
}
private static AdvancedConfig loadAdvancedConfig(File file) throws IOException {
private AdvancedConfig loadAdvancedConfig(File file) throws IOException {
var loader = createLoader(file, ADVANCED_HEADER);
if (file.exists()) {
ConfigurationNode node = loader.load();
@ -237,18 +287,38 @@ public final class ConfigLoader {
}
}
private static YamlConfigurationLoader createLoader(File file, String header) {
private YamlConfigurationLoader createLoader(File file, String header) {
return YamlConfigurationLoader.builder()
.file(file)
.indent(2)
.nodeStyle(NodeStyle.BLOCK)
.defaultOptions(options -> InterfaceDefaultOptions.addTo(options)
.defaultOptions(options -> InterfaceDefaultOptions.addTo(options, builder ->
builder.addProcessor(ExcludePlatform.class, excludePlatform(bootstrap.platformType().platformName()))
.addProcessor(PlatformTypeSpecific.class, platformTypeSpecific(bootstrap.platformType() != PlatformType.STANDALONE)))
.shouldCopyDefaults(false) // If we use ConfigurationNode#get(type, default), do not write the default back to the node.
.header(header)
.serializers(builder -> builder.register(new LowercaseEnumSerializer())))
.build();
}
private static Processor.Factory<ExcludePlatform, Object> excludePlatform(String thisPlatform) {
return (data, fieldType) -> (value, destination) -> {
for (String platform : data.platforms()) {
if (thisPlatform.equals(platform)) {
//noinspection DataFlowIssue
destination.parent().removeChild(destination.key());
break;
}
}
};
}
private ConfigLoader() {
private static Processor.Factory<PlatformTypeSpecific, Object> platformTypeSpecific(boolean thisConfigPlugin) {
return (data, fieldType) -> (value, destination) -> {
if (data.forPlugin() != thisConfigPlugin) {
//noinspection DataFlowIssue
destination.parent().removeChild(destination.key());
}
};
}
}

Datei anzeigen

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.configuration;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcludePlatform {
String[] platforms();
}

Datei anzeigen

@ -83,6 +83,11 @@ public interface GeyserConfig {
@DefaultBoolean(true)
boolean passthroughPlayerCounts();
@Comment("""
Use server API methods to determine the Java server's MOTD and ping passthrough.
There is no need to disable this unless your MOTD or player count does not appear properly.""")
@DefaultBoolean(true)
@PlatformTypeSpecific
boolean integratedPingPassthrough();
@Comment("How often to ping the Java server to refresh MOTD and player count, in seconds.")
@ -214,6 +219,7 @@ public interface GeyserConfig {
Some hosting services change your Java port everytime you start the server and require the same port to be used for Bedrock.
This option makes the Bedrock port the same as the Java port every time you start the server.""")
@DefaultBoolean
@PlatformTypeSpecific
boolean cloneRemotePort();
void address(String address);

Datei anzeigen

@ -27,7 +27,6 @@ package org.geysermc.geyser.configuration;
import org.spongepowered.configurate.interfaces.meta.Exclude;
import org.spongepowered.configurate.interfaces.meta.Field;
import org.spongepowered.configurate.interfaces.meta.defaults.DefaultBoolean;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Comment;
@ -59,13 +58,6 @@ public interface GeyserPluginConfig extends GeyserConfig {
}
}
@Comment("""
Use server API methods to determine the Java server's MOTD and ping passthrough.
There is no need to disable this unless your MOTD or player count does not appear properly.""")
@DefaultBoolean(true)
@Override
boolean integratedPingPassthrough();
@Comment("""
How often to ping the Java server to refresh MOTD and player count, in seconds.
Only relevant if integrated-ping-passthrough is disabled.""")

Datei anzeigen

@ -25,7 +25,6 @@
package org.geysermc.geyser.configuration;
import org.spongepowered.configurate.interfaces.meta.Exclude;
import org.spongepowered.configurate.interfaces.meta.defaults.DefaultNumeric;
import org.spongepowered.configurate.interfaces.meta.defaults.DefaultString;
import org.spongepowered.configurate.interfaces.meta.range.NumericRange;
@ -37,21 +36,9 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
*/
@ConfigSerializable
public interface GeyserRemoteConfig extends GeyserConfig {
@Override
RemoteBedrock bedrock();
@Override
RemoteConfig java();
@ConfigSerializable
interface RemoteBedrock extends BedrockConfig {
@Override
@Exclude // We can bring this back if there's a use-case but it's not really justified here.
default boolean cloneRemotePort() {
return false;
}
}
@ConfigSerializable
interface RemoteConfig extends JavaConfig {
@Override
@ -71,11 +58,4 @@ public interface GeyserRemoteConfig extends GeyserConfig {
This is designed to be used for forced hosts on proxies""")
boolean forwardHostname();
}
@Exclude
@Override
default boolean integratedPingPassthrough() {
// Does nothing here.
return false;
}
}

Datei anzeigen

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.configuration;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface PlatformTypeSpecific {
boolean forPlugin() default true;
}

Datei anzeigen

@ -39,7 +39,7 @@ public class BootstrapDumpInfo {
private final PlatformType platform;
public BootstrapDumpInfo() {
this.platform = GeyserImpl.getInstance().getPlatformType();
this.platform = GeyserImpl.getInstance().platformType();
}
@Getter

Datei anzeigen

@ -1084,7 +1084,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.authentication_type_mismatch", locale());
// Explain that they may be looking for Floodgate.
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog(
geyser.getPlatformType() == PlatformType.STANDALONE ?
geyser.platformType() == PlatformType.STANDALONE ?
"geyser.network.remote.floodgate_explanation_standalone"
: "geyser.network.remote.floodgate_explanation_plugin",
Constants.FLOODGATE_DOWNLOAD_LOCATION
@ -1092,7 +1092,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
} else {
// Likely that Floodgate is not configured correctly.
disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.floodgate_login_error", locale());
if (geyser.getPlatformType() == PlatformType.STANDALONE) {
if (geyser.platformType() == PlatformType.STANDALONE) {
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.remote.floodgate_login_error_standalone"));
}
}

Datei anzeigen

@ -44,8 +44,8 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
}
static void handleCommand(GeyserSession session, String command) {
if (session.getGeyser().getPlatformType() == PlatformType.STANDALONE ||
session.getGeyser().getPlatformType() == PlatformType.VIAPROXY) {
if (session.getGeyser().platformType() == PlatformType.STANDALONE ||
session.getGeyser().platformType() == PlatformType.VIAPROXY) {
// try to handle the command within the standalone/viaproxy command manager
String[] args = command.split(" ");

Datei anzeigen

@ -50,7 +50,7 @@ public class JavaLoginDisconnectTranslator extends PacketTranslator<ClientboundL
String disconnectMessage;
if (testForOutdatedServer(disconnectReason)) {
String locale = session.locale();
PlatformType platform = session.getGeyser().getPlatformType();
PlatformType platform = session.getGeyser().platformType();
String outdatedType = (platform == PlatformType.BUNGEECORD || platform == PlatformType.VELOCITY || platform == PlatformType.VIAPROXY) ?
"geyser.network.remote.outdated.proxy" : "geyser.network.remote.outdated.server";
disconnectMessage = GeyserLocale.getPlayerLocaleString(outdatedType, locale, GameProtocol.getJavaVersions().get(0)) + '\n'

Datei anzeigen

@ -92,7 +92,7 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
// Retracting sticky pistons is an exception, since the event is not called on Spigot from 1.13.2 - 1.17.1
// See https://github.com/PaperMC/Paper/blob/6fa1983e9ce177a4a412d5b950fd978620174777/patches/server/0304-Fire-BlockPistonRetractEvent-for-all-empty-pistons.patch
boolean isSticky = isSticky(pistonBlock);
if (session.getGeyser().getPlatformType() == PlatformType.SPIGOT && !isSticky) {
if (session.getGeyser().platformType() == PlatformType.SPIGOT && !isSticky) {
return;
}

Datei anzeigen

@ -233,6 +233,6 @@ public class WebUtils {
}
public static String getUserAgent() {
return "Geyser-" + GeyserImpl.getInstance().getPlatformType().platformName() + "/" + GeyserImpl.VERSION;
return "Geyser-" + GeyserImpl.getInstance().platformType().platformName() + "/" + GeyserImpl.VERSION;
}
}