use of cn.nukkit.event.entity.EntityVehicleEnterEvent 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;
}
Aggregations