Files
PlazmaBukkitMC/plazma-server/minecraft-patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch
2025-02-24 01:53:56 +09:00

296 lines
17 KiB
Diff

--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -61,8 +_,8 @@
public class DedicatedServer extends MinecraftServer implements ServerInterface {
static final Logger LOGGER = LogUtils.getLogger();
- private static final int CONVERSION_RETRY_DELAY_MS = 5000;
- private static final int CONVERSION_RETRIES = 2;
+ // private static final int CONVERSION_RETRY_DELAY_MS = 5000;
+ // private static final int CONVERSION_RETRIES = 2;
private final java.util.Queue<ConsoleInput> serverCommandQueue = new java.util.concurrent.ConcurrentLinkedQueue<>(); // Paper - Perf: use a proper queue
@Nullable
private QueryThreadGs4 queryThreadGs4;
@@ -105,47 +_,12 @@
public void run() {
// CraftBukkit start
if (!org.bukkit.craftbukkit.Main.useConsole) return;
+ // Plazma start - Improve code quality
// Paper start - Use TerminalConsoleAppender
- if (DedicatedServer.this.gui == null || System.console() != null) // Purpur - GUI Improvements - has no GUI or has console (did not double-click)
+ if (DedicatedServer.this.gui != null && System.console() == null) return;
new com.destroystokyo.paper.console.PaperConsole(DedicatedServer.this).start();
- /*
- jline.console.ConsoleReader bufferedreader = DedicatedServer.this.reader;
- // MC-33041, SPIGOT-5538: if System.in is not valid due to javaw, then return
- try {
- System.in.available();
- } catch (IOException ex) {
- return;
- }
- // CraftBukkit end
- String string1;
- try {
- // CraftBukkit start - JLine disabling compatibility
- while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning()) {
- if (org.bukkit.craftbukkit.Main.useJline) {
- string1 = bufferedreader.readLine(">", null);
- } else {
- string1 = bufferedreader.readLine();
- }
-
- // SPIGOT-5220: Throttle if EOF (ctrl^d) or stdin is /dev/null
- if (string1 == null) {
- try {
- Thread.sleep(50L);
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- continue;
- }
- if (string1.trim().length() > 0) { // Trim to filter lines which are just spaces
- DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener());
- }
- // CraftBukkit end
- }
- } catch (IOException var4) {
- DedicatedServer.LOGGER.error("Exception handling console input", (Throwable)var4);
- }
- */
- // Paper end
+ // Paper end - Use TerminalConsoleAppender
+ // Plazma end - Improve code quality
}
};
// CraftBukkit start - TODO: handle command-line logging arguments
@@ -156,21 +_,7 @@
}
global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());
- // Paper start - Not needed with TerminalConsoleAppender
- final org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getRootLogger();
- /*
- final org.apache.logging.log4j.core.Logger logger = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger());
- for (org.apache.logging.log4j.core.Appender appender : logger.getAppenders().values()) {
- if (appender instanceof org.apache.logging.log4j.core.appender.ConsoleAppender) {
- logger.removeAppender(appender);
- }
- }
-
- TerminalConsoleWriterThread writerThread = new TerminalConsoleWriterThread(System.out, this.reader);
- this.reader.setCompletionHandler(new TerminalCompletionHandler(writerThread, this.reader.getCompletionHandler()));
- writerThread.start();
- */
- // Paper end - Not needed with TerminalConsoleAppender
+ final org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getRootLogger(); // Paper - Not needed with TCA // Plazma - Remove commented codes
System.setOut(org.apache.logging.log4j.io.IoBuilder.forLogger(logger).setLevel(org.apache.logging.log4j.Level.INFO).buildPrintStream());
System.setErr(org.apache.logging.log4j.io.IoBuilder.forLogger(logger).setLevel(org.apache.logging.log4j.Level.WARN).buildPrintStream());
@@ -183,16 +_,6 @@
LOGGER.warn("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\"");
}
- // Paper start - detect running as root
- if (io.papermc.paper.util.ServerEnvironment.userIsRootOrAdmin()) {
- LOGGER.warn("****************************");
- LOGGER.warn("YOU ARE RUNNING THIS SERVER AS AN ADMINISTRATIVE OR ROOT USER. THIS IS NOT ADVISED.");
- LOGGER.warn("YOU ARE OPENING YOURSELF UP TO POTENTIAL RISKS WHEN DOING THIS.");
- LOGGER.warn("FOR MORE INFORMATION, SEE https://madelinemiller.dev/blog/root-minecraft-server/");
- LOGGER.warn("****************************");
- }
- // Paper end - detect running as root
-
LOGGER.info("Loading properties");
DedicatedServerProperties properties = this.settings.getProperties();
if (this.isSingleplayer()) {
@@ -208,6 +_,8 @@
org.spigotmc.SpigotConfig.init((java.io.File) this.options.valueOf("spigot-settings"));
org.spigotmc.SpigotConfig.registerCommands();
// Spigot end
+
+ // noinspection ResultOfMethodCallIgnored // Plazma - For preloading
io.papermc.paper.util.ObfHelper.INSTANCE.getClass(); // Paper - load mappings for stacktrace deobf and etc.
// Purpur start - Configurable void damage height and damage
try {
@@ -218,10 +_,27 @@
}
org.purpurmc.purpur.PurpurConfig.registerCommands();
// Purpur end - Configurable void damage height and damage
+
// Paper start - initialize global and world-defaults configuration
this.paperConfigurations.initializeGlobalConfiguration(this.registryAccess());
this.paperConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
// Paper end - initialize global and world-defaults configuration
+
+ // Plazma start - Configurable Plazma
+ this.plazmaConfigurations.initializeGlobalConfiguration(this.registryAccess());
+ this.plazmaConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
+ // Plazma end - Configurable Plazma
+
+ // Paper start - detect running as root // Plazma start - Tweak console logging (moved down)
+ if (org.plazmamc.plazma.Options.global().consoleLogs.rootUserWarning && io.papermc.paper.util.ServerEnvironment.userIsRootOrAdmin()) {
+ LOGGER.warn("****************************");
+ LOGGER.warn("YOU ARE RUNNING THIS SERVER AS AN ADMINISTRATIVE OR ROOT USER. THIS IS NOT ADVISED.");
+ LOGGER.warn("YOU ARE OPENING YOURSELF UP TO POTENTIAL RISKS WHEN DOING THIS.");
+ LOGGER.warn("FOR MORE INFORMATION, SEE https://madelinemiller.dev/blog/root-minecraft-server/");
+ LOGGER.warn("****************************");
+ }
+ // Paper end - detect running as root // Plazma end - Tweak console logging (moved down)
+
this.server.spark.enableEarlyIfRequested(); // Paper - spark
// Paper start - fix converting txt to json file; convert old users earlier after PlayerList creation but before file load/save
if (this.convertOldUsers()) {
@@ -234,16 +_,8 @@
io.papermc.paper.command.PaperCommands.registerCommands(this); // Paper - setup /paper command
this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics
- /*// Purpur start - Purpur config files // Purpur - Configurable void damage height and damage
- try {
- org.purpurmc.purpur.PurpurConfig.init((java.io.File) options.valueOf("purpur-settings"));
- } catch (Exception e) {
- DedicatedServer.LOGGER.error("Unable to load server configuration", e);
- return false;
- }
- org.purpurmc.purpur.PurpurConfig.registerCommands();
- */// Purpur end - Purpur config files // Purpur - Configurable void damage height and damage
- com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
+ // noinspection ResultOfMethodCallIgnored // Plazma - For preloading
+ com.destroystokyo.paper.VersionHistoryManager.initialize(options); // Paper - load version history now // Plazma - Add options to modify the configuration files
this.setPvpAllowed(properties.pvp);
this.setFlightAllowed(properties.allowFlight);
@@ -287,8 +_,7 @@
LOGGER.warn("**** FAILED TO BIND TO PORT!");
LOGGER.warn("The exception was: {}", var10.toString());
LOGGER.warn("Perhaps a server is already running on that port?");
- if (true) throw new IllegalStateException("Failed to bind to port", var10); // Paper - Propagate failed to bind to port error
- return false;
+ throw new IllegalStateException("Failed to bind to port", var10); // Paper - Propagate failed to bind to port error
}
// Purpur start - UPnP Port Forwarding
if (org.purpurmc.purpur.PurpurConfig.useUPnP) {
@@ -316,44 +_,33 @@
// Purpur end - UPnP Port Forwarding
// CraftBukkit start
- // this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // Spigot - moved up
this.server.loadPlugins();
this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP);
// CraftBukkit end
- // Paper start - Add Velocity IP Forwarding Support
- boolean usingProxy = org.spigotmc.SpigotConfig.bungee || io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled;
- String proxyFlavor = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "Velocity" : "BungeeCord";
- String proxyLink = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "https://docs.papermc.io/velocity/security" : "http://www.spigotmc.org/wiki/firewall-guide/";
- // Paper end - Add Velocity IP Forwarding Support
- if (!this.usesAuthentication()) {
- LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
+ // Plazma start - Tweak console logging
+ final boolean usingVelocity = io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled;
+ if (!this.usesAuthentication()
+ && org.plazmamc.plazma.Options.global().consoleLogs.offlineWarnings
+ && (!usingVelocity || !io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.onlineMode)
+ ) {
+ LOGGER.warn("********** SERVER IS RUNNING IN OFFLINE/INSECURE MODE! **********");
LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
- // Spigot start
- // Paper start - Add Velocity IP Forwarding Support
- if (usingProxy) {
- LOGGER.warn("Whilst this makes it possible to use {}, unless access to your server is properly restricted, it also opens up the ability for hackers to connect with any username they choose.", proxyFlavor);
- LOGGER.warn("Please see {} for further information.", proxyLink);
- // Paper end - Add Velocity IP Forwarding Support
+ if (usingVelocity || org.spigotmc.SpigotConfig.bungee) {
+ LOGGER.warn("Whilst this makes it possible to use {}, unless access to your server is properly restricted, it also opens up the ability for hackers to connect with any username they choose.", usingVelocity ? "Velocity" : "BungeeCord");
+ LOGGER.warn("Please see {} for further information.", usingVelocity ? "https://docs.papermc.io/velocity/security" : "https://www.spigotmc.org/wiki/firewall-guide/");
} else {
LOGGER.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
}
- // Spigot end
LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
- }
-
- // CraftBukkit start
- /*
- if (this.convertOldUsers()) {
- this.getProfileCache().save();
- }
- */
- // CraftBukkit end
+ LOGGER.warn("Or, if you understand exactly about this problem, and if you are prepared measures for it, change the \"console-logs.offline-warnings\" to \"false\" in the config/plazma-global.yml file.");
+ LOGGER.warn("This can suppress this warning, but you still need to be careful about related issues.");
+ }
+ // Plazma end - Tweak console logging
if (!OldUsersConverter.serverReadyAfterUserconversion(this)) {
return false;
} else {
- // this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // CraftBukkit - moved up
this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList());
this.tickTimeLogger = new RemoteSampleLogger(
TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME
@@ -380,14 +_,6 @@
this.rconThread = RconThread.create(this);
}
- if (false && this.getMaxTickLength() > 0L) { // Spigot - disable
- Thread thread1 = new Thread(new ServerWatchdog(this));
- thread1.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandlerWithName(LOGGER));
- thread1.setName("Server Watchdog");
- thread1.setDaemon(true);
- thread1.start();
- }
-
if (properties.enableJmxMonitoring) {
MinecraftServerStatistics.registerJmxMonitoring(this);
LOGGER.info("JMX monitoring enabled");
@@ -459,10 +_,6 @@
this.rconThread.stopNonBlocking(); // Paper - don't wait for remote connections
}
- if (this.queryThreadGs4 != null) {
- // this.remoteStatusListener.stop(); // Paper - don't wait for remote connections
- }
-
this.hasFullyShutdown = true; // Paper - Improved watchdog support
System.exit(this.abnormalExit ? 70 : 0); // CraftBukkit // Paper - Improved watchdog support
}
@@ -728,7 +_,7 @@
private void waitForRetry() {
try {
Thread.sleep(5000L);
- } catch (InterruptedException var2) {
+ } catch (InterruptedException ignore) { // Plazma - Fix IDE warning
}
}
@@ -748,7 +_,7 @@
org.bukkit.plugin.Plugin[] plugins = this.server.getPluginManager().getPlugins();
result.append(this.server.getName());
- result.append(" on Bukkit ");
+ result.append(" on Plazma "); // Plazma - Rebrand
result.append(this.server.getBukkitVersion());
if (plugins.length > 0 && this.server.getQueryPlugins()) {
@@ -759,9 +_,9 @@
result.append("; ");
}
- result.append(plugins[i].getDescription().getName());
+ result.append(plugins[i].getPluginMeta().getName()); // Plazma - Use modern method
result.append(" ");
- result.append(plugins[i].getDescription().getVersion().replaceAll(";", ","));
+ result.append(plugins[i].getPluginMeta().getVersion().replaceAll(";", ",")); // Plazma - Use modern method
}
}
@@ -876,7 +_,7 @@
private static ServerLinks createServerLinks(DedicatedServerSettings settings) {
Optional<URI> optional = parseBugReportLink(settings.getProperties());
- return optional.<ServerLinks>map(uri -> new ServerLinks(List.of(ServerLinks.KnownLinkType.BUG_REPORT.create(uri)))).orElse(ServerLinks.EMPTY);
+ return optional.map(uri -> new ServerLinks(List.of(ServerLinks.KnownLinkType.BUG_REPORT.create(uri)))).orElse(ServerLinks.EMPTY); // Plazma - Remove unnecessary type parameter
}
private static Optional<URI> parseBugReportLink(DedicatedServerProperties properties) {