Search in sources :

Example 1 with ConfigurationSection

use of com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection in project Parties by AlessioDP.

the class ConfigMain method loadConfiguration.

@Override
public void loadConfiguration() {
    loadConfigOptions();
    ConfigurationSection csPlaceholders = configuration.getConfigurationSection("additional.placeholders.customs");
    if (csPlaceholders != null) {
        ConfigMain.ADDITIONAL_PLACEHOLDER_CUSTOMS = new HashMap<>();
        for (String key : csPlaceholders.getKeys(false)) {
            ConfigMain.ADDITIONAL_PLACEHOLDER_CUSTOMS.put(key, csPlaceholders.getString(key, ""));
        }
    } else {
        // Give error: no ranks node found
        plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_PLACEHOLDERS_NOTFOUND);
    }
}
Also used : ConfigurationSection(com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection)

Example 2 with ConfigurationSection

use of com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection in project Parties by AlessioDP.

the class ConfigParties method handleRanks.

private void handleRanks() {
    Set<PartyRankImpl> ranks = new HashSet<>();
    PartyRankImpl rank;
    ConfigurationSection csBlocks = configuration.getConfigurationSection("ranks");
    if (csBlocks != null) {
        PartyRankImpl def = null;
        PartyRankImpl lower = null;
        PartyRankImpl higher = null;
        for (String key : csBlocks.getKeys(false)) {
            rank = new PartyRankImpl(key);
            rank.setName(csBlocks.getString(key + ".name", key));
            rank.setChat(csBlocks.getString(key + ".chat", rank.getName()));
            rank.setLevel(csBlocks.getInt(key + ".level", 1));
            if (csBlocks.get(key + ".inheritence") != null) {
                Optional<PartyRankImpl> opt = ranks.stream().filter(r -> r.getConfigName().equals(csBlocks.getString(key + ".inheritence"))).findAny();
                if (opt.isPresent())
                    rank.setInheritence(opt.get());
            }
            rank.getPermissions().addAll(csBlocks.getStringList(key + ".permissions"));
            rank.setDefault(csBlocks.getBoolean(key + ".default", false));
            if (!rank.isDefault())
                rank.setSlot(csBlocks.getInt(key + ".slot", 0));
            ranks.add(rank);
            if (rank.isDefault())
                def = rank;
            if (lower == null || rank.getLevel() < lower.getLevel())
                lower = rank;
            if (higher == null || rank.getLevel() > higher.getLevel())
                higher = rank;
        }
        if (ranks.size() > 1) {
            if (def == null) {
                // Give error: default rank not found
                def = lower;
                plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_RANK_NODEFAULT);
            }
            // Save rank list
            ConfigParties.RANK_LIST = ranks;
            ConfigParties.RANK_SET_DEFAULT = def.getLevel();
            ConfigParties.RANK_SET_HIGHER = higher.getLevel();
        } else if (ranks.size() == 1) {
            // At least 2 ranks needed
            plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_RANK_ONLYONE);
        } else {
            // Give error: no ranks found
            plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_RANK_EMPTY);
        }
    } else {
        // Give error: no ranks node found
        plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_RANK_NOTFOUND);
    }
}
Also used : MemorySection(com.alessiodp.core.common.addons.external.simpleyaml.configuration.MemorySection) ConfigOption(com.alessiodp.core.common.configuration.ConfigOption) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) PartyRankImpl(com.alessiodp.parties.common.players.objects.PartyRankImpl) Arrays(java.util.Arrays) Set(java.util.Set) HashSet(java.util.HashSet) List(java.util.List) PartyColorImpl(com.alessiodp.parties.common.parties.objects.PartyColorImpl) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) Optional(java.util.Optional) ConfigurationFile(com.alessiodp.core.common.configuration.ConfigurationFile) Collections(java.util.Collections) ConfigurationSection(com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection) PartyRankImpl(com.alessiodp.parties.common.players.objects.PartyRankImpl) HashSet(java.util.HashSet) ConfigurationSection(com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection)

Example 3 with ConfigurationSection

use of com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection in project Parties by AlessioDP.

the class PartiesYAMLDispatcher method updatePlayer.

@Override
public void updatePlayer(PartyPlayerImpl player) {
    if (player.isPersistent()) {
        ConfigurationSection node = database.getYaml().getConfigurationSection("players." + player.getPlayerUUID());
        if (node == null)
            node = database.getYaml().createSection("players." + player.getPlayerUUID());
        if (player.getPartyId() != null) {
            node.set("party", player.getPartyId().toString());
            node.set("rank", player.getRank());
            node.set("nickname", player.getNickname());
        } else {
            node.set("party", null);
            node.set("rank", null);
            node.set("nickname", null);
        }
        if (player.isChatParty() || player.isSpy() || player.isMuted()) {
            node.set("options.chat", player.isChatParty() ? true : null);
            node.set("options.spy", player.isSpy() ? true : null);
            node.set("options.mute", player.isMuted() ? true : null);
        } else {
            node.set("options", null);
        }
    } else {
        database.getYaml().set("players." + player.getPlayerUUID(), null);
    }
    save();
}
Also used : ConfigurationSection(com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection)

Example 4 with ConfigurationSection

use of com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection in project Parties by AlessioDP.

the class PartiesYAMLDispatcher method getListPartiesNumber.

@Override
public int getListPartiesNumber() {
    int ret = 0;
    ConfigurationSection node = database.getYaml().getConfigurationSection("parties");
    if (node != null) {
        List<String> lowerCaseBlacklist = new ArrayList<>();
        for (String b : ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES) lowerCaseBlacklist.add(CommonUtils.toLowerCase(b));
        for (String key : node.getKeys(false)) {
            if (!lowerCaseBlacklist.contains(CommonUtils.toLowerCase(node.getString(key + ".name"))))
                ret++;
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) ConfigurationSection(com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection)

Example 5 with ConfigurationSection

use of com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection in project Parties by AlessioDP.

the class PartiesYAMLDispatcher method getListPlayersInPartyNumber.

public int getListPlayersInPartyNumber() {
    int ret = 0;
    ConfigurationSection players = database.getYaml().getConfigurationSection("players");
    if (players != null) {
        Set<String> keys = players.getKeys(false);
        for (String key : keys) {
            if (players.get(key + ".party") != null)
                ret++;
        }
    }
    return ret;
// return (int) database.getRootNode().node("players").childrenList().stream().filter(p -> !p.node("party").empty()).count();
}
Also used : ConfigurationSection(com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection)

Aggregations

ConfigurationSection (com.alessiodp.core.common.addons.external.simpleyaml.configuration.ConfigurationSection)9 ArrayList (java.util.ArrayList)3 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 MemorySection (com.alessiodp.core.common.addons.external.simpleyaml.configuration.MemorySection)1 ConfigOption (com.alessiodp.core.common.configuration.ConfigOption)1 ConfigurationFile (com.alessiodp.core.common.configuration.ConfigurationFile)1 PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)1 PartiesConstants (com.alessiodp.parties.common.configuration.PartiesConstants)1 PartyColorImpl (com.alessiodp.parties.common.parties.objects.PartyColorImpl)1 PartyRankImpl (com.alessiodp.parties.common.players.objects.PartyRankImpl)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1