Search in sources :

Example 1 with ClientboundPlayerInfoPacketAccessor

use of org.spongepowered.common.accessor.network.protocol.game.ClientboundPlayerInfoPacketAccessor in project SpongeCommon by SpongePowered.

the class SpongeTabList method sendUpdate.

/**
 * Send an entry update.
 *
 * @param entry The entry to update
 * @param action The update action to perform
 */
@SuppressWarnings("ConstantConditions")
void sendUpdate(final TabListEntry entry, final ClientboundPlayerInfoPacket.Action action) {
    final ClientboundPlayerInfoPacket packet = new ClientboundPlayerInfoPacket();
    ((ClientboundPlayerInfoPacketAccessor) packet).accessor$action(action);
    final ClientboundPlayerInfoPacket.PlayerUpdate data = packet.new PlayerUpdate(SpongeGameProfile.toMcProfile(entry.profile()), entry.latency(), (GameType) (Object) entry.gameMode(), entry.displayName().isPresent() ? SpongeAdventure.asVanilla(entry.displayName().get()) : null);
    ((ClientboundPlayerInfoPacketAccessor) packet).accessor$entries().add(data);
    this.player.connection.send(packet);
}
Also used : ClientboundPlayerInfoPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ClientboundPlayerInfoPacketAccessor) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 2 with ClientboundPlayerInfoPacketAccessor

use of org.spongepowered.common.accessor.network.protocol.game.ClientboundPlayerInfoPacketAccessor in project SpongeCommon by SpongePowered.

the class PlayerListMixin method impl$onlySendAddPlayerForUnvanishedPlayers.

@Redirect(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;send(Lnet/minecraft/network/protocol/Packet;)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Ljava/util/List;size()I", remap = false), to = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addNewPlayer(Lnet/minecraft/server/level/ServerPlayer;)V")))
private void impl$onlySendAddPlayerForUnvanishedPlayers(ServerGamePacketListenerImpl connection, Packet<?> packet) {
    ClientboundPlayerInfoPacketAccessor playerInfoPacketAccessor = (ClientboundPlayerInfoPacketAccessor) packet;
    // size is always 1
    VanishableBridge p = (VanishableBridge) this.playersByUUID.get(playerInfoPacketAccessor.accessor$entries().get(0).getProfile().getId());
    // Effectively, don't notify new players of vanished players
    if (p.bridge$vanishState().invisible()) {
        return;
    }
    connection.send(packet);
}
Also used : ClientboundPlayerInfoPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ClientboundPlayerInfoPacketAccessor) VanishableBridge(org.spongepowered.common.bridge.data.VanishableBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

ClientboundPlayerInfoPacketAccessor (org.spongepowered.common.accessor.network.protocol.game.ClientboundPlayerInfoPacketAccessor)2 ClientboundPlayerInfoPacket (net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 VanishableBridge (org.spongepowered.common.bridge.data.VanishableBridge)1