Search in sources :

Example 1 with ClientboundPlayerCountPacket

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

the class ServerHeadUpDisplayManager method clientDisconnect.

@Listener(order = Order.LAST)
public void clientDisconnect(final ClientConnectionEvent.Disconnect event) {
    final Player player = event.getTargetEntity();
    final ClientboundPlayerCountPacket packet = this.createPlayerCountPacket(true);
    for (final Player viewer : this.game.getServer().getOnlinePlayers()) {
        if (viewer.getUniqueId().equals(player.getUniqueId())) {
            continue;
        }
        this.network.sendTo(viewer, packet);
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ClientboundPlayerCountPacket(com.almuradev.almura.feature.hud.network.ClientboundPlayerCountPacket) Listener(org.spongepowered.api.event.Listener)

Example 2 with ClientboundPlayerCountPacket

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

the class ServerHeadUpDisplayManager method createPlayerCountPacket.

private ClientboundPlayerCountPacket createPlayerCountPacket(final boolean disconnect) {
    final Server server = this.game.getServer();
    // Subtract one from the online player count when a player is disconnecting
    // due to the player not being removed from the online players list until
    // after the disconnect event has been posted.
    final int online = server.getOnlinePlayers().size() - (disconnect ? 1 : 0);
    return new ClientboundPlayerCountPacket(online, server.getMaxPlayers());
}
Also used : Server(org.spongepowered.api.Server) ClientboundPlayerCountPacket(com.almuradev.almura.feature.hud.network.ClientboundPlayerCountPacket)

Example 3 with ClientboundPlayerCountPacket

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

ClientboundPlayerCountPacket (com.almuradev.almura.feature.hud.network.ClientboundPlayerCountPacket)3 Player (org.spongepowered.api.entity.living.player.Player)2 Listener (org.spongepowered.api.event.Listener)2 ClientboundPlayerCurrencyPacket (com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket)1 Server (org.spongepowered.api.Server)1