summaryrefslogtreecommitdiffstats
path: root/nms-patches/DedicatedServer.patch
blob: 68c4b08c2ac7bbe504f3a6655aafe6fa91bdbc04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
--- a/net/minecraft/server/DedicatedServer.java
+++ b/net/minecraft/server/DedicatedServer.java
@@ -23,6 +23,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;
+
+import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.LoggerOutputStream;
+import org.bukkit.event.server.ServerCommandEvent;
+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();
@@ -37,8 +48,10 @@
     private EnumGamemode p;
     private boolean q;
 
-    public DedicatedServer(File file, DataFixer datafixer, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache) {
-        super(file, Proxy.NO_PROXY, datafixer, new CommandDispatcher(true), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache);
+    // CraftBukkit start - Signature changed
+    public DedicatedServer(joptsimple.OptionSet options, DataFixer datafixer, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache) {
+        super(options, Proxy.NO_PROXY, datafixer, new CommandDispatcher().init(true), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache);
+        // CraftBukkit end
         Thread thread = new Thread("Server Infinisleeper") {
             {
                 this.setDaemon(true);
@@ -58,16 +71,30 @@
         };
     }
 
-    protected boolean init() throws IOException {
+    public boolean init() throws IOException { // CraftBukkit - decompile error
         Thread thread = new Thread("Server console handler") {
             public void run() {
-                BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
+                // CraftBukkit start
+                if (!org.bukkit.craftbukkit.Main.useConsole) {
+                    return;
+                }
+                jline.console.ConsoleReader bufferedreader = reader;
+                // CraftBukkit end
 
                 String s;
 
                 try {
-                    while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning() && (s = bufferedreader.readLine()) != null) {
-                        DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener());
+                    // CraftBukkit start - JLine disabling compatibility
+                    while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning()) {
+                        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
+                            DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener());
+                        }
+                        // CraftBukkit end
                     }
                 } catch (IOException ioexception) {
                     DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
@@ -76,6 +103,27 @@
             }
         };
 
+        // 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);
+            }
+        }
+
+        new Thread(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
+
         thread.setDaemon(true);
         thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER));
         thread.start();
@@ -85,7 +133,7 @@
         }
 
         DedicatedServer.LOGGER.info("Loading properties");
-        this.propertyManager = new PropertyManager(new File("server.properties"));
+        this.propertyManager = new PropertyManager(this.options); // CraftBukkit - CLI argument support
         this.eula = new EULA(new File("eula.txt"));
         if (!this.eula.a()) {
             DedicatedServer.LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
@@ -143,6 +191,12 @@
                 return false;
             }
 
+            // CraftBukkit start
+            this.a((PlayerList) (new DedicatedPlayerList(this)));
+            server.loadPlugins();
+            server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP);
+            // CraftBukkit end
+
             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.");
@@ -157,7 +211,7 @@
             if (!NameReferencingFileConverter.a(this.propertyManager)) {
                 return false;
             } else {
-                this.a((PlayerList) (new DedicatedPlayerList(this)));
+                this.convertable = new WorldLoaderServer(server.getWorldContainer().toPath(), server.getWorldContainer().toPath().resolve("../backups"), this.dataConverterManager); // CraftBukkit - moved from MinecraftServer constructor
                 long j = SystemUtils.getMonotonicNanos();
 
                 if (this.getWorld() == null) {
@@ -204,7 +258,13 @@
                 if (worldtype == WorldType.FLAT) {
                     jsonobject.addProperty("flat_world_options", s2);
                 } else if (!s2.isEmpty()) {
-                    jsonobject = ChatDeserializer.a(s2);
+                    // CraftBukkit start
+                    try {
+                        jsonobject = ChatDeserializer.a(s2);
+                    } catch (Exception ex) {
+                        DedicatedServer.LOGGER.warn("Invalid generator-settings, ignoring", ex);
+                    }
+                    // CraftBukkit end
                 }
 
                 this.a(this.getWorld(), this.getWorld(), k, worldtype, jsonobject);
@@ -228,8 +288,19 @@
                     DedicatedServer.LOGGER.info("Starting remote control listener");
                     this.l = new RemoteControlListener(this);
                     this.l.a();
+                    this.remoteConsole = new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(this.remoteControlCommandListener); // CraftBukkit
                 }
 
+                // CraftBukkit start
+                if (this.server.getBukkitSpawnRadius() > -1) {
+                    DedicatedServer.LOGGER.info("'settings.spawn-radius' in bukkit.yml has been moved to 'spawn-protection' in server.properties. I will move your config for you.");
+                    this.propertyManager.properties.remove("spawn-protection");
+                    this.propertyManager.getInt("spawn-protection", this.server.getBukkitSpawnRadius());
+                    this.server.removeBukkitSpawnRadius();
+                    this.propertyManager.savePropertiesFile();
+                }
+                // CraftBukkit end
+
                 if (this.getMaxTickTime() > 0L) {
                     Thread thread1 = new Thread(new ThreadWatchdog(this));
 
@@ -303,11 +374,11 @@
         return crashreport;
     }
 
-    protected void t() {
+    public void t() { // CraftBukkit - decompile error
         System.exit(0);
     }
 
-    protected void b(BooleanSupplier booleansupplier) {
+    public void b(BooleanSupplier booleansupplier) { // CraftBukkit - fix decompile error
         super.b(booleansupplier);
         this.handleCommandQueue();
     }
@@ -342,7 +413,15 @@
         while (!this.serverCommandQueue.isEmpty()) {
             ServerCommand servercommand = (ServerCommand) this.serverCommandQueue.remove(0);
 
-            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);
+
+            // this.getCommandDispatcher().a(servercommand.source, servercommand.command); // Called in dispatchServerCommand
+            server.dispatchServerCommand(console, servercommand);
+            // CraftBukkit end
         }
 
     }
@@ -549,12 +628,71 @@
     }
 
     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("; ");
+                }
+
+                result.append(plugins[i].getDescription().getName());
+                result.append(" ");
+                result.append(plugins[i].getDescription().getVersion().replaceAll(";", ","));
+            }
+        }
+
+        return result.toString();
+        // CraftBukkit end
+    }
+
+    // CraftBukkit start - fire RemoteServerCommandEvent
+    public String executeRemoteCommand(final String s) {
+        Waitable<String> waitable = new Waitable<String>() {
+            @Override
+            protected String evaluate() {
+                remoteControlCommandListener.clearMessages();
+                // Event changes start
+                RemoteServerCommandEvent event = new RemoteServerCommandEvent(remoteConsole, s);
+                server.getPluginManager().callEvent(event);
+                if (event.isCancelled()) {
+                    return "";
+                }
+                // Event change end
+                ServerCommand serverCommand = new ServerCommand(event.getCommand(), remoteControlCommandListener.f());
+                server.dispatchServerCommand(remoteConsole, serverCommand);
+                return remoteControlCommandListener.getMessages();
+            }
+        };
+        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
+    }
+
+    // CraftBukkit start
+    @Override
+    public PropertyManager getPropertyManager() {
+        return this.propertyManager;
     }
 
-    public String executeRemoteCommand(String s) {
-        this.remoteControlCommandListener.clearMessages();
-        this.getCommandDispatcher().a(this.remoteControlCommandListener.f(), s);
-        return this.remoteControlCommandListener.getMessages();
+    @Override
+    public CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
+        return console;
     }
+    // CraftBukkit end
 }