Search in sources :

Example 1 with Key

use of net.glowstone.util.config.ServerConfig.Key in project Glowstone by GlowstoneMC.

the class GlowServer method parseArguments.

private static ServerConfig parseArguments(String... args) {
    Map<Key, Object> parameters = new EnumMap<>(Key.class);
    String configDirName = "config";
    String configFileName = "glowstone.yml";
    // Calculate acceptable parameters
    for (int i = 0; i < args.length; i++) {
        String opt = args[i];
        if (opt.isEmpty() || opt.charAt(0) != '-') {
            System.err.println("Ignored invalid option: " + opt);
            continue;
        }
        // Help and version
        if ("--help".equals(opt) || "-h".equals(opt) || "-?".equals(opt)) {
            System.out.println("Available command-line options:");
            System.out.println("  --help, -h, -?                 Shows this help message and exits.");
            System.out.println("  --version, -v                  Shows version information and exits.");
            System.out.println("  --configdir <directory>        Sets the configuration directory.");
            System.out.println("  --configfile <file>            Sets the configuration file.");
            System.out.println("  --port, -p <port>              Sets the server listening port.");
            System.out.println("  --host, -H <ip | hostname>     Sets the server listening address.");
            System.out.println("  --onlinemode, -o <onlinemode>  Sets the server's online-mode.");
            System.out.println("  --jline <true/false>           Enables or disables JLine console.");
            System.out.println("  --plugins-dir, -P <directory>  Sets the plugin directory to use.");
            System.out.println("  --worlds-dir, -W <directory>   Sets the world directory to use.");
            System.out.println("  --update-dir, -U <directory>   Sets the plugin update folder to use.");
            System.out.println("  --max-players, -M <director>   Sets the maximum amount of players.");
            System.out.println("  --world-name, -N <name>        Sets the main world name.");
            System.out.println("  --log-pattern, -L <pattern>    Sets the log file pattern (%D for date).");
            return null;
        } else if ("--version".equals(opt) || "-v".equals(opt)) {
            System.out.println("Glowstone version: " + GlowServer.class.getPackage().getImplementationVersion());
            System.out.println("Bukkit version:    " + GlowServer.class.getPackage().getSpecificationVersion());
            System.out.println("Minecraft version: " + GAME_VERSION + " protocol " + PROTOCOL_VERSION);
            return null;
        }
        // Below this point, options require parameters
        if (i == args.length - 1) {
            System.err.println("Ignored option specified without value: " + opt);
            continue;
        }
        switch(opt) {
            case "--configdir":
                configDirName = args[++i];
                break;
            case "--configfile":
                configFileName = args[++i];
                break;
            case "--port":
            case "-p":
                parameters.put(Key.SERVER_PORT, Integer.valueOf(args[++i]));
                break;
            case "--host":
            case "-H":
                parameters.put(Key.SERVER_IP, args[++i]);
                break;
            case "--onlinemode":
            case "-o":
                parameters.put(Key.ONLINE_MODE, Boolean.valueOf(args[++i]));
                break;
            case "--jline":
                parameters.put(Key.USE_JLINE, Boolean.valueOf(args[++i]));
                break;
            case "--plugins-dir":
            case "-P":
                parameters.put(Key.PLUGIN_FOLDER, args[++i]);
                break;
            case "--worlds-dir":
            case "-W":
                parameters.put(Key.WORLD_FOLDER, args[++i]);
                break;
            case "--update-dir":
            case "-U":
                parameters.put(Key.UPDATE_FOLDER, args[++i]);
                break;
            case "--max-players":
            case "-M":
                parameters.put(Key.MAX_PLAYERS, Integer.valueOf(args[++i]));
                break;
            case "--world-name":
            case "-N":
                parameters.put(Key.LEVEL_NAME, args[++i]);
                break;
            case "--log-pattern":
            case "-L":
                parameters.put(Key.LOG_FILE, args[++i]);
                break;
            default:
                System.err.println("Ignored invalid option: " + opt);
        }
    }
    File configDir = new File(configDirName);
    worldConfig = new WorldConfig(configDir, new File(configDir, "worlds.yml"));
    File configFile = new File(configDir, configFileName);
    return new ServerConfig(configDir, configFile, parameters);
}
Also used : ServerConfig(net.glowstone.util.config.ServerConfig) WorldConfig(net.glowstone.util.config.WorldConfig) JSONObject(org.json.simple.JSONObject) UuidListFile(net.glowstone.util.bans.UuidListFile) File(java.io.File) Key(net.glowstone.util.config.ServerConfig.Key)

Aggregations

File (java.io.File)1 UuidListFile (net.glowstone.util.bans.UuidListFile)1 ServerConfig (net.glowstone.util.config.ServerConfig)1 Key (net.glowstone.util.config.ServerConfig.Key)1 WorldConfig (net.glowstone.util.config.WorldConfig)1 JSONObject (org.json.simple.JSONObject)1