2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/DedicatedServer.java
+++ b/net/minecraft/server/DedicatedServer.java
2016-02-29 22:32:46 +01:00
@@ -4,10 +4,9 @@
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
-import java.io.BufferedReader;
+
import java.io.File;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Proxy;
import java.util.Collections;
@@ -18,10 +17,20 @@
2014-11-25 22:32:16 +01:00
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;
2015-02-26 23:41:06 +01:00
+import org.bukkit.craftbukkit.util.Waitable;
+import org.bukkit.event.server.RemoteServerCommandEvent;
2014-11-25 22:32:16 +01:00
+// CraftBukkit end
+
public class DedicatedServer extends MinecraftServer implements IMinecraftServer {
private static final Logger LOGGER = LogManager.getLogger();
2016-02-29 22:32:46 +01:00
- private final List<ServerCommand> serverCommandQueue = Collections.synchronizedList(Lists.newArrayList());
+ private final List<ServerCommand> serverCommandQueue = Collections.synchronizedList(Lists.<ServerCommand>newArrayList()); // CraftBukkit - fix decompile error
2015-02-26 23:41:06 +01:00
private RemoteStatusListener m;
2016-02-29 22:32:46 +01:00
public final RemoteControlCommandListener remoteControlCommandListener = new RemoteControlCommandListener(this);
private RemoteControlListener o;
@@ -31,8 +40,10 @@
private WorldSettings.EnumGamemode s;
private boolean t;
- public DedicatedServer(File file, DataConverterManager dataconvertermanager, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache) {
- super(file, Proxy.NO_PROXY, dataconvertermanager, yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Signature changed
2016-02-29 22:32:46 +01:00
+ public DedicatedServer(joptsimple.OptionSet options, DataConverterManager dataconvertermanager, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache) {
+ super(options, Proxy.NO_PROXY, dataconvertermanager, yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
Thread thread = new Thread("Server Infinisleeper") {
{
this.setDaemon(true);
2016-02-29 22:32:46 +01:00
@@ -54,13 +65,27 @@
2015-02-26 23:41:06 +01:00
protected boolean init() throws IOException {
Thread thread = new Thread("Server console handler") {
public void run() {
- BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.Main.useConsole) {
+ return;
+ }
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
2015-02-26 23:41:06 +01:00
+ jline.console.ConsoleReader bufferedreader = reader; // CraftBukkit
String s;
try {
- while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning() && (s = bufferedreader.readLine()) != null) {
- DedicatedServer.this.issueCommand(s, DedicatedServer.this);
+ // CraftBukkit start - JLine disabling compatibility
+ while (!isStopped() && 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
+ issueCommand(s, DedicatedServer.this);
+ }
+ // CraftBukkit end
}
} catch (IOException ioexception) {
DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
2016-02-29 22:32:46 +01:00
@@ -69,6 +94,27 @@
2015-05-25 14:04:32 +02:00
}
};
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +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);
+ }
+ }
+
+ 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
+
2015-05-25 14:04:32 +02:00
thread.setDaemon(true);
thread.start();
2016-03-30 21:50:59 +02:00
DedicatedServer.LOGGER.info("Starting minecraft server version 1.9.2");
2016-02-29 22:32:46 +01:00
@@ -77,7 +123,7 @@
2014-11-25 22:32:16 +01:00
}
DedicatedServer.LOGGER.info("Loading properties");
- this.propertyManager = new PropertyManager(new File("server.properties"));
+ this.propertyManager = new PropertyManager(this.options); // CraftBukkit - CLI argument support
2016-02-29 22:32:46 +01:00
this.q = new EULA(new File("eula.txt"));
if (!this.q.a()) {
2014-11-25 22:32:16 +01:00
DedicatedServer.LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
2016-02-29 22:32:46 +01:00
@@ -133,6 +179,8 @@
2014-11-25 22:32:16 +01:00
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.");
2016-02-29 22:32:46 +01:00
@@ -147,7 +195,7 @@
2014-11-25 22:32:16 +01:00
if (!NameReferencingFileConverter.a(this.propertyManager)) {
return false;
} else {
- this.a((PlayerList) (new DedicatedPlayerList(this)));
2016-02-29 22:32:46 +01:00
+ this.convertable = new WorldLoaderServer(server.getWorldContainer(), this.getDataConverterManager()); // CraftBukkit - moved from MinecraftServer constructor
2014-11-25 22:32:16 +01:00
long j = System.nanoTime();
2016-02-29 22:32:46 +01:00
if (this.S() == null) {
@@ -205,7 +253,18 @@
2014-11-25 22:32:16 +01:00
DedicatedServer.LOGGER.info("Starting remote control listener");
2016-02-29 22:32:46 +01:00
this.o = new RemoteControlListener(this);
this.o.a();
+ this.remoteConsole = new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(this.remoteControlCommandListener); // CraftBukkit
2015-05-25 14:04:32 +02:00
+ }
+
2014-11-25 22:32:16 +01:00
+ // 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();
2015-05-25 14:04:32 +02:00
}
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2015-05-25 14:04:32 +02:00
2016-02-29 22:32:46 +01:00
if (this.aP() > 0L) {
2015-02-26 23:41:06 +01:00
Thread thread1 = new Thread(new ThreadWatchdog(this));
2016-02-29 22:32:46 +01:00
@@ -298,7 +357,7 @@
2015-02-26 23:41:06 +01:00
System.exit(0);
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
- protected void D() {
+ public void D() { // CraftBukkit - fix decompile error
super.D();
this.aL();
2014-11-25 22:32:16 +01:00
}
2016-03-03 06:56:07 +01:00
@@ -329,7 +388,15 @@
2016-02-29 22:32:46 +01:00
while (!this.serverCommandQueue.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.serverCommandQueue.remove(0);
2014-11-25 22:32:16 +01:00
- this.getCommandHandler().a(servercommand.source, servercommand.command);
+ // CraftBukkit start - ServerCommand for preprocessing
+ ServerCommandEvent event = new ServerCommandEvent(console, servercommand.command);
+ server.getPluginManager().callEvent(event);
2016-03-03 06:56:07 +01:00
+ if (event.isCancelled()) continue;
2014-11-25 22:32:16 +01:00
+ servercommand = new ServerCommand(event.getCommand(), servercommand.source);
+
+ // this.getCommandHandler().a(servercommand.source, servercommand.command); // Called in dispatchServerCommand
+ server.dispatchServerCommand(console, servercommand);
+ // CraftBukkit end
}
}
2016-03-03 06:56:07 +01:00
@@ -536,16 +603,70 @@
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-02-29 22:32:46 +01:00
+
2015-02-26 23:41:06 +01:00
+ result.append(plugins[i].getDescription().getName());
+ result.append(" ");
+ result.append(plugins[i].getDescription().getVersion().replaceAll(";", ","));
+ }
+ }
2016-02-29 22:32:46 +01:00
- public String executeRemoteCommand(String s) {
- this.remoteControlCommandListener.clearMessages();
- this.b.a(this.remoteControlCommandListener, s);
- return this.remoteControlCommandListener.getMessages();
2015-02-26 23:41:06 +01:00
+ 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() {
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);
2015-07-12 11:54:34 +02:00
+ if (event.isCancelled()) {
2015-07-17 13:18:48 +02:00
+ return "";
2015-07-12 11:54:34 +02:00
+ }
2015-02-26 23:41:06 +01:00
+ // Event change end
2016-02-29 22:32:46 +01:00
+ ServerCommand serverCommand = new ServerCommand(event.getCommand(), remoteControlCommandListener);
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
}
public PlayerList getPlayerList() {
2016-02-29 22:32:46 +01:00
return this.aM();
}
+
+ // CraftBukkit start
+ @Override
+ public PropertyManager getPropertyManager() {
+ return this.propertyManager;
+ }
+ // CraftBukkit end
}