Search in sources :

Example 1 with WorldConfig

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

the class GlowServer method parseArguments.

private static ServerConfig parseArguments(String... args) {
    Map<Key, Object> parameters = new EnumMap<>(Key.class);
    @NonNls String configDirName = "config";
    @NonNls String configFileName = "glowstone.yml";
    // Calculate acceptable parameters
    for (int i = 0; i < args.length; i++) {
        @NonNls String opt = args[i];
        if (opt.isEmpty() || opt.charAt(0) != '-') {
            System.err.println(ConsoleMessages.Warn.Option.INVALID.get(opt));
        }
        // Help and version
        if ("--help".equals(opt) || "-h".equals(opt) || "-?".equals(opt)) {
            System.out.println(ConsoleMessages.Info.Option.HELP.get());
            return null;
        } else if ("--version".equals(opt) || "-v".equals(opt)) {
            System.out.println(ConsoleMessages.Info.Version.GLOWSTONE.get(GlowServer.class.getPackage().getImplementationVersion()));
            System.out.println(ConsoleMessages.Info.Version.BUKKIT.get(GlowServer.class.getPackage().getSpecificationVersion()));
            System.out.println(ConsoleMessages.Info.Version.MINECRAFT_CLIENT.get(GAME_VERSION, PROTOCOL_VERSION));
            return null;
        } else if ("--generate-config".equals(opt)) {
            generateConfigOnly = true;
        }
        // Below this point, options require parameters
        if (i == args.length - 1 && !"--generate-config".equals(opt)) {
            System.err.format(ConsoleMessages.Warn.Option.NO_VALUE.get(), 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;
            case "--generate-config":
                // previously handled
                break;
            default:
                System.err.format(ConsoleMessages.Warn.Option.INVALID.get(), 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 : NonNls(org.jetbrains.annotations.NonNls) ServerConfig(net.glowstone.util.config.ServerConfig) WorldConfig(net.glowstone.util.config.WorldConfig) EnumMap(java.util.EnumMap) UuidListFile(net.glowstone.util.bans.UuidListFile) File(java.io.File) LibraryKey(net.glowstone.util.library.LibraryKey) Key(net.glowstone.util.config.ServerConfig.Key) NamespacedKey(org.bukkit.NamespacedKey)

Aggregations

File (java.io.File)1 EnumMap (java.util.EnumMap)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 LibraryKey (net.glowstone.util.library.LibraryKey)1 NamespacedKey (org.bukkit.NamespacedKey)1 NonNls (org.jetbrains.annotations.NonNls)1