Search in sources :

Example 6 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project TotalEconomy by Erigitic.

the class BalanceTopCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    ConfigurationNode accountNode = accountManager.getAccountConfig();
    List<Text> accountBalances = new ArrayList<>();
    Map<String, BigDecimal> accountBalancesMap = new HashMap<>();
    Currency defaultCurrency = totalEconomy.getDefaultCurrency();
    accountNode.getChildrenMap().keySet().forEach(accountUUID -> {
        UUID uuid;
        try {
            uuid = UUID.fromString(accountUUID.toString());
        } catch (IllegalArgumentException e) {
            return;
        }
        TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(uuid).get();
        Text playerName = playerAccount.getDisplayName();
        accountBalancesMap.put(playerName.toPlain(), playerAccount.getBalance(defaultCurrency));
    });
    accountBalancesMap.entrySet().stream().sorted(Map.Entry.<String, BigDecimal>comparingByValue().reversed()).limit(10).forEach(entry -> accountBalances.add(Text.of(TextColors.GRAY, entry.getKey(), ": ", TextColors.GOLD, defaultCurrency.format(entry.getValue()).toPlain())));
    builder.title(Text.of(TextColors.GOLD, "Top 10 Balances")).contents(accountBalances).sendTo(src);
    return CommandResult.success();
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Currency(org.spongepowered.api.service.economy.Currency) TECurrency(com.erigitic.config.TECurrency) Text(org.spongepowered.api.text.Text) TEAccount(com.erigitic.config.TEAccount) BigDecimal(java.math.BigDecimal)

Example 7 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project TotalEconomy by Erigitic.

the class MinerJobSet method populateNode.

@Override
public void populateNode(ConfigurationNode node) {
    ConfigurationNode myNode = node.getNode(SETNAME);
    for (String[] a : REWARDS) {
        ConfigurationNode n = myNode.getNode(a[0], a[1]);
        n.getNode("exp").setValue(a[2]);
        n.getNode("money").setValue(a[3]);
    }
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode)

Example 8 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project TotalEconomy by Erigitic.

the class TEJobManager method reloadJobSetConfig.

/**
     * Reload the jobSet config
     */
public boolean reloadJobSetConfig() {
    try {
        jobSetsConfig = jobSetsLoader.load();
        ConfigurationNode sets = jobSetsConfig.getNode("sets");
        if (!jobSetsFile.exists()) {
            for (JobSet s : defaultJobSets) {
                s.populateNode(sets);
            }
            jobSetsLoader.save(jobSetsConfig);
        }
        sets.getChildrenMap().forEach((setName, setNode) -> {
            if (setNode != null) {
                TEJobSet jobSet = new TEJobSet(setNode);
                jobSets.put((String) setName, jobSet);
            }
        });
        return true;
    } catch (IOException e) {
        logger.warn("[TE] An error occurred while creating/loading the jobSets configuration file!");
        return false;
    }
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) IOException(java.io.IOException)

Example 9 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project TotalEconomy by Erigitic.

the class FishermanJobSet method populateNode.

@Override
public void populateNode(ConfigurationNode node) {
    ConfigurationNode myNode = node.getNode(SETNAME);
    for (String[] a : REWARDS) {
        ConfigurationNode n = myNode.getNode(a[0], a[1]);
        n.getNode("exp").setValue(a[2]);
        n.getNode("money").setValue(a[3]);
    }
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode)

Example 10 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project TotalEconomy by Erigitic.

the class LumberjackJobSet method populateNode.

@Override
public void populateNode(ConfigurationNode node) {
    ConfigurationNode myNode = node.getNode(SETNAME);
    for (String[] a : REWARDS) {
        ConfigurationNode n = myNode.getNode(a[0], a[1]);
        n.getNode("exp").setValue(a[2]);
        n.getNode("money").setValue(a[3]);
    }
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode)

Aggregations

ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)11 IOException (java.io.IOException)2 CommentedConfigurationNode (ninja.leaping.configurate.commented.CommentedConfigurationNode)2 GsonConfigurationLoader (ninja.leaping.configurate.gson.GsonConfigurationLoader)2 Text (org.spongepowered.api.text.Text)2 TEAccount (com.erigitic.config.TEAccount)1 TECurrency (com.erigitic.config.TECurrency)1 JsonParser (com.google.gson.JsonParser)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 ItemEnchantment (org.spongepowered.api.data.meta.ItemEnchantment)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Currency (org.spongepowered.api.service.economy.Currency)1