Search in sources :

Example 1 with EntityMountEvent

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

the class GlowEntity method addPassenger.

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

Aggregations

Vehicle (org.bukkit.entity.Vehicle)1 VehicleEnterEvent (org.bukkit.event.vehicle.VehicleEnterEvent)1 EntityMountEvent (org.spigotmc.event.entity.EntityMountEvent)1