use of org.bukkit.event.vehicle.VehicleEnterEvent 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);
}
Aggregations