use of org.spongepowered.api.service.economy.Currency 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;
// Check if the account is virtual or not. If virtual, skip the rest of the execution and move on to next account.
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();
}
Aggregations