From acf5f2f443e58520feee6ee8cd06f2d9178fc60e Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 25 Sep 2014 11:13:23 +1000 Subject: [PATCH] Fix bootstrap Java 7 warner so that it actually works! --- .../main/java/net/md_5/bungee/Bootstrap.java | 71 +------------------ .../net/md_5/bungee/BungeeCordLauncher.java | 64 +++++++++++++++++ 2 files changed, 67 insertions(+), 68 deletions(-) create mode 100644 bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java diff --git a/bootstrap/src/main/java/net/md_5/bungee/Bootstrap.java b/bootstrap/src/main/java/net/md_5/bungee/Bootstrap.java index 69ca3861..b7cb81e2 100644 --- a/bootstrap/src/main/java/net/md_5/bungee/Bootstrap.java +++ b/bootstrap/src/main/java/net/md_5/bungee/Bootstrap.java @@ -1,82 +1,17 @@ package net.md_5.bungee; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.concurrent.TimeUnit; -import joptsimple.OptionParser; -import joptsimple.OptionSet; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.command.ConsoleCommandSender; - public class Bootstrap { - private static List list(String... params) - { - return Arrays.asList( params ); - } - - /** - * Starts a new instance of BungeeCord. - * - * @param args command line arguments, currently none are used - * @throws Exception when the server cannot be started - */ public static void main(String[] args) throws Exception { if ( Float.parseFloat( System.getProperty( "java.class.version" ) ) < 51.0 ) { - System.err.println( "*** ERROR *** BungeeCord requires Java 7 or above to function!" ); + System.err.println( "*** ERROR *** BungeeCord requires Java 7 or above to function! Please download and install it!" ); + System.out.println( "You can check your Java version with the command: java -version" ); return; } - OptionParser parser = new OptionParser(); - parser.allowsUnrecognizedOptions(); - parser.acceptsAll( list( "v", "version" ) ); - - OptionSet options = parser.parse( args ); - - if ( options.has( "version" ) ) - { - System.out.println( Bootstrap.class.getPackage().getImplementationVersion() ); - return; - } - - if ( BungeeCord.class.getPackage().getSpecificationVersion() != null && System.getProperty( "IReallyKnowWhatIAmDoingISwear" ) == null ) - { - Date buildDate = new SimpleDateFormat( "yyyyMMdd" ).parse( BungeeCord.class.getPackage().getSpecificationVersion() ); - - Calendar deadline = Calendar.getInstance(); - deadline.add( Calendar.WEEK_OF_YEAR, -3 ); - if ( buildDate.before( deadline.getTime() ) ) - { - System.err.println( "*** Warning, this build is outdated ***" ); - System.err.println( "*** Please download a new build from http://ci.md-5.net/job/BungeeCord ***" ); - System.err.println( "*** You will get NO support regarding this build ***" ); - System.err.println( "*** Server will start in 30 seconds ***" ); - Thread.sleep( TimeUnit.SECONDS.toMillis( 30 ) ); - } - } - - BungeeCord bungee = new BungeeCord(); - ProxyServer.setInstance( bungee ); - bungee.getLogger().info( "Enabled BungeeCord version " + bungee.getVersion() ); - bungee.start(); - - while ( bungee.isRunning ) - { - String line = bungee.getConsoleReader().readLine( ">" ); - if ( line != null ) - { - if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) ) - { - bungee.getConsole().sendMessage( ChatColor.RED + "Command not found" ); - } - } - } + BungeeCordLauncher.main( args ); } } diff --git a/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java new file mode 100644 index 00000000..629bded4 --- /dev/null +++ b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java @@ -0,0 +1,64 @@ +package net.md_5.bungee; + +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.concurrent.TimeUnit; +import joptsimple.OptionParser; +import joptsimple.OptionSet; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.command.ConsoleCommandSender; + +public class BungeeCordLauncher +{ + + public static void main(String[] args) throws Exception + { + OptionParser parser = new OptionParser(); + parser.allowsUnrecognizedOptions(); + parser.acceptsAll( Arrays.asList( "v", "version" ) ); + + OptionSet options = parser.parse( args ); + + if ( options.has( "version" ) ) + { + System.out.println( Bootstrap.class.getPackage().getImplementationVersion() ); + return; + } + + if ( BungeeCord.class.getPackage().getSpecificationVersion() != null && System.getProperty( "IReallyKnowWhatIAmDoingISwear" ) == null ) + { + Date buildDate = new SimpleDateFormat( "yyyyMMdd" ).parse( BungeeCord.class.getPackage().getSpecificationVersion() ); + + Calendar deadline = Calendar.getInstance(); + deadline.add( Calendar.WEEK_OF_YEAR, -3 ); + if ( buildDate.before( deadline.getTime() ) ) + { + System.err.println( "*** Warning, this build is outdated ***" ); + System.err.println( "*** Please download a new build from http://ci.md-5.net/job/BungeeCord ***" ); + System.err.println( "*** You will get NO support regarding this build ***" ); + System.err.println( "*** Server will start in 30 seconds ***" ); + Thread.sleep( TimeUnit.SECONDS.toMillis( 30 ) ); + } + } + + BungeeCord bungee = new BungeeCord(); + ProxyServer.setInstance( bungee ); + bungee.getLogger().info( "Enabled BungeeCord version " + bungee.getVersion() ); + bungee.start(); + + while ( bungee.isRunning ) + { + String line = bungee.getConsoleReader().readLine( ">" ); + if ( line != null ) + { + if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) ) + { + bungee.getConsole().sendMessage( ChatColor.RED + "Command not found" ); + } + } + } + } +}