Search in sources :

Example 1 with AddPlayerPacket

use of cn.nukkit.network.protocol.AddPlayerPacket in project Nukkit by Nukkit.

the class EntityHuman method spawnTo.

@Override
public void spawnTo(Player player) {
    if (this != player && !this.hasSpawned.containsKey(player.getLoaderId())) {
        this.hasSpawned.put(player.getLoaderId(), player);
        if (this.skin.getData().length < 64 * 32 * 4) {
            throw new IllegalStateException(this.getClass().getSimpleName() + " must have a valid skin set");
        }
        if (this instanceof Player)
            this.server.updatePlayerListData(this.getUniqueId(), this.getId(), this.getName(), this.skin, ((Player) this).getLoginChainData().getXUID(), new Player[] { player });
        else
            this.server.updatePlayerListData(this.getUniqueId(), this.getId(), this.getName(), this.skin, new Player[] { player });
        AddPlayerPacket pk = new AddPlayerPacket();
        pk.uuid = this.getUniqueId();
        pk.username = this.getName();
        pk.entityUniqueId = this.getId();
        pk.entityRuntimeId = this.getId();
        pk.x = (float) this.x;
        pk.y = (float) this.y;
        pk.z = (float) this.z;
        pk.speedX = (float) this.motionX;
        pk.speedY = (float) this.motionY;
        pk.speedZ = (float) this.motionZ;
        pk.yaw = (float) this.yaw;
        pk.pitch = (float) this.pitch;
        pk.item = this.getInventory().getItemInHand();
        pk.metadata = this.dataProperties;
        player.dataPacket(pk);
        this.inventory.sendArmorContents(player);
        if (this.riding != null) {
            SetEntityLinkPacket pkk = new SetEntityLinkPacket();
            pkk.rider = this.riding.getId();
            pkk.riding = this.getId();
            pkk.type = 1;
            pkk.unknownByte = 1;
            player.dataPacket(pkk);
        }
        if (!(this instanceof Player)) {
            this.server.removePlayerListData(this.getUniqueId(), new Player[] { player });
        }
    }
}
Also used : Player(cn.nukkit.Player) SetEntityLinkPacket(cn.nukkit.network.protocol.SetEntityLinkPacket) AddPlayerPacket(cn.nukkit.network.protocol.AddPlayerPacket)

Example 2 with AddPlayerPacket

use of cn.nukkit.network.protocol.AddPlayerPacket in project Nukkit by Nukkit.

the class FloatingTextParticle method encode.

@Override
public DataPacket[] encode() {
    ArrayList<DataPacket> packets = new ArrayList<>();
    if (this.entityId == -1) {
        this.entityId = 1095216660480L + ThreadLocalRandom.current().nextLong(0, 0x7fffffffL);
    } else {
        RemoveEntityPacket pk = new RemoveEntityPacket();
        pk.eid = this.entityId;
        packets.add(pk);
    }
    if (!this.invisible) {
        AddPlayerPacket pk = new AddPlayerPacket();
        pk.uuid = UUID.randomUUID();
        pk.username = "";
        pk.entityUniqueId = this.entityId;
        pk.entityRuntimeId = this.entityId;
        pk.x = (float) this.x;
        pk.y = (float) (this.y - 0.75);
        pk.z = (float) this.z;
        pk.speedX = 0;
        pk.speedY = 0;
        pk.speedZ = 0;
        pk.yaw = 0;
        pk.pitch = 0;
        long flags = ((1L << Entity.DATA_FLAG_CAN_SHOW_NAMETAG) | (1L << Entity.DATA_FLAG_ALWAYS_SHOW_NAMETAG) | (1L << Entity.DATA_FLAG_IMMOBILE));
        pk.metadata = new EntityMetadata().putLong(Entity.DATA_FLAGS, flags).putString(Entity.DATA_NAMETAG, this.title + (!this.text.isEmpty() ? "\n" + this.text : "")).putLong(Entity.DATA_LEAD_HOLDER_EID, -1).putFloat(Entity.DATA_SCALE, // zero causes problems on debug builds?
        0.01f);
        pk.item = Item.get(Item.AIR);
        packets.add(pk);
    }
    return packets.stream().toArray(DataPacket[]::new);
}
Also used : RemoveEntityPacket(cn.nukkit.network.protocol.RemoveEntityPacket) AddPlayerPacket(cn.nukkit.network.protocol.AddPlayerPacket) EntityMetadata(cn.nukkit.entity.data.EntityMetadata) ArrayList(java.util.ArrayList) DataPacket(cn.nukkit.network.protocol.DataPacket)

Aggregations

AddPlayerPacket (cn.nukkit.network.protocol.AddPlayerPacket)2 Player (cn.nukkit.Player)1 EntityMetadata (cn.nukkit.entity.data.EntityMetadata)1 DataPacket (cn.nukkit.network.protocol.DataPacket)1 RemoveEntityPacket (cn.nukkit.network.protocol.RemoveEntityPacket)1 SetEntityLinkPacket (cn.nukkit.network.protocol.SetEntityLinkPacket)1 ArrayList (java.util.ArrayList)1