Search in sources :

Example 21 with Currency

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

Aggregations

Currency (org.spongepowered.api.service.economy.Currency)21 BigDecimal (java.math.BigDecimal)11 TEAccount (com.erigitic.config.TEAccount)6 Player (org.spongepowered.api.entity.living.player.Player)6 EconomyService (org.spongepowered.api.service.economy.EconomyService)6 Listener (org.spongepowered.api.event.Listener)5 Account (org.spongepowered.api.service.economy.account.Account)5 UUID (java.util.UUID)4 TECurrency (com.erigitic.config.TECurrency)3 Text (org.spongepowered.api.text.Text)3 LuckPerms (net.luckperms.api.LuckPerms)2 BlockState (org.spongepowered.api.block.BlockState)2 BlockTrait (org.spongepowered.api.block.trait.BlockTrait)2 CommandException (org.spongepowered.api.command.CommandException)2 UniqueAccount (org.spongepowered.api.service.economy.account.UniqueAccount)2 ClientboundClaimDataPacket (com.almuradev.almura.feature.claim.network.ClientboundClaimDataPacket)1 ClientboundPlayerDiedPacket (com.almuradev.almura.feature.death.network.ClientboundPlayerDiedPacket)1 ClientboundPlayerCurrencyPacket (com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket)1 ClientboundMembershipGuiOpenPacket (com.almuradev.almura.feature.membership.network.ClientboundMembershipGuiOpenPacket)1 ClientboundMembershipSuccessPacket (com.almuradev.almura.feature.membership.network.ClientboundMembershipSuccessPacket)1