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