summaryrefslogtreecommitdiffstats
path: root/nms-patches/DedicatedServer.patch
blob: 7b6eb346c832113ece801623b9d283030fef0a3b (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
--- ../work/decompile-8eb82bde//net/minecraft/server/DedicatedServer.java	2014-11-28 17:43:43.033707436 +0000
+++ src/main/java/net/minecraft/server/DedicatedServer.java	2014-11-28 17:38:22.000000000 +0000
@@ -13,6 +13,14 @@
 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.craftbukkit.LoggerOutputStream;
+import org.bukkit.event.server.ServerCommandEvent;
+// CraftBukkit end
+
 public class DedicatedServer extends MinecraftServer implements IMinecraftServer {
 
     private static final Logger LOGGER = LogManager.getLogger();
@@ -25,23 +33,48 @@
     private EnumGamemode q;
     private boolean r;
 
-    public DedicatedServer(File file) {
-        super(file, Proxy.NO_PROXY, DedicatedServer.a);
+    // CraftBukkit start - Signature changed
+    public DedicatedServer(joptsimple.OptionSet options) {
+        super(options, Proxy.NO_PROXY, a);
+        // super(file, Proxy.NO_PROXY, a);
+        // CraftBukkit end
         new ThreadSleepForever(this, "Server Infinisleeper");
     }
 
-    protected boolean init() {
+    protected boolean init() throws java.net.UnknownHostException { // CraftBukkit - throws UnknownHostException
         ThreadCommandReader threadcommandreader = new ThreadCommandReader(this, "Server console handler");
 
         threadcommandreader.setDaemon(true);
         threadcommandreader.start();
+
+        // 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
+
         DedicatedServer.LOGGER.info("Starting minecraft server version 1.8");
         if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) {
             DedicatedServer.LOGGER.warn("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\"");
         }
 
         DedicatedServer.LOGGER.info("Loading properties");
-        this.propertyManager = new PropertyManager(new File("server.properties"));
+        this.propertyManager = new PropertyManager(this.options); // CraftBukkit - CLI argument support
         this.o = new EULA(new File("eula.txt"));
         if (!this.o.a()) {
             DedicatedServer.LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
@@ -90,13 +123,15 @@
 
             try {
                 this.ao().a(inetaddress, this.Q());
-            } catch (IOException ioexception) {
+            } catch (Throwable ioexception) { // CraftBukkit - IOException -> Throwable
                 DedicatedServer.LOGGER.warn("**** FAILED TO BIND TO PORT!");
                 DedicatedServer.LOGGER.warn("The exception was: {}", new Object[] { ioexception.toString()});
                 DedicatedServer.LOGGER.warn("Perhaps a server is already running on that port?");
                 return false;
             }
 
+            this.a((PlayerList) (new DedicatedPlayerList(this))); // CraftBukkit
+
             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.");
@@ -111,7 +146,8 @@
             if (!NameReferencingFileConverter.a(this.propertyManager)) {
                 return false;
             } else {
-                this.a((PlayerList) (new DedicatedPlayerList(this)));
+                // this.a((PlayerList) (new DedicatedPlayerList(this))); // CraftBukkit - moved up
+                this.convertable = new WorldLoaderServer(server.getWorldContainer()); // CraftBukkit - moved from MinecraftServer constructor
                 long j = System.nanoTime();
 
                 if (this.T() == null) {
@@ -166,7 +202,18 @@
                     DedicatedServer.LOGGER.info("Starting remote control listener");
                     this.m = new RemoteControlListener(this);
                     this.m.a();
+                    this.remoteConsole = new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(); // 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.aQ() > 0L) {
                     Thread thread = new Thread(new ThreadWatchdog(this));
@@ -181,6 +228,12 @@
         }
     }
 
+    // CraftBukkit start
+    public PropertyManager getPropertyManager() {
+        return this.propertyManager;
+    }
+    // CraftBukkit end
+
     public void setGamemode(EnumGamemode enumgamemode) {
         super.setGamemode(enumgamemode);
         this.q = enumgamemode;
@@ -203,6 +256,7 @@
     }
 
     protected void a(CrashReport crashreport) {
+        /* CraftBukkit start - not sure why you would want to continue running commands once the server crashed
         while (this.isRunning()) {
             this.aM();
 
@@ -212,7 +266,7 @@
                 ;
             }
         }
-
+        // CraftBukkit end */        
     }
 
     public CrashReport b(CrashReport crashreport) {
@@ -257,7 +311,14 @@
         while (!this.k.isEmpty()) {
             ServerCommand servercommand = (ServerCommand) this.k.remove(0);
 
-            this.getCommandHandler().a(servercommand.source, servercommand.command);
+            // CraftBukkit start - ServerCommand for preprocessing
+            ServerCommandEvent event = new ServerCommandEvent(console, servercommand.command);
+            server.getPluginManager().callEvent(event);
+            servercommand = new ServerCommand(event.getCommand(), servercommand.source);
+
+            // this.getCommandHandler().a(servercommand.source, servercommand.command); // Called in dispatchServerCommand
+            server.dispatchServerCommand(console, servercommand);
+            // CraftBukkit end
         }
 
     }