Search in sources :

Example 1 with ClientboundPlayerCurrencyPacket

use of com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket 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 ClientboundPlayerCurrencyPacket

use of com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket 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)

Example 3 with ClientboundPlayerCurrencyPacket

use of com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket in project Almura by AlmuraDev.

the class ServerHeadUpDisplayManager method clientJoin.

@Listener(order = Order.LAST)
public void clientJoin(final ClientConnectionEvent.Join event) {
    final Player player = event.getTargetEntity();
    this.network.sendTo(player, this.createWorldNamePacket(player.getTransform()));
    final ClientboundPlayerCountPacket packet = this.createPlayerCountPacket(false);
    for (final Player viewer : this.game.getServer().getOnlinePlayers()) {
        this.network.sendTo(viewer, packet);
    }
    this.network.sendTo(player, packet);
    final ClientboundPlayerCurrencyPacket currPacket = this.createPlayerCurrencyPacket(player);
    if (currPacket != null) {
        this.network.sendTo(player, currPacket);
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ClientboundPlayerCountPacket(com.almuradev.almura.feature.hud.network.ClientboundPlayerCountPacket) ClientboundPlayerCurrencyPacket(com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket) Listener(org.spongepowered.api.event.Listener)

Aggregations

ClientboundPlayerCurrencyPacket (com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket)3 Listener (org.spongepowered.api.event.Listener)2 Account (org.spongepowered.api.service.economy.account.Account)2 UniqueAccount (org.spongepowered.api.service.economy.account.UniqueAccount)2 ClientboundPlayerCountPacket (com.almuradev.almura.feature.hud.network.ClientboundPlayerCountPacket)1 BigDecimal (java.math.BigDecimal)1 Nullable (javax.annotation.Nullable)1 Player (org.spongepowered.api.entity.living.player.Player)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