13
0
geforkt von Mirrors/Paper
Paper/nms-patches/DedicatedServer.patch

247 Zeilen
12 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/DedicatedServer.java
+++ b/net/minecraft/server/DedicatedServer.java
2020-06-25 02:00:00 +02:00
@@ -22,6 +22,17 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import java.io.PrintStream;
+import org.apache.logging.log4j.Level;
+
2018-07-15 02:00:00 +02:00
+import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.LoggerOutputStream;
+import org.bukkit.event.server.ServerCommandEvent;
2015-02-26 23:41:06 +01:00
+import org.bukkit.craftbukkit.util.Waitable;
+import org.bukkit.event.server.RemoteServerCommandEvent;
+// CraftBukkit end
+
public class DedicatedServer extends MinecraftServer implements IMinecraftServer {
private static final Logger LOGGER = LogManager.getLogger();
2020-06-25 02:00:00 +02:00
@@ -34,8 +45,10 @@
2019-04-23 04:00:00 +02:00
@Nullable
2020-06-25 02:00:00 +02:00
private ServerGUI q;
2016-02-29 22:32:46 +01:00
2020-08-11 23:00:00 +02:00
- public DedicatedServer(Thread thread, IRegistryCustom.Dimension iregistrycustom_dimension, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, DataPackResources datapackresources, SaveData savedata, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory) {
2020-06-25 02:00:00 +02:00
- super(thread, iregistrycustom_dimension, convertable_conversionsession, savedata, resourcepackrepository, Proxy.NO_PROXY, datafixer, datapackresources, minecraftsessionservice, gameprofilerepository, usercache, worldloadlistenerfactory);
+ // CraftBukkit start - Signature changed
2020-08-11 23:00:00 +02:00
+ public DedicatedServer(joptsimple.OptionSet options, DataPackConfiguration datapackconfiguration, Thread thread, IRegistryCustom.Dimension iregistrycustom_dimension, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, DataPackResources datapackresources, SaveData savedata, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory) {
2020-06-25 02:00:00 +02:00
+ super(options, datapackconfiguration, thread, iregistrycustom_dimension, convertable_conversionsession, savedata, resourcepackrepository, Proxy.NO_PROXY, datafixer, datapackresources, minecraftsessionservice, gameprofilerepository, usercache, worldloadlistenerfactory);
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
this.propertyManager = dedicatedserversettings;
this.remoteControlCommandListener = new RemoteControlCommandListener(this);
2020-06-25 02:00:00 +02:00
}
@@ -44,13 +57,44 @@
2019-04-23 04:00:00 +02:00
public boolean init() throws IOException {
2015-02-26 23:41:06 +01:00
Thread thread = new Thread("Server console handler") {
public void run() {
2017-05-14 04:00:00 +02:00
- BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.Main.useConsole) {
+ return;
+ }
2017-05-14 04:00:00 +02:00
+ jline.console.ConsoleReader bufferedreader = reader;
+
+ // MC-33041, SPIGOT-5538: if System.in is not valid due to javaw, then return
+ try {
+ System.in.available();
+ } catch (IOException ex) {
+ return;
+ }
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
String s;
try {
- while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning() && (s = bufferedreader.readLine()) != null) {
2018-07-15 02:00:00 +02:00
- DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener());
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - JLine disabling compatibility
2018-07-15 02:00:00 +02:00
+ while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning()) {
2015-02-26 23:41:06 +01:00
+ if (org.bukkit.craftbukkit.Main.useJline) {
+ s = bufferedreader.readLine(">", null);
+ } else {
+ s = bufferedreader.readLine();
+ }
+
+ // SPIGOT-5220: Throttle if EOF (ctrl^d) or stdin is /dev/null
+ if (s == null) {
+ try {
+ Thread.sleep(50L);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+ continue;
+ }
+ if (s.trim().length() > 0) { // Trim to filter lines which are just spaces
2018-07-15 02:00:00 +02:00
+ DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener());
2015-02-26 23:41:06 +01:00
+ }
+ // CraftBukkit end
}
} catch (IOException ioexception) {
DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
2020-06-25 02:00:00 +02:00
@@ -59,6 +103,27 @@
2015-05-25 14:04:32 +02:00
}
};
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - TODO: handle command-line logging arguments
+ java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
+ global.setUseParentHandlers(false);
+ for (java.util.logging.Handler handler : global.getHandlers()) {
+ global.removeHandler(handler);
+ }
+ global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());
+
+ 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);
+ }
+ }
+
2019-04-23 04:00:00 +02:00
+ new org.bukkit.craftbukkit.util.TerminalConsoleWriterThread(System.out, this.reader).start();
+
+ System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true));
+ System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true));
+ // CraftBukkit end
+
2015-05-25 14:04:32 +02:00
thread.setDaemon(true);
2018-07-15 02:00:00 +02:00
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER));
2015-05-25 14:04:32 +02:00
thread.start();
2020-06-25 02:00:00 +02:00
@@ -85,7 +150,7 @@
this.setForceGamemode(dedicatedserverproperties.forceGamemode);
super.setIdleTimeout((Integer) dedicatedserverproperties.playerIdleTimeout.get());
this.i(dedicatedserverproperties.enforceWhitelist);
- this.saveData.setGameType(dedicatedserverproperties.gamemode);
+ // this.saveData.setGameType(dedicatedserverproperties.gamemode); // CraftBukkit - moved to world loading
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
InetAddress inetaddress = null;
@@ -110,6 +175,12 @@
2019-04-23 04:00:00 +02:00
return false;
}
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ this.a((PlayerList) (new DedicatedPlayerList(this, this.f, this.worldNBTStorage)));
2019-04-23 04:00:00 +02:00
+ server.loadPlugins();
+ server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP);
+ // CraftBukkit end
+
2019-04-23 04:00:00 +02:00
if (!this.getOnlineMode()) {
DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
2020-06-25 02:00:00 +02:00
@@ -124,7 +195,7 @@
2019-04-23 04:00:00 +02:00
if (!NameReferencingFileConverter.e(this)) {
return false;
} else {
2020-06-25 02:00:00 +02:00
- this.a((PlayerList) (new DedicatedPlayerList(this, this.f, this.worldNBTStorage)));
+ // this.a((PlayerList) (new DedicatedPlayerList(this, this.f, this.worldNBTStorage))); // CraftBukkit - moved up
2019-04-23 04:00:00 +02:00
long i = SystemUtils.getMonotonicNanos();
2020-06-25 02:00:00 +02:00
this.c(dedicatedserverproperties.maxBuildHeight);
@@ -132,7 +203,7 @@
TileEntitySkull.a(this.getMinecraftSessionService());
UserCache.a(this.getOnlineMode());
DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getWorld());
- this.loadWorld();
+ this.loadWorld(convertable.getLevelName()); // CraftBukkit
long j = SystemUtils.getMonotonicNanos() - i;
String s = String.format(Locale.ROOT, "%.3fs", (double) j / 1.0E9D);
2020-08-11 23:00:00 +02:00
@@ -149,6 +220,7 @@
if (dedicatedserverproperties.enableRcon) {
2019-04-23 04:00:00 +02:00
DedicatedServer.LOGGER.info("Starting remote control listener");
2020-08-11 23:00:00 +02:00
this.remoteControlListener = RemoteControlListener.a((IMinecraftServer) this);
2019-04-23 04:00:00 +02:00
+ this.remoteConsole = new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(this.remoteControlCommandListener); // CraftBukkit
}
2016-06-09 03:43:49 +02:00
2019-04-23 04:00:00 +02:00
if (this.getMaxTickTime() > 0L) {
2020-08-11 23:00:00 +02:00
@@ -259,6 +331,7 @@
2019-06-21 12:00:00 +02:00
this.remoteStatusListener.b();
2019-04-23 04:00:00 +02:00
}
2019-04-23 04:00:00 +02:00
+ System.exit(0); // CraftBukkit
}
2019-04-23 04:00:00 +02:00
@Override
2020-08-11 23:00:00 +02:00
@@ -287,7 +360,15 @@
2016-02-29 22:32:46 +01:00
while (!this.serverCommandQueue.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.serverCommandQueue.remove(0);
2018-07-15 02:00:00 +02:00
- this.getCommandDispatcher().a(servercommand.source, servercommand.command);
+ // CraftBukkit start - ServerCommand for preprocessing
+ ServerCommandEvent event = new ServerCommandEvent(console, servercommand.command);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) continue;
+ servercommand = new ServerCommand(event.getCommand(), servercommand.source);
+
2018-07-15 02:00:00 +02:00
+ // this.getCommandDispatcher().a(servercommand.source, servercommand.command); // Called in dispatchServerCommand
+ server.dispatchServerCommand(console, servercommand);
+ // CraftBukkit end
}
}
2020-08-11 23:00:00 +02:00
@@ -497,14 +578,45 @@
2015-02-26 23:41:06 +01:00
2019-04-23 04:00:00 +02:00
@Override
2015-02-26 23:41:06 +01:00
public String getPlugins() {
- return "";
+ // CraftBukkit start - Whole method
+ StringBuilder result = new StringBuilder();
+ org.bukkit.plugin.Plugin[] plugins = server.getPluginManager().getPlugins();
+
+ result.append(server.getName());
+ result.append(" on Bukkit ");
+ result.append(server.getBukkitVersion());
+
+ if (plugins.length > 0 && server.getQueryPlugins()) {
+ result.append(": ");
+
+ for (int i = 0; i < plugins.length; i++) {
+ if (i > 0) {
+ result.append("; ");
+ }
+
2016-07-15 12:08:04 +02:00
+ result.append(plugins[i].getDescription().getName());
+ result.append(" ");
+ result.append(plugins[i].getDescription().getVersion().replaceAll(";", ","));
+ }
+ }
2018-12-13 01:00:00 +01:00
+
2015-02-26 23:41:06 +01:00
+ return result.toString();
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
}
@Override
public String executeRemoteCommand(String s) {
2019-06-21 12:00:00 +02:00
this.remoteControlCommandListener.clearMessages();
this.executeSync(() -> {
2019-07-20 01:00:00 +02:00
- this.getCommandDispatcher().a(this.remoteControlCommandListener.getWrapper(), s);
2019-06-21 12:00:00 +02:00
+ // CraftBukkit start - fire RemoteServerCommandEvent
+ RemoteServerCommandEvent event = new RemoteServerCommandEvent(remoteConsole, s);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
2015-02-26 23:41:06 +01:00
+ }
2019-07-20 01:00:00 +02:00
+ ServerCommand serverCommand = new ServerCommand(event.getCommand(), remoteControlCommandListener.getWrapper());
2019-06-21 12:00:00 +02:00
+ server.dispatchServerCommand(remoteConsole, serverCommand);
+ // CraftBukkit end
});
return this.remoteControlCommandListener.getMessages();
2019-04-23 04:00:00 +02:00
}
2020-08-11 23:00:00 +02:00
@@ -540,4 +652,15 @@
2020-06-25 02:00:00 +02:00
public boolean isSyncChunkWrites() {
return this.propertyManager.getProperties().syncChunkWrites;
2019-04-23 04:00:00 +02:00
}
2016-02-29 22:32:46 +01:00
+
+ // CraftBukkit start
2019-04-23 04:00:00 +02:00
+ public boolean isDebugging() {
+ return this.getDedicatedServerProperties().debug;
+ }
+
2018-07-15 02:00:00 +02:00
+ @Override
+ public CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
+ return console;
2019-04-23 04:00:00 +02:00
+ }
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
}