
* Size limiting (--log-limit <size in bytes>) * Rotation (--log-count <count of files>) * Custom naming (--log-pattern <filename pattern>) * Append (--log-append <true|false>) Note: This is done via command line and not bukkit-settings as that would require lots of refactoring of both core server and CraftBukkit due to the current initialisation ordering and depenencies. All settings default to that of the standard server
134 lines
5.2 KiB
Java
134 lines
5.2 KiB
Java
package org.bukkit.craftbukkit;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.text.SimpleDateFormat;
|
|
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 boolean useJline = true;
|
|
|
|
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("w", "world", "level-name"), "World directory")
|
|
.withRequiredArg()
|
|
.ofType(String.class)
|
|
.describedAs("World dir");
|
|
|
|
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");
|
|
|
|
acceptsAll(asList("d", "date-format"), "Format of the date to display in the console (for log entries)")
|
|
.withRequiredArg()
|
|
.ofType(SimpleDateFormat.class)
|
|
.describedAs("Log date format");
|
|
|
|
acceptsAll(asList("log-pattern"), "Specfies the log filename pattern")
|
|
.withRequiredArg()
|
|
.ofType(String.class)
|
|
.defaultsTo("server.log")
|
|
.describedAs("Log filename");
|
|
|
|
acceptsAll(asList("log-limit"), "Limits the maximum size of the log file (0 = unlimited)")
|
|
.withRequiredArg()
|
|
.ofType(Integer.class)
|
|
.defaultsTo(0)
|
|
.describedAs("Max log size");
|
|
|
|
acceptsAll(asList("log-count"), "Specified how many log files to cycle through")
|
|
.withRequiredArg()
|
|
.ofType(Integer.class)
|
|
.defaultsTo(1)
|
|
.describedAs("Log count");
|
|
|
|
acceptsAll(asList("log-append"), "Whether to append to the log file")
|
|
.withRequiredArg()
|
|
.ofType(Boolean.class)
|
|
.defaultsTo(true)
|
|
.describedAs("Log append");
|
|
|
|
acceptsAll(asList("b", "bukkit-settings"), "File for bukkit settings")
|
|
.withRequiredArg()
|
|
.ofType(File.class)
|
|
.defaultsTo(new File("bukkit.yml"))
|
|
.describedAs("Yml file");
|
|
|
|
acceptsAll(asList("nojline"), "Disables jline and emulates the vanilla console");
|
|
}
|
|
};
|
|
|
|
OptionSet options = null;
|
|
|
|
try {
|
|
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 {
|
|
useJline = !"jline.UnsupportedTerminal".equals(System.getProperty("jline.terminal"));
|
|
|
|
if (options.has("nojline")) {
|
|
System.setProperty("jline.terminal", "jline.UnsupportedTerminal");
|
|
System.setProperty("user.language", "en");
|
|
useJline = false;
|
|
}
|
|
|
|
MinecraftServer.main(options);
|
|
} catch (Throwable t) {
|
|
t.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
private static List<String> asList(String... params) {
|
|
return Arrays.asList(params);
|
|
}
|
|
}
|