Java Code Examples for ninja.leaping.configurate.ConfigurationNode#removeChild()

The following examples show how to use ninja.leaping.configurate.ConfigurationNode#removeChild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationVersionUtil.java    From AntiVPN with MIT License 5 votes vote down vote up
private static void to20(ConfigurationNode config) {
    // Rabbit -> Messaging
    boolean rabbitEnabled = config.getNode("rabbit", "enabled").getBoolean();
    String rabbitAddress = config.getNode("rabbit", "address").getString("");
    int rabbitPort = config.getNode("rabbit", "port").getInt(5672);
    String rabbitUser = config.getNode("rabbit", "user").getString("guest");
    String rabbitPass = config.getNode("rabbit", "pass").getString("guest");
    config.removeChild("rabbit");
    config.getNode("messaging", "type").setValue((rabbitEnabled) ? "rabbit" : "bungee");
    config.getNode("messaging", "rabbit", "address").setValue(rabbitAddress);
    config.getNode("messaging", "rabbit", "port").setValue(rabbitPort);
    config.getNode("messaging", "rabbit", "user").setValue(rabbitUser);
    config.getNode("messaging", "rabbit", "pass").setValue(rabbitPass);

    // sources.order String -> List
    String[] order = config.getNode("sources", "order").getString("").split(",\\s?");
    config.getNode("sources", "order").setValue(Arrays.asList(order));

    // Add ignore
    config.getNode("ignore").setValue(Arrays.asList("127.0.0.1", "localhost", "::1"));

    // Remove async
    config.removeChild("async");

    // Version
    config.getNode("version").setValue(2.0d);
}
 
Example 2
Source File: ConfigurationVersionUtil.java    From AntiVPN with MIT License 5 votes vote down vote up
private static void to37(ConfigurationNode config) {
    // Remove kick->enabled
    boolean kickEnabled = config.getNode("kick", "enabled").getBoolean(true);

    // Rename kick->message to action->kick-message
    String kickMessage = config.getNode("kick", "message").getString("");
    config.getNode("action", "kick-message").setValue(kickEnabled ? kickMessage : "");

    // Rename kick->algorithm to action->algorithm
    String algorithmMethod = config.getNode("kick", "algorithm", "method").getString("");
    double algorithmConsensus = config.getNode("kick", "algorithm", "min-consensus").getDouble(0.6d);

    config.getNode("action", "algorithm", "method").setValue(algorithmMethod);
    config.getNode("action", "algorithm", "min-consensus").setValue(algorithmConsensus);

    // Rename kick->ignore to action->ignore
    List<String> ignore;
    try {
        ignore = new ArrayList<>(config.getNode("kick", "ignore").getList(TypeToken.of(String.class)));
    } catch (Exception ex) {
        ignore = new ArrayList<>();
    }

    config.getNode("action", "ignore").setValue(ignore);

    // Remove kick
    config.removeChild("kick");

    // Add action->command
    config.getNode("action", "command").setValue("");

    // Version
    config.getNode("version").setValue(3.7d);
}
 
Example 3
Source File: ConfigurationVersionUtil.java    From AntiVPN with MIT License 4 votes vote down vote up
private static void to33(ConfigurationNode config) {
    // sql -> storage
    String sqlType = config.getNode("sql", "type").getString("sqlite");
    int sqlThreads = config.getNode("sql", "threads").getInt(2);
    String sqlDatabase;
    if (sqlType.equalsIgnoreCase("sqlite")) {
        sqlDatabase = config.getNode("sql", "sqlite", "file").getString("avpn");
        int dotIndex = sqlDatabase.indexOf('.');
        if (dotIndex > 0) {
            sqlDatabase = sqlDatabase.substring(0, dotIndex);
        }
    } else {
        sqlDatabase = config.getNode("sql", "mysql", "database").getString("avpn");
    }
    String mysqlAddress = config.getNode("sql", "mysql", "address").getString("127.0.0.1");
    int mysqlPort = config.getNode("sql", "mysql", "port").getInt(3306);
    String mysqlUser = config.getNode("sql", "mysql", "user").getString("");
    String mysqlPass = config.getNode("sql", "mysql", "pass").getString("");
    config.removeChild("sql");
    config.getNode("storage", "method").setValue(sqlType);
    config.getNode("storage", "data", "address").setValue(mysqlAddress + ":" + mysqlPort);
    config.getNode("storage", "data", "database").setValue(sqlDatabase);
    config.getNode("storage", "data", "prefix").setValue("antivpn_");
    config.getNode("storage", "data", "username").setValue(mysqlUser);
    config.getNode("storage", "data", "password").setValue(mysqlPass);
    config.getNode("storage", "data", "mongodb", "collection-prefix").setValue("");
    config.getNode("storage", "data", "mongodb", "connection-uri").setValue("");
    config.getNode("storage", "settings", "max-pool-size").setValue(sqlThreads);
    config.getNode("storage", "settings", "min-idle").setValue(sqlThreads);
    config.getNode("storage", "settings", "max-lifetime").setValue(1800000L);
    config.getNode("storage", "settings", "timeout").setValue(5000L);
    config.getNode("storage", "settings", "properties", "unicode").setValue(Boolean.TRUE);
    config.getNode("storage", "settings", "properties", "encoding").setValue("utf8");

    // redis
    String redisAddress = config.getNode("redis", "address").getString("");
    if (redisAddress.isEmpty()) {
        redisAddress = "127.0.0.1";
    }
    int redisPort = config.getNode("redis", "port").getInt(6379);
    String redisPass = config.getNode("redis", "pass").getString("");
    config.getNode("redis").removeChild("port");
    config.getNode("redis").removeChild("pass");
    config.getNode("redis", "address").setValue(redisAddress + ":" + redisPort);
    config.getNode("redis", "password").setValue(redisPass);

    // messaging -> rabbitmq
    String messagingType = config.getNode("messaging", "type").getString("");
    String rabbitAddress = config.getNode("messaging", "rabbit", "address").getString("");
    if (rabbitAddress.isEmpty()) {
        rabbitAddress = "127.0.0.1";
    }
    int rabbitPort = config.getNode("messaging", "rabbit", "port").getInt(5672);
    String rabbitUser = config.getNode("messaging", "rabbit", "user").getString("guest");
    String rabbitPass = config.getNode("messaging", "rabbit", "pass").getString("guest");
    config.removeChild("messaging");
    config.getNode("rabbitmq", "enabled").setValue(messagingType.equalsIgnoreCase("rabbit") || messagingType.equalsIgnoreCase("rabbitmq") ? Boolean.TRUE : Boolean.FALSE);
    config.getNode("rabbitmq", "address").setValue(rabbitAddress + ":" + rabbitPort);
    config.getNode("rabbitmq", "username").setValue(rabbitUser);
    config.getNode("rabbitmq", "password").setValue(rabbitPass);

    // kick -> kick.enabled
    boolean kick = config.getNode("kick").getBoolean(true);
    config.removeChild("kick");
    config.getNode("kick", "enabled").setValue(kick);

    // ignore -> kick.ignore
    List<String> ignore;
    try {
        ignore = config.getNode("ignore").getList(TypeToken.of(String.class));
    } catch (Exception ex) {
        ignore = new ArrayList<>();
    }
    config.removeChild("ignore");
    config.getNode("kick", "ignore").setValue(ignore);

    // kickMessage -> kick.message
    String kickMessage = config.getNode("kickMessage").getString("");
    config.removeChild("kickMessage");
    config.getNode("kick", "message").setValue(kickMessage);

    // consensus -> kick.algorithm
    double consensus = config.getNode("consensus").getDouble();
    config.getNode("kick", "algorithm", "method").setValue(consensus >= 0.0d ? "consensus" : "cascade");
    config.getNode("kick", "algorithm", "min-consensus").setValue(consensus >= 0.0d ? consensus : 0.6d);
    config.removeChild("consensus");

    // Add threads
    config.getNode("threads").setValue(4);

    // Version
    config.getNode("version").setValue(3.3d);
}