Search in sources :

Example 1 with WebServerConfig

use of de.dytanic.cloudnet.web.server.util.WebServerConfig in project CloudNet by Dytanic.

the class CloudConfig method load.

public CloudConfig load() throws Exception {
    try (InputStream inputStream = Files.newInputStream(configPath);
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
        Configuration configuration = CONFIGURATION_PROVIDER.load(inputStreamReader);
        this.config = configuration;
        String host = configuration.getString("server.hostaddress");
        Collection<ConnectableAddress> addresses = new ArrayList<>();
        for (int value : configuration.getIntList("server.ports")) {
            addresses.add(new ConnectableAddress(host, value));
        }
        this.addresses = addresses;
        this.wrapperKey = NetworkUtils.readWrapperKey();
        this.autoUpdate = configuration.getBoolean("general.auto-update");
        this.notifyService = configuration.getBoolean("general.notify-service");
        this.cloudDevServices = configuration.getBoolean("general.devservices");
        this.cloudDynamicServices = configuration.getBoolean("general.dynamicservices");
        this.webServerConfig = new WebServerConfig(true, configuration.getString("server.webservice.hostaddress"), configuration.getInt("server.webservice.port"));
        this.formatSplitter = configuration.getString("general.server-name-splitter");
        this.networkProperties = configuration.getSection("networkproperties").self;
        // configuration.set("general.disabled-modules", new ArrayList<>());
        if (!configuration.getSection("general").self.containsKey("disabled-modules")) {
            configuration.set("general.disabled-modules", new ArrayList<>());
            try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(configPath), StandardCharsets.UTF_8)) {
                CONFIGURATION_PROVIDER.save(configuration, outputStreamWriter);
            }
        }
        if (!configuration.getSection("general").self.containsKey("cloudGameServer-wrapperList")) {
            configuration.set("general.cloudGameServer-wrapperList", Arrays.asList("Wrapper-1"));
            try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(configPath), StandardCharsets.UTF_8)) {
                CONFIGURATION_PROVIDER.save(configuration, outputStreamWriter);
            }
        }
        this.disabledModules = configuration.getStringList("general.disabled-modules");
        this.cloudServerWrapperList = configuration.getStringList("general.cloudGameServer-wrapperList");
    }
    this.serviceDocument = Document.loadDocument(servicePath);
    this.wrappers = this.serviceDocument.getObject("wrapper", new TypeToken<List<WrapperMeta>>() {
    }.getType());
    this.userDocument = Document.loadDocument(usersPath);
    /* ============================================================== */
    return this;
}
Also used : InputStreamReader(java.io.InputStreamReader) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) InputStream(java.io.InputStream) ConnectableAddress(de.dytanic.cloudnet.lib.ConnectableAddress) WebServerConfig(de.dytanic.cloudnet.web.server.util.WebServerConfig) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)1 WebServerConfig (de.dytanic.cloudnet.web.server.util.WebServerConfig)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Configuration (net.md_5.bungee.config.Configuration)1 YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)1