Add configuration interface to expose certain config values (#12273)

This commit is contained in:
David 2025-05-03 22:33:25 +02:00 committed by GitHub
parent 53d1d04ec5
commit c98cd65802
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package io.papermc.paper.configuration;
/**
* Represents the configuration settings for a server.
* <p>
* This interface doesn't aim to cover every possible server configuration
* option but focuses on selected critical settings and behaviors.
*/
public interface ServerConfiguration {
/**
* Gets whether the server is in online mode.
* <p>
* This method returns true if:
* <ul>
* <li>The server is in {@link org.bukkit.Server#getOnlineMode online mode},</li>
* <li>Velocity is enabled and configured to be in online mode, or</li>
* <li>BungeeCord is enabled and configured to be in online mode.</li>
* </ul>
*
* @return whether the server is in online mode or behind a proxy configured for online mode
*/
boolean isProxyOnlineMode();
}

View File

@ -14,6 +14,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.logging.Logger;
import io.papermc.paper.configuration.ServerConfiguration;
import net.kyori.adventure.text.Component;
import org.bukkit.Warning.WarningState;
import org.bukkit.advancement.Advancement;
@ -1435,6 +1436,15 @@ public final class Bukkit {
return server.getOnlineMode();
}
/**
* Retrieves the server configuration.
*
* @return the instance of ServerConfiguration containing the server's configuration details
*/
public static @NotNull ServerConfiguration getServerConfig() {
return server.getServerConfig();
}
/**
* Gets whether this server allows flying or not.
*

View File

@ -14,6 +14,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.logging.Logger;
import io.papermc.paper.configuration.ServerConfiguration;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
@ -1267,6 +1268,13 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
public boolean getOnlineMode();
/**
* Retrieves the server configuration.
*
* @return the instance of ServerConfiguration containing the server's configuration details
*/
@NotNull ServerConfiguration getServerConfig();
/**
* Gets whether this server allows flying or not.
*
@ -2319,6 +2327,7 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
* @deprecated Server config options may be renamed or removed without notice. Prefer using existing API
* wherever possible, rather than directly reading from a server config.
*
* @see #getServerConfig()
* @return The server's spigot config.
*/
@Deprecated(since = "1.21.4", forRemoval = true)
@ -2331,6 +2340,7 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
* @deprecated Server config options may be renamed or removed without notice. Prefer using existing API
* wherever possible, rather than directly reading from a server config.
*
* @see #getServerConfig()
* @return The server's bukkit config.
*/
// Paper start
@ -2345,6 +2355,7 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
* @deprecated Server config options may be renamed or removed without notice. Prefer using existing API
* wherever possible, rather than directly reading from a server config.
*
* @see #getServerConfig()
* @return The server's spigot config.
*/
@Deprecated(since = "1.21.4", forRemoval = true)
@ -2358,6 +2369,7 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
* @deprecated Server config options may be renamed or removed without notice. Prefer using existing API
* wherever possible, rather than directly reading from a server config.
*
* @see #getServerConfig()
* @return The server's paper config.
*/
@Deprecated(since = "1.21.4", forRemoval = true)

View File

@ -0,0 +1,9 @@
package io.papermc.paper.configuration;
public class PaperServerConfiguration implements ServerConfiguration {
@Override
public boolean isProxyOnlineMode() {
return GlobalConfiguration.get().proxies.isProxyOnlineMode();
}
}

View File

@ -12,6 +12,8 @@ import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.Lifecycle;
import io.papermc.paper.configuration.PaperServerConfiguration;
import io.papermc.paper.configuration.ServerConfiguration;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
@ -313,6 +315,7 @@ public final class CraftServer implements Server {
private final io.papermc.paper.logging.SysoutCatcher sysoutCatcher = new io.papermc.paper.logging.SysoutCatcher();
private final io.papermc.paper.potion.PaperPotionBrewer potionBrewer;
public final io.papermc.paper.SparksFly spark;
private final ServerConfiguration serverConfig = new PaperServerConfiguration();
// Paper start - Folia region threading API
private final io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler();
@ -1869,6 +1872,11 @@ public final class CraftServer implements Server {
return this.console.usesAuthentication();
}
@Override
public @NotNull ServerConfiguration getServerConfig() {
return serverConfig;
}
@Override
public boolean getAllowFlight() {
return this.console.isFlightAllowed();