Search in sources :

Example 1 with SPacketPlayerListItem

use of net.minecraft.network.play.server.SPacketPlayerListItem in project SpongeCommon by SpongePowered.

the class MixinPlayerList method playerLoggedIn2.

@Inject(method = "playerLoggedIn", at = @At(value = "INVOKE", target = SERVER_SEND_PACKET_TO_ALL_PLAYERS, shift = At.Shift.BEFORE), cancellable = true)
public void playerLoggedIn2(EntityPlayerMP player, CallbackInfo ci) {
    // Create a packet to be used for players without context data
    SPacketPlayerListItem noSpecificViewerPacket = new SPacketPlayerListItem(SPacketPlayerListItem.Action.ADD_PLAYER, player);
    for (EntityPlayerMP viewer : this.playerEntityList) {
        if (((Player) viewer).canSee((Player) player)) {
            viewer.connection.sendPacket(noSpecificViewerPacket);
        }
        if (((Player) player).canSee((Player) viewer)) {
            player.connection.sendPacket(new SPacketPlayerListItem(SPacketPlayerListItem.Action.ADD_PLAYER, viewer));
        }
    }
    // Spawn player into level
    WorldServer level = this.mcServer.getWorld(player.dimension);
    // TODO direct this appropriately
    level.spawnEntity(player);
    this.preparePlayer(player, null);
    // We always want to cancel.
    ci.cancel();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) SPacketPlayerListItem(net.minecraft.network.play.server.SPacketPlayerListItem) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with SPacketPlayerListItem

use of net.minecraft.network.play.server.SPacketPlayerListItem in project SpongeCommon by SpongePowered.

the class EntityHuman method createPlayerListPacket.

/**
 * Creates a {@link SPacketPlayerListItem} packet with the given action.
 *
 * @param action The action to apply on the tab list
 * @return A new tab list packet
 */
public SPacketPlayerListItem createPlayerListPacket(SPacketPlayerListItem.Action action) {
    SPacketPlayerListItem packet = new SPacketPlayerListItem(action);
    packet.players.add(packet.new AddPlayerData(this.fakeProfile, 0, GameType.NOT_SET, this.getDisplayName()));
    return packet;
}
Also used : SPacketPlayerListItem(net.minecraft.network.play.server.SPacketPlayerListItem)

Example 3 with SPacketPlayerListItem

use of net.minecraft.network.play.server.SPacketPlayerListItem 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
 */
protected void sendUpdate(TabListEntry entry, SPacketPlayerListItem.Action action) {
    SPacketPlayerListItem packet = new SPacketPlayerListItem();
    packet.action = action;
    ((IMixinSPacketPlayerListItem) packet).addEntry(entry);
    this.player.connection.sendPacket(packet);
}
Also used : SPacketPlayerListItem(net.minecraft.network.play.server.SPacketPlayerListItem) IMixinSPacketPlayerListItem(org.spongepowered.common.interfaces.network.play.server.IMixinSPacketPlayerListItem) IMixinSPacketPlayerListItem(org.spongepowered.common.interfaces.network.play.server.IMixinSPacketPlayerListItem)

Example 4 with SPacketPlayerListItem

use of net.minecraft.network.play.server.SPacketPlayerListItem in project SpongeCommon by SpongePowered.

the class MixinEntity method spongeOnUpdate.

@Inject(method = "onUpdate", at = @At("RETURN"))
private void spongeOnUpdate(CallbackInfo callbackInfo) {
    if (this.pendingVisibilityUpdate && !this.world.isRemote) {
        final EntityTracker entityTracker = ((WorldServer) this.world).getEntityTracker();
        final EntityTrackerEntry lookup = entityTracker.trackedEntityHashTable.lookup(this.getEntityId());
        if (this.visibilityTicks % 4 == 0) {
            if (this.isVanished) {
                for (EntityPlayerMP entityPlayerMP : lookup.trackingPlayers) {
                    entityPlayerMP.connection.sendPacket(new SPacketDestroyEntities(this.getEntityId()));
                    if (((Object) this) instanceof EntityPlayerMP) {
                        entityPlayerMP.connection.sendPacket(new SPacketPlayerListItem(SPacketPlayerListItem.Action.REMOVE_PLAYER, (EntityPlayerMP) (Object) this));
                    }
                }
            } else {
                this.visibilityTicks = 1;
                this.pendingVisibilityUpdate = false;
                for (EntityPlayerMP entityPlayerMP : SpongeImpl.getServer().getPlayerList().getPlayers()) {
                    if (((Object) this) == entityPlayerMP) {
                        continue;
                    }
                    if (((Object) this) instanceof EntityPlayerMP) {
                        Packet<?> packet = new SPacketPlayerListItem(SPacketPlayerListItem.Action.ADD_PLAYER, (EntityPlayerMP) (Object) this);
                        entityPlayerMP.connection.sendPacket(packet);
                    }
                    // creates the spawn packet for us
                    Packet<?> newPacket = lookup.createSpawnPacket();
                    entityPlayerMP.connection.sendPacket(newPacket);
                }
            }
        }
        if (this.visibilityTicks > 0) {
            this.visibilityTicks--;
        } else {
            this.pendingVisibilityUpdate = false;
        }
    }
}
Also used : EntityTrackerEntry(net.minecraft.entity.EntityTrackerEntry) EntityTracker(net.minecraft.entity.EntityTracker) SPacketPlayerListItem(net.minecraft.network.play.server.SPacketPlayerListItem) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketDestroyEntities(net.minecraft.network.play.server.SPacketDestroyEntities) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with SPacketPlayerListItem

use of net.minecraft.network.play.server.SPacketPlayerListItem in project SpongeCommon by SpongePowered.

the class MixinEntityTrackerEntry method onSendSpawnPacket.

@Redirect(method = "updatePlayerEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetHandlerPlayServer;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 0))
public void onSendSpawnPacket(final NetHandlerPlayServer thisCtx, final Packet<?> spawnPacket, final EntityPlayerMP playerIn) {
    if (!(this.trackedEntity instanceof EntityHuman)) {
        // This is the method call that was @Redirected
        thisCtx.sendPacket(spawnPacket);
        return;
    }
    final EntityHuman human = (EntityHuman) this.trackedEntity;
    // Adds the GameProfile to the client
    thisCtx.sendPacket(human.createPlayerListPacket(SPacketPlayerListItem.Action.ADD_PLAYER));
    // Actually spawn the human (a player)
    thisCtx.sendPacket(spawnPacket);
    // Remove from tab list
    final SPacketPlayerListItem removePacket = human.createPlayerListPacket(SPacketPlayerListItem.Action.REMOVE_PLAYER);
    if (human.canRemoveFromListImmediately()) {
        thisCtx.sendPacket(removePacket);
    } else {
        human.removeFromTabListDelayed(playerIn, removePacket);
    }
}
Also used : EntityHuman(org.spongepowered.common.entity.living.human.EntityHuman) SPacketPlayerListItem(net.minecraft.network.play.server.SPacketPlayerListItem) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

SPacketPlayerListItem (net.minecraft.network.play.server.SPacketPlayerListItem)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 WorldServer (net.minecraft.world.WorldServer)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 EntityTracker (net.minecraft.entity.EntityTracker)1 EntityTrackerEntry (net.minecraft.entity.EntityTrackerEntry)1 SPacketDestroyEntities (net.minecraft.network.play.server.SPacketDestroyEntities)1 Player (org.spongepowered.api.entity.living.player.Player)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 EntityHuman (org.spongepowered.common.entity.living.human.EntityHuman)1 IMixinEntityPlayerMP (org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP)1 IMixinSPacketPlayerListItem (org.spongepowered.common.interfaces.network.play.server.IMixinSPacketPlayerListItem)1