diff --git a/paper-api/src/main/java/io/papermc/paper/configuration/ServerConfiguration.java b/paper-api/src/main/java/io/papermc/paper/configuration/ServerConfiguration.java new file mode 100644 index 0000000000..86d1b609b8 --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/configuration/ServerConfiguration.java @@ -0,0 +1,24 @@ +package io.papermc.paper.configuration; + +/** + * Represents the configuration settings for a server. + *

+ * 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. + *

+ * This method returns true if: + *

+ * + * @return whether the server is in online mode or behind a proxy configured for online mode + */ + boolean isProxyOnlineMode(); +} diff --git a/paper-api/src/main/java/org/bukkit/Bukkit.java b/paper-api/src/main/java/org/bukkit/Bukkit.java index ee791bf629..c9ea6559f8 100644 --- a/paper-api/src/main/java/org/bukkit/Bukkit.java +++ b/paper-api/src/main/java/org/bukkit/Bukkit.java @@ -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. * diff --git a/paper-api/src/main/java/org/bukkit/Server.java b/paper-api/src/main/java/org/bukkit/Server.java index 5f649c86c9..ed899c4cb4 100644 --- a/paper-api/src/main/java/org/bukkit/Server.java +++ b/paper-api/src/main/java/org/bukkit/Server.java @@ -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) diff --git a/paper-server/src/main/java/io/papermc/paper/configuration/PaperServerConfiguration.java b/paper-server/src/main/java/io/papermc/paper/configuration/PaperServerConfiguration.java new file mode 100644 index 0000000000..14d0965f4c --- /dev/null +++ b/paper-server/src/main/java/io/papermc/paper/configuration/PaperServerConfiguration.java @@ -0,0 +1,9 @@ +package io.papermc.paper.configuration; + +public class PaperServerConfiguration implements ServerConfiguration { + + @Override + public boolean isProxyOnlineMode() { + return GlobalConfiguration.get().proxies.isProxyOnlineMode(); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 41bf483b13..1da86b25e3 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -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();