2012-07-29 09:33:13 +02:00
package net.minecraft.server ;
import java.io.File ;
import java.io.IOException ;
import java.net.InetAddress ;
2013-11-04 14:07:38 +01:00
import java.net.Proxy ;
2012-07-29 09:33:13 +02:00
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.List ;
import java.util.Random ;
import java.util.concurrent.Callable ;
2013-11-04 14:07:38 +01:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2012-07-29 09:33:13 +02:00
// CraftBukkit start
import java.io.PrintStream ;
2013-11-04 14:07:38 +01:00
import org.apache.logging.log4j.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-11-04 14:07:38 +01:00
private static final Logger h = LogManager . getLogger ( ) ;
private final List i = Collections . synchronizedList ( new ArrayList ( ) ) ;
private RemoteStatusListener j ;
private RemoteControlListener k ;
2012-07-29 09:33:13 +02:00
public PropertyManager propertyManager ; // CraftBukkit - private -> public
private boolean generateStructures ;
2013-11-04 14:07:38 +01:00
private EnumGamemode n ;
private boolean o ;
2012-07-29 09:33:13 +02:00
// CraftBukkit start - Signature changed
public DedicatedServer ( joptsimple . OptionSet options ) {
2013-11-04 14:07:38 +01:00
super ( options , Proxy . NO_PROXY ) ;
// super(file1, Proxy.NO_PROXY);
2012-07-29 09:33:13 +02:00
// CraftBukkit end
2013-11-04 14:07:38 +01:00
new ThreadSleepForever ( this , " Server Infinisleeper " ) ;
2012-07-29 09:33:13 +02:00
}
protected boolean init ( ) throws java . net . UnknownHostException { // CraftBukkit - throws UnknownHostException
2013-11-04 14:07:38 +01:00
ThreadCommandReader threadcommandreader = new ThreadCommandReader ( this , " Server console handler " ) ;
2012-07-29 09:33:13 +02:00
threadcommandreader . setDaemon ( true ) ;
threadcommandreader . start ( ) ;
2013-12-01 18:15:18 +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 ) ;
2013-11-04 14:07:38 +01:00
}
2013-12-01 18:15:18 +01:00
global . addHandler ( new org . bukkit . craftbukkit . util . ForwardLogHandler ( ) ) ;
2013-11-04 14:07:38 +01:00
2013-12-01 18:15:18 +01:00
final org . apache . logging . log4j . core . Logger logger = ( ( org . apache . logging . log4j . core . Logger ) LogManager . getRootLogger ( ) ) ;
2013-12-01 20:21:22 +01:00
for ( org . apache . logging . log4j . core . Appender appender : logger . getAppenders ( ) . values ( ) ) {
if ( appender instanceof org . apache . logging . log4j . core . appender . ConsoleAppender ) {
logger . removeAppender ( appender ) ;
}
}
2013-11-04 14:07:38 +01:00
new Thread ( new org . bukkit . craftbukkit . util . TerminalConsoleWriterThread ( System . out , this . reader ) ) . start ( ) ;
2013-12-01 18:15:18 +01:00
System . setOut ( new PrintStream ( new LoggerOutputStream ( logger , Level . INFO ) , true ) ) ;
System . setErr ( new PrintStream ( new LoggerOutputStream ( logger , Level . WARN ) , true ) ) ;
2012-07-29 09:33:13 +02:00
// CraftBukkit end
2014-03-21 05:26:30 +01:00
h . info ( " Starting minecraft server version 1.7.5 " ) ;
2012-07-29 09:33:13 +02:00
if ( Runtime . getRuntime ( ) . maxMemory ( ) / 1024L / 1024L < 512L ) {
2013-11-04 14:07:38 +01:00
h . warn ( " 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-11-04 14:07:38 +01:00
h . info ( " Loading properties " ) ;
this . propertyManager = new PropertyManager ( this . options ) ; // CraftBukkit - CLI argument support
2014-03-21 05:26:30 +01:00
if ( this . M ( ) ) {
2013-07-01 13:03:00 +02:00
this . c ( " 127.0.0.1 " ) ;
2012-07-29 09:33:13 +02:00
} else {
this . setOnlineMode ( this . propertyManager . getBoolean ( " online-mode " , true ) ) ;
2013-07-01 13:03:00 +02:00
this . c ( 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 ) ) ;
2013-11-04 14:07:38 +01:00
this . setTexturePack ( this . propertyManager . getString ( " resource-pack " , " " ) ) ;
2012-07-29 09:33:13 +02:00
this . setMotd ( this . propertyManager . getString ( " motd " , " A Minecraft Server " ) ) ;
2013-04-27 11:40:05 +02:00
this . setForceGamemode ( this . propertyManager . getBoolean ( " force-gamemode " , false ) ) ;
2014-03-21 05:26:30 +01:00
this . setIdleTimeout ( this . propertyManager . getInt ( " player-idle-timeout " , 0 ) ) ;
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 ( ) ) ;
2013-11-04 14:07:38 +01:00
this . n = WorldSettings . a ( i ) ;
h . info ( " Default game type: " + this . n ) ;
2012-07-29 09:33:13 +02:00
InetAddress inetaddress = null ;
if ( this . getServerIp ( ) . length ( ) > 0 ) {
inetaddress = InetAddress . getByName ( this . getServerIp ( ) ) ;
}
2014-03-21 05:26:30 +01:00
if ( this . K ( ) < 0 ) {
2012-07-29 09:33:13 +02:00
this . setPort ( this . propertyManager . getInt ( " server-port " , 25565 ) ) ;
}
2013-11-04 14:07:38 +01:00
h . info ( " Generating keypair " ) ;
2012-07-29 09:33:13 +02:00
this . a ( MinecraftEncryption . b ( ) ) ;
2014-03-21 05:26:30 +01:00
h . info ( " Starting Minecraft server on " + ( this . getServerIp ( ) . length ( ) = = 0 ? " * " : this . getServerIp ( ) ) + " : " + this . K ( ) ) ;
2012-07-29 09:33:13 +02:00
try {
2014-03-21 05:26:30 +01:00
this . ah ( ) . a ( inetaddress , this . K ( ) ) ;
2012-07-29 09:33:13 +02:00
} catch ( Throwable ioexception ) { // CraftBukkit - IOException -> Throwable
2013-11-04 14:07:38 +01:00
h . warn ( " **** FAILED TO BIND TO PORT! " ) ;
h . warn ( " The exception was: {} " , new Object [ ] { ioexception . toString ( ) } ) ;
h . warn ( " 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-11-04 14:07:38 +01:00
h . warn ( " **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE! " ) ;
h . warn ( " The server will make no attempt to authenticate usernames. Beware. " ) ;
h . warn ( " 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. " ) ;
h . warn ( " 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 ( ) ;
2014-03-21 05:26:30 +01:00
if ( this . N ( ) = = null ) {
2013-07-01 13:03:00 +02:00
this . k ( 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 " ) ;
2012-10-25 05:53:23 +02:00
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 ;
}
2014-03-21 05:26:30 +01:00
this . as ( ) ;
2013-11-04 14:07:38 +01:00
this . getEnableCommandBlock ( ) ;
this . l ( ) ;
this . getSnooperEnabled ( ) ;
this . c ( this . propertyManager . getInt ( " max-build-height " , 256 ) ) ;
this . c ( ( this . getMaxBuildHeight ( ) + 8 ) / 16 * 16 ) ;
this . c ( MathHelper . a ( this . getMaxBuildHeight ( ) , 64 , 256 ) ) ;
2012-07-29 09:33:13 +02:00
this . propertyManager . a ( " max-build-height " , Integer . valueOf ( this . getMaxBuildHeight ( ) ) ) ;
2013-11-04 14:07:38 +01:00
h . info ( " Preparing level \" " + this . M ( ) + " \" " ) ;
2014-03-21 05:26:30 +01:00
this . a ( this . N ( ) , this . N ( ) , k , worldtype , s2 ) ;
2012-07-29 09:33:13 +02:00
long i1 = System . nanoTime ( ) - j ;
2012-10-25 05:53:23 +02:00
String s3 = String . format ( " %.3fs " , new Object [ ] { Double . valueOf ( ( double ) i1 / 1 . 0E9D ) } ) ;
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
h . info ( " Done ( " + s3 + " )! For help, type \" help \" or \" ? \" " ) ;
2012-07-29 09:33:13 +02:00
if ( this . propertyManager . getBoolean ( " enable-query " , false ) ) {
2013-11-04 14:07:38 +01:00
h . info ( " Starting GS4 status listener " ) ;
this . j = new RemoteStatusListener ( this ) ;
this . j . a ( ) ;
2012-07-29 09:33:13 +02:00
}
if ( this . propertyManager . getBoolean ( " enable-rcon " , false ) ) {
2013-11-04 14:07:38 +01:00
h . info ( " Starting remote control listener " ) ;
this . k = new RemoteControlListener ( this ) ;
this . k . a ( ) ;
2012-07-29 09:33:13 +02:00
this . remoteConsole = new org . bukkit . craftbukkit . command . CraftRemoteConsoleCommandSender ( ) ; // CraftBukkit
}
// CraftBukkit start
2012-10-28 06:30:09 +01:00
if ( this . server . getBukkitSpawnRadius ( ) > - 1 ) {
2013-11-04 14:07:38 +01:00
h . 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 " ) ;
2012-10-28 06:30:09 +01:00
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 ( ) {
2013-11-04 14:07:38 +01:00
return this . n ;
2012-07-29 09:33:13 +02:00
}
2013-11-04 14:07:38 +01:00
public EnumDifficulty getDifficulty ( ) {
return EnumDifficulty . a ( this . propertyManager . getInt ( " difficulty " , 1 ) ) ;
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 ( ) ) {
2014-03-21 05:26:30 +01:00
this . ax ( ) ;
2012-07-29 09:33:13 +02:00
try {
Thread . sleep ( 10L ) ;
} catch ( InterruptedException interruptedexception ) {
2013-11-04 14:07:38 +01:00
;
2012-07-29 09:33:13 +02:00
}
}
}
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
}
2014-03-21 05:26:30 +01:00
protected void t ( ) {
2012-07-29 09:33:13 +02:00
System . exit ( 0 ) ;
}
2014-03-21 05:26:30 +01:00
public void v ( ) { // CraftBukkit - protected -> public
super . v ( ) ;
this . ax ( ) ;
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 ) {
2014-03-21 05:26:30 +01:00
mojangstatisticsgenerator . a ( " whitelist_enabled " , Boolean . valueOf ( this . ay ( ) . getHasWhitelist ( ) ) ) ;
mojangstatisticsgenerator . a ( " whitelist_count " , Integer . valueOf ( this . ay ( ) . 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-11-04 14:07:38 +01:00
this . i . add ( new ServerCommand ( s , icommandlistener ) ) ;
2012-07-29 09:33:13 +02:00
}
2014-03-21 05:26:30 +01:00
public void ax ( ) {
2013-11-04 14:07:38 +01:00
while ( ! this . i . isEmpty ( ) ) {
ServerCommand servercommand = ( ServerCommand ) this . i . 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
}
}
2014-03-21 05:26:30 +01:00
public boolean W ( ) {
2012-07-29 09:33:13 +02:00
return true ;
}
2014-03-21 05:26:30 +01:00
public DedicatedPlayerList ay ( ) {
2012-12-20 05:03:52 +01:00
return ( DedicatedPlayerList ) super . getPlayerList ( ) ;
2012-07-29 09:33:13 +02:00
}
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 ( ) ;
}
2013-11-04 14:07:38 +01:00
public String b ( ) {
2012-07-29 09:33:13 +02:00
File file1 = this . propertyManager . c ( ) ;
return file1 ! = null ? file1 . getAbsolutePath ( ) : " No settings file " ;
}
2014-03-21 05:26:30 +01:00
public void az ( ) {
2012-07-29 09:33:13 +02:00
ServerGUI . a ( this ) ;
2013-11-04 14:07:38 +01:00
this . o = true ;
2012-07-29 09:33:13 +02:00
}
2014-03-21 05:26:30 +01:00
public boolean aj ( ) {
2013-11-04 14:07:38 +01:00
return this . o ;
2012-07-29 09:33:13 +02:00
}
public String a ( EnumGamemode enumgamemode , boolean flag ) {
return " " ;
}
2012-10-25 05:53:23 +02:00
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 ;
2014-03-21 05:26:30 +01:00
} else if ( this . ay ( ) . getOPs ( ) . isEmpty ( ) ) {
2013-03-13 23:33:27 +01:00
return false ;
2014-03-21 05:26:30 +01:00
} else if ( this . ay ( ) . isOp ( entityhuman . getName ( ) ) ) {
2013-03-13 23:33:27 +01:00
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 ( ) ;
}
}
2013-11-04 14:07:38 +01:00
public int l ( ) {
2013-07-01 13:03:00 +02:00
return this . propertyManager . getInt ( " op-permission-level " , 4 ) ;
2013-03-13 23:33:27 +01:00
}
2014-03-21 05:26:30 +01:00
public void setIdleTimeout ( int i ) {
super . setIdleTimeout ( i ) ;
2013-09-19 20:25:08 +02:00
this . propertyManager . a ( " player-idle-timeout " , Integer . valueOf ( i ) ) ;
this . a ( ) ;
}
2014-03-21 05:26:30 +01:00
public boolean m ( ) {
return this . propertyManager . getBoolean ( " broadcast-rcon-to-ops " , true ) ;
2013-11-04 14:07:38 +01:00
}
2014-03-21 05:26:30 +01:00
public boolean as ( ) {
return this . propertyManager . getBoolean ( " announce-player-achievements " , true ) ;
}
2012-12-20 05:03:52 +01:00
public PlayerList getPlayerList ( ) {
2014-03-21 05:26:30 +01:00
return this . ay ( ) ;
2013-11-04 14:07:38 +01:00
}
2014-03-21 05:26:30 +01:00
static Logger aA ( ) {
2013-11-04 14:07:38 +01:00
return h ;
2012-07-29 09:33:13 +02:00
}
}