Search in sources :

Example 1 with EntityDismountEvent

use of org.spigotmc.event.entity.EntityDismountEvent in project Glowstone by GlowstoneMC.

the class GlowEntity method removePassenger.

@Override
public boolean removePassenger(Entity passenger) {
    Preconditions.checkArgument(!this.equals(passenger), "Entity cannot ride itself.");
    if (passenger == null || !passengers.contains(passenger)) {
        // nothing changed
        return false;
    }
    if (EventFactory.getInstance().callEvent(new EntityDismountEvent(passenger, this)).isCancelled()) {
        return false;
    }
    if (!(passenger instanceof GlowEntity)) {
        return false;
    }
    GlowEntity glowPassenger = (GlowEntity) passenger;
    if (this instanceof Vehicle && glowPassenger instanceof LivingEntity) {
        VehicleExitEvent event = EventFactory.getInstance().callEvent(new VehicleExitEvent((Vehicle) this, (LivingEntity) glowPassenger));
        if (event.isCancelled()) {
            return false;
        }
    }
    passengerChanged = true;
    glowPassenger.vehicle = null;
    glowPassenger.teleport(getDismountLocation());
    return passengers.remove(passenger);
}
Also used : Vehicle(org.bukkit.entity.Vehicle) LivingEntity(org.bukkit.entity.LivingEntity) EntityDismountEvent(org.spigotmc.event.entity.EntityDismountEvent) VehicleExitEvent(org.bukkit.event.vehicle.VehicleExitEvent)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)1 Vehicle (org.bukkit.entity.Vehicle)1 VehicleExitEvent (org.bukkit.event.vehicle.VehicleExitEvent)1 EntityDismountEvent (org.spigotmc.event.entity.EntityDismountEvent)1