Paper/nms-patches/DedicatedServer.patch

246 lines
11 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/DedicatedServer.java
+++ b/net/minecraft/server/DedicatedServer.java
2019-04-23 04:00:00 +02:00
@@ -25,6 +25,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();
2019-04-23 04:00:00 +02:00
@@ -38,8 +49,10 @@
@Nullable
private ServerGUI q;
2016-02-29 22:32:46 +01:00
2019-04-23 04:00:00 +02:00
- public DedicatedServer(File file, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory, String s) {
- super(file, Proxy.NO_PROXY, datafixer, new CommandDispatcher(true), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache, worldloadlistenerfactory, s);
+ // CraftBukkit start - Signature changed
2019-04-23 04:00:00 +02:00
+ public DedicatedServer(joptsimple.OptionSet options, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory, String s) {
+ super(options, Proxy.NO_PROXY, datafixer, new CommandDispatcher().init(true), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache, worldloadlistenerfactory, s);
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
this.propertyManager = dedicatedserversettings;
this.remoteControlCommandListener = new RemoteControlCommandListener(this);
2015-02-26 23:41:06 +01:00
Thread thread = new Thread("Server Infinisleeper") {
2019-04-23 04:00:00 +02:00
@@ -65,13 +78,27 @@
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;
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();
+ }
+ if (s != null && 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);
2019-04-23 04:00:00 +02:00
@@ -80,6 +107,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();
2019-04-23 04:00:00 +02:00
@@ -133,6 +181,12 @@
return false;
}
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ this.a((PlayerList) (new DedicatedPlayerList(this)));
+ 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.");
@@ -147,7 +201,7 @@
if (!NameReferencingFileConverter.e(this)) {
return false;
} else {
- this.a((PlayerList) (new DedicatedPlayerList(this)));
+ this.convertable = new Convertable(server.getWorldContainer().toPath(), server.getWorldContainer().toPath().resolve("../backups"), this.dataConverterManager); // CraftBukkit - moved from MinecraftServer constructor
long i = SystemUtils.getMonotonicNanos();
String s = dedicatedserverproperties.levelSeed;
String s1 = dedicatedserverproperties.generatorSettings;
@@ -177,7 +231,13 @@
if (worldtype == WorldType.FLAT) {
jsonobject.addProperty("flat_world_options", s1);
} else if (!s1.isEmpty()) {
- jsonobject = ChatDeserializer.a(s1);
+ // CraftBukkit start
2019-04-23 04:00:00 +02:00
+ try {
+ jsonobject = ChatDeserializer.a(s1);
+ } catch (Exception ex) {
+ DedicatedServer.LOGGER.warn("Invalid generator-settings, ignoring", ex);
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
}
2019-04-23 04:00:00 +02:00
this.a(this.getWorld(), this.getWorld(), j, worldtype, jsonobject);
@@ -199,6 +259,7 @@
DedicatedServer.LOGGER.info("Starting remote control listener");
this.remoteControlListener = new RemoteControlListener(this);
this.remoteControlListener.a();
+ 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) {
@@ -301,6 +362,7 @@
this.l.b();
}
2019-04-23 04:00:00 +02:00
+ System.exit(0); // CraftBukkit
}
2019-04-23 04:00:00 +02:00
@Override
@@ -334,7 +396,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
}
}
2019-04-23 04:00:00 +02:00
@@ -529,14 +599,61 @@
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) {
- this.remoteControlCommandListener.clearMessages();
- this.getCommandDispatcher().a(this.remoteControlCommandListener.f(), s);
- return this.remoteControlCommandListener.getMessages();
+ // CraftBukkit start - fire RemoteServerCommandEvent
2015-02-26 23:41:06 +01:00
+ Waitable<String> waitable = new Waitable<String>() {
+ @Override
+ protected String evaluate() {
2016-02-29 22:32:46 +01:00
+ remoteControlCommandListener.clearMessages();
2015-02-26 23:41:06 +01:00
+ // Event changes start
+ RemoteServerCommandEvent event = new RemoteServerCommandEvent(remoteConsole, s);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return "";
+ }
2015-02-26 23:41:06 +01:00
+ // Event change end
2018-07-15 02:00:00 +02:00
+ ServerCommand serverCommand = new ServerCommand(event.getCommand(), remoteControlCommandListener.f());
2015-02-26 23:41:06 +01:00
+ server.dispatchServerCommand(remoteConsole, serverCommand);
2016-02-29 22:32:46 +01:00
+ return remoteControlCommandListener.getMessages();
2015-02-26 23:41:06 +01:00
+ }
+ };
+ processQueue.add(waitable);
+ try {
+ return waitable.get();
+ } catch (java.util.concurrent.ExecutionException e) {
+ throw new RuntimeException("Exception processing rcon command " + s, e.getCause());
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt(); // Maintain interrupted state
+ throw new RuntimeException("Interrupted processing rcon command " + s, e);
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
}
public void setHasWhitelist(boolean flag) {
@@ -555,4 +672,16 @@
public boolean b(GameProfile gameprofile) {
return false;
}
2016-02-29 22:32:46 +01:00
+
+ // CraftBukkit start
+ @Override
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
}