2017-04-01 22:31:57 +02:00
package net.ME1312.SubServers.Host ;
import net.ME1312.SubServers.Host.API.Command ;
import net.ME1312.SubServers.Host.API.SubPluginInfo ;
import net.ME1312.SubServers.Host.Executable.SubCreator ;
2017-08-18 11:58:06 +02:00
import net.ME1312.SubServers.Host.Library.TextColor ;
2017-04-01 22:31:57 +02:00
import net.ME1312.SubServers.Host.Library.Util ;
import net.ME1312.SubServers.Host.Library.Version.Version ;
import net.ME1312.SubServers.Host.Network.Packet.* ;
2017-08-18 11:58:06 +02:00
import org.w3c.dom.Document ;
import org.w3c.dom.Node ;
import org.w3c.dom.NodeList ;
import org.xml.sax.InputSource ;
2017-04-01 22:31:57 +02:00
2017-08-18 11:58:06 +02:00
import javax.xml.parsers.DocumentBuilderFactory ;
import java.io.BufferedReader ;
import java.io.InputStreamReader ;
import java.io.StringReader ;
import java.net.URL ;
import java.nio.charset.Charset ;
2017-04-01 22:31:57 +02:00
import java.util.* ;
/ * *
* Command Class
* /
public class SubCommand {
private SubCommand ( ) { }
2017-04-16 19:02:14 +02:00
protected static void load ( ExHost host ) {
2017-04-01 22:31:57 +02:00
new Command ( null ) {
@Override
public void command ( String handle , String [ ] args ) {
if ( args . length = = 0 ) {
host . log . message . println (
System . getProperty ( " os.name " ) + ' ' + System . getProperty ( " os.version " ) + ',' ,
" Java " + System . getProperty ( " java.version " ) + ',' ,
2018-03-14 04:38:26 +01:00
" SubServers.Host v " + host . version . toExtendedString ( ) ) ;
new Thread ( ( ) - > {
try {
Document updxml = DocumentBuilderFactory . newInstance ( ) . newDocumentBuilder ( ) . parse ( new InputSource ( new StringReader ( Util . readAll ( new BufferedReader ( new InputStreamReader ( new URL ( " https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Host/maven-metadata.xml " ) . openStream ( ) , Charset . forName ( " UTF-8 " ) ) ) ) ) ) ) ;
2017-08-18 11:58:06 +02:00
2018-03-14 04:38:26 +01:00
NodeList updnodeList = updxml . getElementsByTagName ( " version " ) ;
Version updversion = host . version ;
2018-03-14 22:50:15 +01:00
int updcount = 0 ;
2018-03-14 04:38:26 +01:00
for ( int i = 0 ; i < updnodeList . getLength ( ) ; i + + ) {
Node node = updnodeList . item ( i ) ;
if ( node . getNodeType ( ) = = Node . ELEMENT_NODE ) {
2018-03-14 22:50:15 +01:00
if ( ! node . getTextContent ( ) . startsWith ( " - " ) & & ! node . getTextContent ( ) . equals ( host . version . toString ( ) ) & & new Version ( node . getTextContent ( ) ) . compareTo ( updversion ) > 0 ) {
2018-03-14 04:38:26 +01:00
updversion = new Version ( node . getTextContent ( ) ) ;
updcount + + ;
2017-08-18 11:58:06 +02:00
}
}
}
2018-03-14 22:50:15 +01:00
if ( updcount = = 0 ) {
2018-03-14 04:38:26 +01:00
host . log . message . println ( " You are on the latest version. " ) ;
} else {
host . log . message . println ( " You are " + updcount + " version " + ( ( updcount = = 1 ) ? " " : " s " ) + " behind. " ) ;
}
} catch ( Exception e ) {
}
} ) . start ( ) ;
2017-04-01 22:31:57 +02:00
} else if ( host . api . plugins . get ( args [ 0 ] . toLowerCase ( ) ) ! = null ) {
SubPluginInfo plugin = host . api . plugins . get ( args [ 0 ] . toLowerCase ( ) ) ;
host . log . message . println ( plugin . getName ( ) + " v " + plugin . getVersion ( ) + " by " + plugin . getAuthors ( ) . toString ( ) . substring ( 1 , plugin . getAuthors ( ) . toString ( ) . length ( ) - 1 ) ) ;
if ( plugin . getWebsite ( ) ! = null ) host . log . message . println ( plugin . getWebsite ( ) . toString ( ) ) ;
if ( plugin . getDescription ( ) ! = null ) host . log . message . println ( " " , plugin . getDescription ( ) ) ;
} else {
host . log . message . println ( " There is no plugin with that name " ) ;
}
}
} . usage ( " [plugin] " ) . description ( " Gets the version of the System and SubServers or the specified Plugin " ) . help (
" This command will print what OS you're running, your OS version, " ,
" your Java version, and the SubServers.Host version. " ,
" " ,
" If the [plugin] option is provided, it will print information about the specified plugin instead. " ,
" " ,
" Examples: " ,
" /version " ,
" /version ExamplePlugin "
) . register ( " ver " , " version " ) ;
new Command ( null ) {
@Override
public void command ( String handle , String [ ] args ) {
2018-01-02 23:29:25 +01:00
host . subdata . sendPacket ( new PacketDownloadServerList ( null , null , json - > {
2017-08-18 11:58:06 +02:00
int i = 0 ;
2017-08-26 07:19:59 +02:00
boolean sent = false ;
String div = TextColor . RESET + " , " ;
2018-01-22 03:49:18 +01:00
if ( json . getJSONObject ( " groups " ) . length ( ) > 0 ) {
host . log . message . println ( " Group/Server List: " ) ;
for ( String group : json . getJSONObject ( " groups " ) . keySet ( ) ) {
String message = " " ;
message + = TextColor . GOLD + group + TextColor . RESET + " : " ;
for ( String server : json . getJSONObject ( " groups " ) . getJSONObject ( group ) . keySet ( ) ) {
if ( i ! = 0 ) message + = div ;
if ( ! json . getJSONObject ( " groups " ) . getJSONObject ( group ) . getJSONObject ( server ) . keySet ( ) . contains ( " enabled " ) ) {
message + = TextColor . WHITE ;
} else if ( json . getJSONObject ( " groups " ) . getJSONObject ( group ) . getJSONObject ( server ) . getBoolean ( " temp " ) ) {
message + = TextColor . AQUA ;
} else if ( json . getJSONObject ( " groups " ) . getJSONObject ( group ) . getJSONObject ( server ) . getBoolean ( " running " ) ) {
message + = TextColor . GREEN ;
} else if ( json . getJSONObject ( " groups " ) . getJSONObject ( group ) . getJSONObject ( server ) . getBoolean ( " enabled " ) & & json . getJSONObject ( " groups " ) . getJSONObject ( group ) . getJSONObject ( server ) . getJSONArray ( " incompatible " ) . length ( ) = = 0 ) {
message + = TextColor . YELLOW ;
} else {
message + = TextColor . RED ;
}
message + = json . getJSONObject ( " groups " ) . getJSONObject ( group ) . getJSONObject ( server ) . getString ( " display " ) + " ( " + json . getJSONObject ( " groups " ) . getJSONObject ( group ) . getJSONObject ( server ) . getString ( " address " ) + ( ( server . equals ( json . getJSONObject ( " groups " ) . getJSONObject ( group ) . getJSONObject ( server ) . getString ( " display " ) ) ) ? " " : TextColor . stripColor ( div ) + server ) + " ) " ;
i + + ;
2017-08-26 07:19:59 +02:00
}
2018-01-22 03:49:18 +01:00
if ( i = = 0 ) message + = TextColor . RESET + " (none) " ;
host . log . message . println ( message ) ;
i = 0 ;
sent = true ;
2017-08-26 07:19:59 +02:00
}
2018-01-22 03:49:18 +01:00
if ( ! sent ) host . log . message . println ( TextColor . RESET + " (none) " ) ;
sent = false ;
2017-08-26 07:19:59 +02:00
}
ExHost h = host ;
host . log . message . println ( " Host/SubServer List: " ) ;
2017-08-18 11:58:06 +02:00
for ( String host : json . getJSONObject ( " hosts " ) . keySet ( ) ) {
String message = " " ;
if ( json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getBoolean ( " enabled " ) ) {
message + = TextColor . AQUA ;
} else {
message + = TextColor . RED ;
}
message + = json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getString ( " display " ) + " ( " + json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getString ( " address " ) + ( ( host . equals ( json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getString ( " display " ) ) ) ? " " : TextColor . stripColor ( div ) + host ) + " ) " + TextColor . RESET + " : " ;
2017-04-01 22:31:57 +02:00
for ( String subserver : json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getJSONObject ( " servers " ) . keySet ( ) ) {
2017-08-18 11:58:06 +02:00
if ( i ! = 0 ) message + = div ;
if ( json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getJSONObject ( " servers " ) . getJSONObject ( subserver ) . getBoolean ( " temp " ) ) {
message + = TextColor . AQUA ;
} else if ( json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getJSONObject ( " servers " ) . getJSONObject ( subserver ) . getBoolean ( " running " ) ) {
message + = TextColor . GREEN ;
} else if ( json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getJSONObject ( " servers " ) . getJSONObject ( subserver ) . getBoolean ( " enabled " ) & & json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getJSONObject ( " servers " ) . getJSONObject ( subserver ) . getJSONArray ( " incompatible " ) . length ( ) = = 0 ) {
message + = TextColor . YELLOW ;
} else {
message + = TextColor . RED ;
}
message + = json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getJSONObject ( " servers " ) . getJSONObject ( subserver ) . getString ( " display " ) + " ( " + json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getJSONObject ( " servers " ) . getJSONObject ( subserver ) . getString ( " address " ) . split ( " : " ) [ json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getJSONObject ( " servers " ) . getJSONObject ( subserver ) . getString ( " address " ) . split ( " : " ) . length - 1 ] + ( ( subserver . equals ( json . getJSONObject ( " hosts " ) . getJSONObject ( host ) . getJSONObject ( " servers " ) . getJSONObject ( subserver ) . getString ( " display " ) ) ) ? " " : TextColor . stripColor ( div ) + subserver ) + " ) " ;
i + + ;
2017-04-01 22:31:57 +02:00
}
2017-08-26 07:19:59 +02:00
if ( i = = 0 ) message + = TextColor . RESET + " (none) " ;
2017-08-18 11:58:06 +02:00
h . log . message . println ( message ) ;
i = 0 ;
2017-08-26 07:19:59 +02:00
sent = true ;
2017-04-01 22:31:57 +02:00
}
2017-08-26 07:19:59 +02:00
if ( ! sent ) host . log . message . println ( TextColor . RESET + " (none) " ) ;
2017-08-18 11:58:06 +02:00
host . log . message . println ( " Server List: " ) ;
String message = " " ;
2017-04-01 22:31:57 +02:00
for ( String server : json . getJSONObject ( " servers " ) . keySet ( ) ) {
2017-08-18 11:58:06 +02:00
if ( i ! = 0 ) message + = div ;
message + = TextColor . WHITE + json . getJSONObject ( " servers " ) . getJSONObject ( server ) . getString ( " display " ) + " ( " + json . getJSONObject ( " servers " ) . getJSONObject ( server ) . getString ( " address " ) + ( ( server . equals ( json . getJSONObject ( " servers " ) . getJSONObject ( server ) . getString ( " display " ) ) ) ? " " : TextColor . stripColor ( div ) + server ) + " ) " ;
i + + ;
2017-04-01 22:31:57 +02:00
}
2017-08-26 07:19:59 +02:00
if ( i = = 0 ) message + = TextColor . RESET + " (none) " ;
2017-08-18 11:58:06 +02:00
host . log . message . println ( message ) ;
2017-04-01 22:31:57 +02:00
} ) ) ;
}
} . description ( " Lists the available Hosts and Servers " ) . help (
" This command will print a list of the available Hosts and Servers. " ,
" You can then use these names in commands where applicable. " ,
" " ,
" Example: " ,
" /list "
) . register ( " list " ) ;
new Command ( null ) {
@Override
2017-08-15 11:58:48 +02:00
public void command ( String handle , String [ ] args ) {
if ( args . length > 0 ) {
host . subdata . sendPacket ( new PacketDownloadServerInfo ( args [ 0 ] . toLowerCase ( ) , json - > {
switch ( json . getString ( " type " ) . toLowerCase ( ) ) {
case " invalid " :
host . log . message . println ( " There is no server with that name " ) ;
break ;
case " subserver " :
host . log . message . println ( " Info on " + json . getJSONObject ( " server " ) . getString ( " display " ) + ':' ) ;
if ( ! json . getJSONObject ( " server " ) . getString ( " name " ) . equals ( json . getJSONObject ( " server " ) . getString ( " display " ) ) ) host . log . message . println ( " - Real Name: " + json . getJSONObject ( " server " ) . getString ( " name " ) ) ;
host . log . message . println ( " - Host: " + json . getJSONObject ( " server " ) . getString ( " host " ) ) ;
host . log . message . println ( " - Enabled: " + ( ( json . getJSONObject ( " server " ) . getBoolean ( " enabled " ) ) ? " yes " : " no " ) ) ;
2018-01-13 22:22:13 +01:00
host . log . message . println ( " - Editable: " + ( ( json . getJSONObject ( " server " ) . getBoolean ( " editable " ) ) ? " yes " : " no " ) ) ;
2017-08-26 07:19:59 +02:00
if ( json . getJSONObject ( " server " ) . getJSONArray ( " group " ) . length ( ) > 0 ) {
host . log . message . println ( " - Group: " ) ;
for ( int i = 0 ; i < json . getJSONObject ( " server " ) . getJSONArray ( " group " ) . length ( ) ; i + + )
host . log . message . println ( " - " + json . getJSONObject ( " server " ) . getJSONArray ( " group " ) . getString ( i ) ) ;
}
2017-08-15 11:58:48 +02:00
if ( json . getJSONObject ( " server " ) . getBoolean ( " temp " ) ) host . log . message . println ( " - Temporary: yes " ) ;
host . log . message . println ( " - Running: " + ( ( json . getJSONObject ( " server " ) . getBoolean ( " running " ) ) ? " yes " : " no " ) ) ;
host . log . message . println ( " - Logging: " + ( ( json . getJSONObject ( " server " ) . getBoolean ( " log " ) ) ? " yes " : " no " ) ) ;
2017-08-18 11:58:06 +02:00
host . log . message . println ( " - Address: " + json . getJSONObject ( " server " ) . getString ( " address " ) ) ;
2017-08-15 11:58:48 +02:00
host . log . message . println ( " - Auto Restart: " + ( ( json . getJSONObject ( " server " ) . getBoolean ( " auto-restart " ) ) ? " yes " : " no " ) ) ;
host . log . message . println ( " - Hidden: " + ( ( json . getJSONObject ( " server " ) . getBoolean ( " hidden " ) ) ? " yes " : " no " ) ) ;
if ( json . getJSONObject ( " server " ) . getJSONArray ( " incompatible-list " ) . length ( ) > 0 ) {
List < String > current = new ArrayList < String > ( ) ;
for ( int i = 0 ; i < json . getJSONObject ( " server " ) . getJSONArray ( " incompatible " ) . length ( ) ; i + + ) current . add ( json . getJSONObject ( " server " ) . getJSONArray ( " incompatible " ) . getString ( i ) . toLowerCase ( ) ) ;
host . log . message . println ( " - Incompatibilities: " ) ;
for ( int i = 0 ; i < json . getJSONObject ( " server " ) . getJSONArray ( " incompatible-list " ) . length ( ) ; i + + )
host . log . message . println ( " - " + json . getJSONObject ( " server " ) . getJSONArray ( " incompatible-list " ) . getString ( i ) + ( ( current . contains ( json . getJSONObject ( " server " ) . getJSONArray ( " incompatible-list " ) . getString ( i ) . toLowerCase ( ) ) ) ? " * " : " " ) ) ;
}
2018-01-13 22:22:13 +01:00
host . log . message . println ( " - Signature: " + json . getJSONObject ( " server " ) . getString ( " signature " ) ) ;
2017-08-15 11:58:48 +02:00
break ;
default :
host . log . message . println ( " That Server is not a SubServer " ) ;
}
} ) ) ;
} else {
host . log . message . println ( " Usage: " + handle + " <SubServer> " ) ;
}
}
2017-08-17 01:29:02 +02:00
} . usage ( " <SubServer> " ) . description ( " Gets information about a SubServer " ) . help (
2017-08-15 11:58:48 +02:00
" This command will print a list of information about " ,
" the specified SubServer. " ,
" " ,
" The <SubServer> argument is required, and should be the name of " ,
" the SubServer you want to obtain information about. " ,
" " ,
" Example: " ,
" /info ExampleServer "
) . register ( " info " , " status " ) ;
new Command ( null ) {
@Override
2017-04-01 22:31:57 +02:00
public void command ( String handle , String [ ] args ) {
if ( args . length > 0 ) {
host . subdata . sendPacket ( new PacketStartServer ( null , args [ 0 ] , json - > {
switch ( json . getInt ( " r " ) ) {
case 3 :
host . log . message . println ( " There is no server with that name " ) ;
break ;
case 4 :
host . log . message . println ( " That Server is not a SubServer " ) ;
break ;
case 5 :
if ( json . getString ( " m " ) . contains ( " Host " ) ) {
host . log . message . println ( " That SubServer's Host is not enabled " ) ;
} else {
host . log . message . println ( " That SubServer is not enabled " ) ;
}
break ;
case 6 :
host . log . message . println ( " That SubServer is already running " ) ;
break ;
2017-07-21 22:45:41 +02:00
case 7 :
host . log . message . println ( " That SubServer cannot start while these server(s) are running: " , json . getString ( " m " ) . split ( " : \\ s " ) [ 1 ] ) ;
break ;
2017-04-01 22:31:57 +02:00
case 0 :
case 1 :
host . log . message . println ( " Server was started successfully " ) ;
break ;
default :
host . log . warn . println ( " PacketStartServer(null, " + args [ 0 ] + " ) responded with: " + json . getString ( " m " ) ) ;
host . log . message . println ( " Server was started successfully " ) ;
break ;
}
} ) ) ;
} else {
host . log . message . println ( " Usage: " + handle + " <SubServer> " ) ;
}
}
} . usage ( " <SubServer> " ) . description ( " Starts a SubServer " ) . help (
" This command is used to start a SubServer on the network. " ,
" Once it has been started, you can control it via the other commands " ,
" " ,
" The <SubServer> argument is required, and should be the name of " ,
" the SubServer you want to start. " ,
" " ,
" Example: " ,
" /start ExampleServer "
) . register ( " start " ) ;
new Command ( null ) {
@Override
public void command ( String handle , String [ ] args ) {
if ( args . length > 0 ) {
host . subdata . sendPacket ( new PacketStopServer ( null , args [ 0 ] , false , json - > {
switch ( json . getInt ( " r " ) ) {
case 3 :
host . log . message . println ( " There is no server with that name " ) ;
break ;
case 4 :
host . log . message . println ( " That Server is not a SubServer " ) ;
break ;
case 5 :
host . log . message . println ( " That SubServer is not running " ) ;
break ;
case 0 :
case 1 :
host . log . message . println ( " Server was stopped successfully " ) ;
break ;
default :
host . log . warn . println ( " PacketStopServer(null, " + args [ 0 ] + " , false) responded with: " + json . getString ( " m " ) ) ;
host . log . message . println ( " Server was stopped successfully " ) ;
break ;
}
} ) ) ;
} else {
host . log . message . println ( " Usage: " + handle + " <SubServer> " ) ;
}
}
} . usage ( " <SubServer> " ) . description ( " Stops a SubServer " ) . help (
" This command is used to request a SubServer to stop via the network. " ,
" Stopping a SubServer in this way will run the stop command " ,
" specified in the server's configuration " ,
" " ,
" The <SubServer> argument is required, and should be the name of " ,
" the SubServer you want to stop. " ,
" " ,
" Example: " ,
" /stop ExampleServer "
) . register ( " stop " ) ;
new Command ( null ) {
@Override
public void command ( String handle , String [ ] args ) {
if ( args . length > 0 ) {
host . subdata . sendPacket ( new PacketStopServer ( null , args [ 0 ] , true , json - > {
switch ( json . getInt ( " r " ) ) {
case 3 :
host . log . message . println ( " There is no server with that name " ) ;
break ;
case 4 :
host . log . message . println ( " That Server is not a SubServer " ) ;
break ;
case 5 :
host . log . message . println ( " That SubServer is not running " ) ;
break ;
case 0 :
case 1 :
host . log . message . println ( " Server was terminated successfully " ) ;
break ;
default :
host . log . warn . println ( " PacketStopServer(null, " + args [ 0 ] + " , true) responded with: " + json . getString ( " m " ) ) ;
host . log . message . println ( " Server was terminated successfully " ) ;
break ;
}
} ) ) ;
} else {
host . log . message . println ( " Usage: " + handle + " <SubServer> " ) ;
}
}
} . usage ( " <SubServer> " ) . description ( " Terminates a SubServer " ) . help (
" This command is used to forcefully stop a SubServer on the network. " ,
" Stopping a SubServer in this way can make you lose unsaved data though, " ,
" so it is generally recommended to use this command only when it stops responding. " ,
" " ,
" The <SubServer> argument is required, and should be the name of " ,
" the SubServer you want to terminate. " ,
" " ,
" Example: " ,
" /kill ExampleServer "
) . register ( " kill " , " terminate " ) ;
new Command ( null ) {
@Override
public void command ( String handle , String [ ] args ) {
if ( args . length > 1 ) {
int i = 1 ;
String str = args [ 1 ] ;
if ( args . length > 2 ) {
do {
i + + ;
str = str + " " + args [ i ] ;
} while ( ( i + 1 ) ! = args . length ) ;
}
final String cmd = str ;
host . subdata . sendPacket ( new PacketCommandServer ( null , args [ 0 ] , cmd , json - > {
switch ( json . getInt ( " r " ) ) {
case 3 :
host . log . message . println ( " There is no server with that name " ) ;
break ;
case 4 :
host . log . message . println ( " That Server is not a SubServer " ) ;
break ;
case 5 :
host . log . message . println ( " That SubServer is not running " ) ;
break ;
case 0 :
case 1 :
host . log . message . println ( " Command was sent successfully " ) ;
break ;
default :
host . log . warn . println ( " PacketCommandServer(null, " + args [ 0 ] + " , / " + cmd + " ) responded with: " + json . getString ( " m " ) ) ;
host . log . message . println ( " Command was sent successfully " ) ;
break ;
}
} ) ) ;
} else {
host . log . message . println ( " Usage: " + handle + " <SubServer> <Command> [Args...] " ) ;
}
}
} . usage ( " <SubServer> " , " <Command> " , " [Args...] " ) . description ( " Sends a Command to a SubServer " ) . help (
" This command is used to send a command to a SubServer's Console via the network. " ,
" " ,
" The <SubServer> argument is required, and should be the name of " ,
" the SubServer you want to send a command to. " ,
" " ,
" The <Command> argument is required, and should be the command you " ,
" want to send, the following [Args...] will be passed to that command. " ,
" " ,
" Examples: " ,
" /cmd ExampleServer help " ,
" /cmd ExampleServer say Hello World! "
) . register ( " cmd " , " command " ) ;
new Command ( null ) {
@Override
public void command ( String handle , String [ ] args ) {
if ( args . length > 4 ) {
2017-07-23 06:32:57 +02:00
if ( Util . isException ( ( ) - > Integer . parseInt ( args [ 4 ] ) ) ) {
2017-04-01 22:31:57 +02:00
host . log . message . println ( " Invalid Port Number " ) ;
} else {
2017-07-23 06:32:57 +02:00
host . subdata . sendPacket ( new PacketCreateServer ( null , args [ 0 ] , args [ 1 ] , args [ 2 ] , new Version ( args [ 3 ] ) , Integer . parseInt ( args [ 4 ] ) , json - > {
2017-04-01 22:31:57 +02:00
switch ( json . getInt ( " r " ) ) {
case 3 :
host . log . message . println ( " There is already a SubServer with that name " ) ;
break ;
case 4 :
host . log . message . println ( " There is no host with that name " ) ;
break ;
case 6 :
2017-07-23 06:32:57 +02:00
host . log . message . println ( " There is no template with that name " ) ;
2017-04-01 22:31:57 +02:00
break ;
case 7 :
host . log . message . println ( " SubCreator cannot create servers before Minecraft 1.8 " ) ;
break ;
case 8 :
host . log . message . println ( " Invalid Port Number " ) ;
break ;
case 0 :
case 1 :
host . log . message . println ( " Launching SubCreator... " ) ;
break ;
default :
2017-07-23 06:32:57 +02:00
host . log . warn . println ( " PacketCreateServer(null, " + args [ 0 ] + " , " + args [ 1 ] + " , " + args [ 2 ] + " , " + args [ 3 ] + " , " + args [ 4 ] + " ) responded with: " + json . getString ( " m " ) ) ;
2017-04-01 22:31:57 +02:00
host . log . message . println ( " Launching SubCreator... " ) ;
break ;
}
} ) ) ;
}
} else {
2017-07-23 06:32:57 +02:00
host . log . message . println ( " Usage: " + handle + " <Name> <Host> <Template> <Version> <Port> " ) ;
2017-04-01 22:31:57 +02:00
}
}
2017-07-23 06:32:57 +02:00
} . usage ( " <Name> " , " <Host> " , " <Template> " , " <Version> " , " <Port> " ) . description ( " Creates a SubServer " ) . help (
2017-04-01 22:31:57 +02:00
" This command is used to create and launch a SubServer on the specified host via the network. " ,
2018-01-21 21:45:27 +01:00
" Templates are downloaded from SubServers.Bungee to ~/Templates. " ,
2017-04-01 22:31:57 +02:00
" " ,
" The <Name> argument is required, and should be the name of " ,
" the SubServer you want to create. " ,
" " ,
" The <Host> argument is required, and should be the name of " ,
" the host you want to the server to run on. " ,
" " ,
2018-01-21 21:45:27 +01:00
" The <Template> argument is required, and should be the name of " ,
" the template you want to create your server with. " ,
2017-04-01 22:31:57 +02:00
" " ,
" The <Version> argument is required, and should be a version " ,
" string of the type of server that you want to create " ,
" " ,
" The <Port> argument is required, and should be the port number " ,
" that you want the server to listen on after it has been created. " ,
" " ,
" If the [RAM] argument is provided, it will allocate in megabytes " ,
" the amount of RAM that the server will use after it has been created " ,
" " ,
" Examples: " ,
2017-07-23 06:32:57 +02:00
" /create ExampleServer ExampleHost Spigot 1.11 25565 "
2017-04-01 22:31:57 +02:00
) . register ( " create " ) ;
new Command ( null ) {
public void command ( String handle , String [ ] args ) {
HashMap < String , String > commands = new LinkedHashMap < String , String > ( ) ;
HashMap < Command , String > handles = new LinkedHashMap < Command , String > ( ) ;
int length = 0 ;
for ( String command : host . api . commands . keySet ( ) ) {
String formatted = " / " ;
Command cmd = host . api . commands . get ( command ) ;
String alias = ( handles . keySet ( ) . contains ( cmd ) ) ? handles . get ( cmd ) : null ;
if ( alias ! = null ) formatted = commands . get ( alias ) ;
if ( cmd . usage ( ) . length = = 0 | | alias ! = null ) {
formatted = formatted . replaceFirst ( " \\ s " , ( ( alias ! = null ) ? " | " : " " ) + command + ' ' ) ;
} else {
String usage = " " ;
for ( String str : cmd . usage ( ) ) usage + = ( ( usage . length ( ) = = 0 ) ? " " : " " ) + str ;
formatted = formatted . replaceFirst ( " \\ s " , command + ' ' + usage + ' ' ) ;
}
if ( formatted . length ( ) > length ) {
length = formatted . length ( ) ;
}
if ( alias = = null ) {
commands . put ( command , formatted ) ;
handles . put ( cmd , command ) ;
} else {
commands . put ( alias , formatted ) ;
}
}
if ( args . length = = 0 ) {
host . log . message . println ( " SubServers.Host Command List: " ) ;
for ( String command : commands . keySet ( ) ) {
String formatted = commands . get ( command ) ;
Command cmd = host . api . commands . get ( command ) ;
while ( formatted . length ( ) < length ) {
formatted + = ' ' ;
}
formatted + = ( ( cmd . description ( ) = = null | | cmd . description ( ) . length ( ) = = 0 ) ? " " : " - " + cmd . description ( ) ) ;
host . log . message . println ( formatted ) ;
}
} else if ( host . api . commands . keySet ( ) . contains ( ( args [ 0 ] . startsWith ( " / " ) ) ? args [ 0 ] . toLowerCase ( ) . substring ( 1 ) : args [ 0 ] . toLowerCase ( ) ) ) {
Command cmd = host . api . commands . get ( ( args [ 0 ] . startsWith ( " / " ) ) ? args [ 0 ] . toLowerCase ( ) . substring ( 1 ) : args [ 0 ] . toLowerCase ( ) ) ;
String formatted = commands . get ( Util . getBackwards ( host . api . commands , cmd ) . get ( 0 ) ) ;
host . log . message . println ( formatted . substring ( 0 , formatted . length ( ) - 1 ) ) ;
for ( String line : cmd . help ( ) ) {
host . log . message . println ( " " + line ) ;
}
} else {
host . log . message . println ( " There is no command with that name " ) ;
}
}
} . usage ( " [command] " ) . description ( " Prints a list of the commands and/or their descriptions " ) . help (
" This command will print a list of all currently registered commands and aliases, " ,
" along with their usage and a short description. " ,
" " ,
" If the [command] option is provided, it will print that command, it's aliases, " ,
" it's usage, and an extended description like the one you see here instead. " ,
" " ,
" Examples: " ,
" /help " ,
" /help end "
) . register ( " help " , " ? " ) ;
new Command ( null ) {
@Override
public void command ( String handle , String [ ] args ) {
host . stop ( 0 ) ;
}
} . description ( " Stops this SubServers instance " ) . help (
" This command will shutdown this instance of SubServers.Host, " ,
" SubServers running on this host, and any plugins currently running via SubAPI. " ,
" " ,
" Example: " ,
" /exit "
) . register ( " exit " , " end " ) ;
}
}