Search in sources :

Example 1 with SetEntityLinkPacket

use of cn.nukkit.network.protocol.SetEntityLinkPacket 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 SetEntityLinkPacket

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

the class EntityVehicle method mountEntity.

/**
 * Mount or Dismounts an Entity from a vehicle
 *
 * @param entity The target Entity
 * @return {@code true} if the mounting successful
 */
@Override
public boolean mountEntity(Entity entity) {
    Objects.requireNonNull(entity, "The target of the mounting entity can't be null");
    this.PitchDelta = 0.0D;
    this.YawDelta = 0.0D;
    if (entity.riding != null) {
        EntityVehicleExitEvent ev = new EntityVehicleExitEvent(entity, this);
        server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return false;
        }
        SetEntityLinkPacket pk;
        pk = new SetEntityLinkPacket();
        // Weird Weird Weird
        pk.rider = getId();
        pk.riding = entity.getId();
        pk.type = 3;
        Server.broadcastPacket(this.hasSpawned.values(), pk);
        if (entity instanceof Player) {
            pk = new SetEntityLinkPacket();
            pk.rider = getId();
            pk.riding = entity.getId();
            pk.type = 3;
            ((Player) entity).dataPacket(pk);
        }
        entity.riding = null;
        linkedEntity = null;
        entity.setDataFlag(DATA_FLAGS, DATA_FLAG_RIDING, false);
        return true;
    }
    EntityVehicleEnterEvent ev = new EntityVehicleEnterEvent(entity, this);
    server.getPluginManager().callEvent(ev);
    if (ev.isCancelled()) {
        return false;
    }
    SetEntityLinkPacket pk;
    pk = new SetEntityLinkPacket();
    pk.rider = this.getId();
    pk.riding = entity.getId();
    pk.type = 2;
    Server.broadcastPacket(this.hasSpawned.values(), pk);
    if (entity instanceof Player) {
        pk = new SetEntityLinkPacket();
        pk.rider = this.getId();
        pk.riding = 0;
        pk.type = 2;
        ((Player) entity).dataPacket(pk);
    }
    entity.riding = this;
    linkedEntity = entity;
    entity.setDataFlag(DATA_FLAGS, DATA_FLAG_RIDING, true);
    updateRiderPosition(getMountedYOffset());
    return true;
}
Also used : SetEntityLinkPacket(cn.nukkit.network.protocol.SetEntityLinkPacket) Player(cn.nukkit.Player) EntityVehicleEnterEvent(cn.nukkit.event.entity.EntityVehicleEnterEvent) EntityVehicleExitEvent(cn.nukkit.event.entity.EntityVehicleExitEvent)

Aggregations

Player (cn.nukkit.Player)2 SetEntityLinkPacket (cn.nukkit.network.protocol.SetEntityLinkPacket)2 EntityVehicleEnterEvent (cn.nukkit.event.entity.EntityVehicleEnterEvent)1 EntityVehicleExitEvent (cn.nukkit.event.entity.EntityVehicleExitEvent)1 AddPlayerPacket (cn.nukkit.network.protocol.AddPlayerPacket)1