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