Search in sources :

Example 1 with Account

use of org.spongepowered.api.service.economy.account.Account in project Almura by AlmuraDev.

the class ServerHeadUpDisplayManager method onEconomyTransaction.

@Listener(order = Order.LAST)
public void onEconomyTransaction(EconomyTransactionEvent event) {
    final TransactionResult result = event.getTransactionResult();
    final Account account = result.getAccount();
    if (account instanceof UniqueAccount) {
        Sponge.getServer().getPlayer(((UniqueAccount) account).getUniqueId()).ifPresent(player -> Task.builder().delayTicks(1).execute(() -> {
            final ClientboundPlayerCurrencyPacket packet = this.createPlayerCurrencyPacket(player);
            if (packet != null) {
                this.network.sendTo(player, packet);
            }
        }).submit(this.container));
    }
}
Also used : Account(org.spongepowered.api.service.economy.account.Account) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) TransactionResult(org.spongepowered.api.service.economy.transaction.TransactionResult) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) ClientboundPlayerCurrencyPacket(com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket) Listener(org.spongepowered.api.event.Listener)

Example 2 with Account

use of org.spongepowered.api.service.economy.account.Account in project Almura by AlmuraDev.

the class ServerHeadUpDisplayManager method createPlayerCurrencyPacket.

@Nullable
private ClientboundPlayerCurrencyPacket createPlayerCurrencyPacket(Player player) {
    final EconomyService service = Sponge.getServiceManager().provide(EconomyService.class).orElse(null);
    if (service != null) {
        final Account account = service.getOrCreateAccount(player.getUniqueId()).orElse(null);
        BigDecimal balance = BigDecimal.ZERO;
        if (account != null) {
            final Currency currency = service.getDefaultCurrency();
            balance = account.getBalance(currency);
        }
        return new ClientboundPlayerCurrencyPacket(balance);
    }
    return null;
}
Also used : Account(org.spongepowered.api.service.economy.account.Account) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) EconomyService(org.spongepowered.api.service.economy.EconomyService) Currency(org.spongepowered.api.service.economy.Currency) ClientboundPlayerCurrencyPacket(com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket) BigDecimal(java.math.BigDecimal) Nullable(javax.annotation.Nullable)

Aggregations

ClientboundPlayerCurrencyPacket (com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket)2 Account (org.spongepowered.api.service.economy.account.Account)2 UniqueAccount (org.spongepowered.api.service.economy.account.UniqueAccount)2 BigDecimal (java.math.BigDecimal)1 Nullable (javax.annotation.Nullable)1 Listener (org.spongepowered.api.event.Listener)1 Currency (org.spongepowered.api.service.economy.Currency)1 EconomyService (org.spongepowered.api.service.economy.EconomyService)1 TransactionResult (org.spongepowered.api.service.economy.transaction.TransactionResult)1