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