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);
}
}
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);
}
}
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();
}
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;
}
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();
}
Aggregations