Search in sources :

Example 1 with VehicleDestroyEvent

use of cn.nukkit.event.vehicle.VehicleDestroyEvent in project Nukkit by Nukkit.

the class EntityBoat method attack.

@Override
public boolean attack(EntityDamageEvent source) {
    if (invulnerable) {
        return false;
    } else {
        // Event start
        VehicleDamageEvent event = new VehicleDamageEvent(this, source.getEntity(), source.getFinalDamage());
        getServer().getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return false;
        }
        // Event stop
        performHurtAnimation((int) event.getDamage());
        boolean instantKill = false;
        if (source instanceof EntityDamageByEntityEvent) {
            Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
            instantKill = damager instanceof Player && ((Player) damager).isCreative();
        }
        if (instantKill || getDamage() > 40) {
            // Event start
            VehicleDestroyEvent event2 = new VehicleDestroyEvent(this, source.getEntity());
            getServer().getPluginManager().callEvent(event2);
            if (event2.isCancelled()) {
                return false;
            }
            // Event stop
            if (linkedEntity != null) {
                mountEntity(linkedEntity);
            }
            if (instantKill && (!hasCustomName())) {
                kill();
            } else {
                if (level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) {
                    this.level.dropItem(this, new ItemBoat());
                }
                close();
            }
        }
    }
    return true;
}
Also used : Entity(cn.nukkit.entity.Entity) Player(cn.nukkit.Player) ItemBoat(cn.nukkit.item.ItemBoat) EntityDamageByEntityEvent(cn.nukkit.event.entity.EntityDamageByEntityEvent) VehicleDestroyEvent(cn.nukkit.event.vehicle.VehicleDestroyEvent) VehicleDamageEvent(cn.nukkit.event.vehicle.VehicleDamageEvent)

Aggregations

Player (cn.nukkit.Player)1 Entity (cn.nukkit.entity.Entity)1 EntityDamageByEntityEvent (cn.nukkit.event.entity.EntityDamageByEntityEvent)1 VehicleDamageEvent (cn.nukkit.event.vehicle.VehicleDamageEvent)1 VehicleDestroyEvent (cn.nukkit.event.vehicle.VehicleDestroyEvent)1 ItemBoat (cn.nukkit.item.ItemBoat)1