Added command-line arguments, forced nogui

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
CraftBukkit/Spigot 2011-01-04 00:43:23 +00:00
parent 449fb6523a
commit fcc27e9e40
3 changed files with 74 additions and 4 deletions

View file

@ -27,6 +27,11 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.jopt-simple</groupId>
<artifactId>jopt-simple</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
<!-- This builds a completely 'ready to start' jar with all dependencies inside -->
<build>

View file

@ -27,7 +27,7 @@ public final class CraftServer implements Server {
pluginManager.RegisterInterface(JavaPluginLoader.class);
File pluginFolder = new File("plugins");
File pluginFolder = (File)console.options.valueOf("plugins");
if (pluginFolder.exists()) {
try {

View file

@ -1,16 +1,81 @@
package org.bukkit.craftbukkit;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import net.minecraft.server.MinecraftServer;
public class Main {
public static void main(String[] args) {
// Todo: Installation script
OptionParser parser = new OptionParser() {
{
acceptsAll(asList("?", "help"), "Show the help");
acceptsAll(asList("c", "config"), "Properties file to use")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("server.properties"))
.describedAs("Properties file");
acceptsAll(asList("P", "plugins"), "Plugin directory to use")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("plugins"))
.describedAs("Plugin directory");
acceptsAll(asList("h", "host", "server-ip"), "Host to listen on")
.withRequiredArg()
.ofType(String.class)
.describedAs("Hostname or IP");
acceptsAll(asList("p", "port", "server-port"), "Port to listen on")
.withRequiredArg()
.ofType(Integer.class)
.describedAs("Port");
acceptsAll(asList("o", "online-mode"), "Whether to use online authentication")
.withRequiredArg()
.ofType(Boolean.class)
.describedAs("Authentication");
acceptsAll(asList("s", "size", "max-players"), "Maximum amount of players")
.withRequiredArg()
.ofType(Integer.class)
.describedAs("Server size");
}
};
OptionSet options = null;
try {
MinecraftServer.main(args);
} catch (Throwable t) {
t.printStackTrace();
options = parser.parse(args);
} catch (joptsimple.OptionException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage());
}
if ((options == null) || (options.has("?"))) {
try {
parser.printHelpOn(System.out);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
try {
MinecraftServer.main(options);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
private static List<String> asList(String... params) {
return Arrays.asList(params);
}
}