Paper/src/main/java/net/minecraft/server/DedicatedServer.java

352 Zeilen
13 KiB
Java

2012-07-29 09:33:13 +02:00
package net.minecraft.server;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;
// CraftBukkit start
import java.io.PrintStream;
2013-03-13 23:33:27 +01:00
import java.util.logging.Level;
2012-07-29 09:33:13 +02:00
import org.bukkit.craftbukkit.LoggerOutputStream;
import org.bukkit.event.server.ServerCommandEvent;
// CraftBukkit end
public class DedicatedServer extends MinecraftServer implements IMinecraftServer {
2013-03-13 23:33:27 +01:00
private final List k = Collections.synchronizedList(new ArrayList());
private final IConsoleLogManager l;
2012-07-29 09:33:13 +02:00
private RemoteStatusListener m;
private RemoteControlListener n;
public PropertyManager propertyManager; // CraftBukkit - private -> public
private boolean generateStructures;
private EnumGamemode q;
private ServerConnection r;
private boolean s = false;
// CraftBukkit start - Signature changed
public DedicatedServer(joptsimple.OptionSet options) {
super(options);
// CraftBukkit end
2013-03-13 23:33:27 +01:00
this.l = new ConsoleLogManager("Minecraft-Server", (String) null, (String) null); // CraftBukkit - null last argument
2012-07-29 09:33:13 +02:00
new ThreadSleepForever(this);
}
protected boolean init() throws java.net.UnknownHostException { // CraftBukkit - throws UnknownHostException
ThreadCommandReader threadcommandreader = new ThreadCommandReader(this);
threadcommandreader.setDaemon(true);
threadcommandreader.start();
// CraftBukkit start
2013-03-13 23:33:27 +01:00
System.setOut(new PrintStream(new LoggerOutputStream(this.getLogger().getLogger(), Level.INFO), true));
System.setErr(new PrintStream(new LoggerOutputStream(this.getLogger().getLogger(), Level.SEVERE), true));
2012-07-29 09:33:13 +02:00
// CraftBukkit end
2013-03-20 21:09:23 +01:00
this.getLogger().info("Starting minecraft server version 1.5.1");
2012-07-29 09:33:13 +02:00
if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) {
2013-03-13 23:33:27 +01:00
this.getLogger().warning("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\"");
2012-07-29 09:33:13 +02:00
}
2013-03-13 23:33:27 +01:00
this.getLogger().info("Loading properties");
this.propertyManager = new PropertyManager(this.options, this.getLogger()); // CraftBukkit - CLI argument support
if (this.I()) {
this.d("127.0.0.1");
2012-07-29 09:33:13 +02:00
} else {
this.setOnlineMode(this.propertyManager.getBoolean("online-mode", true));
this.d(this.propertyManager.getString("server-ip", ""));
2012-07-29 09:33:13 +02:00
}
this.setSpawnAnimals(this.propertyManager.getBoolean("spawn-animals", true));
this.setSpawnNPCs(this.propertyManager.getBoolean("spawn-npcs", true));
this.setPvP(this.propertyManager.getBoolean("pvp", true));
this.setAllowFlight(this.propertyManager.getBoolean("allow-flight", false));
this.setTexturePack(this.propertyManager.getString("texture-pack", ""));
this.setMotd(this.propertyManager.getString("motd", "A Minecraft Server"));
2012-11-06 13:05:28 +01:00
if (this.propertyManager.getInt("difficulty", 1) < 0) {
this.propertyManager.a("difficulty", Integer.valueOf(0));
} else if (this.propertyManager.getInt("difficulty", 1) > 3) {
this.propertyManager.a("difficulty", Integer.valueOf(3));
}
2012-07-29 09:33:13 +02:00
this.generateStructures = this.propertyManager.getBoolean("generate-structures", true);
int i = this.propertyManager.getInt("gamemode", EnumGamemode.SURVIVAL.a());
this.q = WorldSettings.a(i);
2013-03-13 23:33:27 +01:00
this.getLogger().info("Default game type: " + this.q);
2012-07-29 09:33:13 +02:00
InetAddress inetaddress = null;
if (this.getServerIp().length() > 0) {
inetaddress = InetAddress.getByName(this.getServerIp());
}
if (this.G() < 0) {
2012-07-29 09:33:13 +02:00
this.setPort(this.propertyManager.getInt("server-port", 25565));
}
2013-03-13 23:33:27 +01:00
this.getLogger().info("Generating keypair");
2012-07-29 09:33:13 +02:00
this.a(MinecraftEncryption.b());
2013-03-13 23:33:27 +01:00
this.getLogger().info("Starting Minecraft server on " + (this.getServerIp().length() == 0 ? "*" : this.getServerIp()) + ":" + this.G());
2012-07-29 09:33:13 +02:00
try {
this.r = new DedicatedServerConnection(this, inetaddress, this.G());
2012-07-29 09:33:13 +02:00
} catch (Throwable ioexception) { // CraftBukkit - IOException -> Throwable
2013-03-13 23:33:27 +01:00
this.getLogger().warning("**** FAILED TO BIND TO PORT!");
this.getLogger().warning("The exception was: {0}", new Object[] { ioexception.toString()});
this.getLogger().warning("Perhaps a server is already running on that port?");
2012-07-29 09:33:13 +02:00
return false;
}
2012-12-20 05:03:52 +01:00
this.a((PlayerList) (new DedicatedPlayerList(this))); // CraftBukkit
2012-07-29 09:33:13 +02:00
if (!this.getOnlineMode()) {
2013-03-13 23:33:27 +01:00
this.getLogger().warning("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
this.getLogger().warning("The server will make no attempt to authenticate usernames. Beware.");
this.getLogger().warning("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
this.getLogger().warning("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
2012-07-29 09:33:13 +02:00
}
2012-12-20 05:03:52 +01:00
// this.a((PlayerList) (new DedicatedPlayerList(this))); // CraftBukkit - moved up
2012-07-29 09:33:13 +02:00
this.convertable = new WorldLoaderServer(server.getWorldContainer()); // CraftBukkit - moved from MinecraftServer constructor
long j = System.nanoTime();
if (this.J() == null) {
this.l(this.propertyManager.getString("level-name", "world"));
2012-07-29 09:33:13 +02:00
}
String s = this.propertyManager.getString("level-seed", "");
String s1 = this.propertyManager.getString("level-type", "DEFAULT");
String s2 = this.propertyManager.getString("generator-settings", "");
2012-07-29 09:33:13 +02:00
long k = (new Random()).nextLong();
if (s.length() > 0) {
try {
long l = Long.parseLong(s);
if (l != 0L) {
k = l;
}
} catch (NumberFormatException numberformatexception) {
k = (long) s.hashCode();
}
}
WorldType worldtype = WorldType.getType(s1);
if (worldtype == null) {
worldtype = WorldType.NORMAL;
}
this.d(this.propertyManager.getInt("max-build-height", 256));
this.d((this.getMaxBuildHeight() + 8) / 16 * 16);
this.d(MathHelper.a(this.getMaxBuildHeight(), 64, 256));
this.propertyManager.a("max-build-height", Integer.valueOf(this.getMaxBuildHeight()));
2013-03-13 23:33:27 +01:00
this.getLogger().info("Preparing level \"" + this.J() + "\"");
this.a(this.J(), this.J(), k, worldtype, s2);
2012-07-29 09:33:13 +02:00
long i1 = System.nanoTime() - j;
String s3 = String.format("%.3fs", new Object[] { Double.valueOf((double) i1 / 1.0E9D)});
2012-07-29 09:33:13 +02:00
2013-03-13 23:33:27 +01:00
this.getLogger().info("Done (" + s3 + ")! For help, type \"help\" or \"?\"");
2012-07-29 09:33:13 +02:00
if (this.propertyManager.getBoolean("enable-query", false)) {
2013-03-13 23:33:27 +01:00
this.getLogger().info("Starting GS4 status listener");
2012-07-29 09:33:13 +02:00
this.m = new RemoteStatusListener(this);
this.m.a();
}
if (this.propertyManager.getBoolean("enable-rcon", false)) {
2013-03-13 23:33:27 +01:00
this.getLogger().info("Starting remote control listener");
2012-07-29 09:33:13 +02:00
this.n = new RemoteControlListener(this);
this.n.a();
this.remoteConsole = new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(); // CraftBukkit
}
// CraftBukkit start
if (this.server.getBukkitSpawnRadius() > -1) {
2013-03-13 23:33:27 +01:00
this.getLogger().info("'settings.spawn-radius' in bukkit.yml has been moved to 'spawn-protection' in server.properties. I will move your config for you.");
2012-07-29 09:33:13 +02:00
this.propertyManager.properties.remove("spawn-protection");
this.propertyManager.getInt("spawn-protection", this.server.getBukkitSpawnRadius());
this.server.removeBukkitSpawnRadius();
2012-07-29 09:33:13 +02:00
this.propertyManager.savePropertiesFile();
}
return true;
}
public PropertyManager getPropertyManager() {
return this.propertyManager;
}
// CraftBukkit end
public boolean getGenerateStructures() {
return this.generateStructures;
}
public EnumGamemode getGamemode() {
return this.q;
}
public int getDifficulty() {
return Math.max(0, Math.min(3, this.propertyManager.getInt("difficulty", 1))); // CraftBukkit - clamp values
2012-07-29 09:33:13 +02:00
}
public boolean isHardcore() {
return this.propertyManager.getBoolean("hardcore", false);
}
protected void a(CrashReport crashreport) {
while (this.isRunning()) {
2013-03-13 23:33:27 +01:00
this.am();
2012-07-29 09:33:13 +02:00
try {
Thread.sleep(10L);
} catch (InterruptedException interruptedexception) {
interruptedexception.printStackTrace();
}
}
}
public CrashReport b(CrashReport crashreport) {
2012-08-25 02:51:51 +02:00
crashreport = super.b(crashreport);
2012-11-06 13:05:28 +01:00
crashreport.g().a("Is Modded", (Callable) (new CrashReportModded(this)));
crashreport.g().a("Type", (Callable) (new CrashReportType(this)));
2012-08-25 02:51:51 +02:00
return crashreport;
2012-07-29 09:33:13 +02:00
}
protected void p() {
2012-07-29 09:33:13 +02:00
System.exit(0);
}
2013-03-13 23:33:27 +01:00
public void r() { // CraftBukkit - protected -> public
super.r();
2013-03-13 23:33:27 +01:00
this.am();
2012-07-29 09:33:13 +02:00
}
public boolean getAllowNether() {
return this.propertyManager.getBoolean("allow-nether", true);
}
public boolean getSpawnMonsters() {
return this.propertyManager.getBoolean("spawn-monsters", true);
}
public void a(MojangStatisticsGenerator mojangstatisticsgenerator) {
2013-03-13 23:33:27 +01:00
mojangstatisticsgenerator.a("whitelist_enabled", Boolean.valueOf(this.an().getHasWhitelist()));
mojangstatisticsgenerator.a("whitelist_count", Integer.valueOf(this.an().getWhitelisted().size()));
2012-07-29 09:33:13 +02:00
super.a(mojangstatisticsgenerator);
}
public boolean getSnooperEnabled() {
return this.propertyManager.getBoolean("snooper-enabled", true);
}
public void issueCommand(String s, ICommandListener icommandlistener) {
2013-03-13 23:33:27 +01:00
this.k.add(new ServerCommand(s, icommandlistener));
2012-07-29 09:33:13 +02:00
}
2013-03-13 23:33:27 +01:00
public void am() {
while (!this.k.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.k.remove(0);
2012-07-29 09:33:13 +02:00
// CraftBukkit start - ServerCommand for preprocessing
ServerCommandEvent event = new ServerCommandEvent(this.console, servercommand.command);
this.server.getPluginManager().callEvent(event);
servercommand = new ServerCommand(event.getCommand(), servercommand.source);
// this.getCommandHandler().a(servercommand.source, servercommand.command); // Called in dispatchServerCommand
this.server.dispatchServerCommand(this.console, servercommand);
// CraftBukkit end
}
}
public boolean T() {
2012-07-29 09:33:13 +02:00
return true;
}
2013-03-13 23:33:27 +01:00
public DedicatedPlayerList an() {
2012-12-20 05:03:52 +01:00
return (DedicatedPlayerList) super.getPlayerList();
2012-07-29 09:33:13 +02:00
}
public ServerConnection ae() {
2012-07-29 09:33:13 +02:00
return this.r;
}
public int a(String s, int i) {
return this.propertyManager.getInt(s, i);
}
public String a(String s, String s1) {
return this.propertyManager.getString(s, s1);
}
public boolean a(String s, boolean flag) {
return this.propertyManager.getBoolean(s, flag);
}
public void a(String s, Object object) {
this.propertyManager.a(s, object);
}
public void a() {
this.propertyManager.savePropertiesFile();
}
public String b_() {
2012-07-29 09:33:13 +02:00
File file1 = this.propertyManager.c();
return file1 != null ? file1.getAbsolutePath() : "No settings file";
}
2013-03-13 23:33:27 +01:00
public void ao() {
2012-07-29 09:33:13 +02:00
ServerGUI.a(this);
this.s = true;
}
public boolean ag() {
2012-07-29 09:33:13 +02:00
return this.s;
}
public String a(EnumGamemode enumgamemode, boolean flag) {
return "";
}
public boolean getEnableCommandBlock() {
return this.propertyManager.getBoolean("enable-command-block", false);
}
public int getSpawnProtection() {
return this.propertyManager.getInt("spawn-protection", super.getSpawnProtection());
}
2013-03-13 23:33:27 +01:00
public boolean a(World world, int i, int j, int k, EntityHuman entityhuman) {
if (world.worldProvider.dimension != 0) {
return false;
} else if (this.an().getOPs().isEmpty()) {
return false;
} else if (this.an().isOp(entityhuman.name)) {
return false;
} else if (this.getSpawnProtection() <= 0) {
return false;
} else {
ChunkCoordinates chunkcoordinates = world.getSpawn();
int l = MathHelper.a(i - chunkcoordinates.x);
int i1 = MathHelper.a(k - chunkcoordinates.z);
int j1 = Math.max(l, i1);
return j1 <= this.getSpawnProtection();
}
}
public IConsoleLogManager getLogger() {
return this.l;
}
2012-12-20 05:03:52 +01:00
public PlayerList getPlayerList() {
2013-03-13 23:33:27 +01:00
return this.an();
2012-07-29 09:33:13 +02:00
}
}