Search in sources :

Example 1 with DamageEntityEvent

use of com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent in project WorldGuard by EngineHub.

the class EventAbstractionListener method onLingeringApply.

@EventHandler(ignoreCancelled = true)
public void onLingeringApply(AreaEffectCloudApplyEvent event) {
    AreaEffectCloud entity = event.getEntity();
    List<PotionEffect> effects = new ArrayList<>();
    PotionEffectType baseEffectType = entity.getBasePotionData().getType().getEffectType();
    if (baseEffectType != null) {
        effects.add(new PotionEffect(baseEffectType, 0, 0));
    }
    if (entity.hasCustomEffects()) {
        effects.addAll(entity.getCustomEffects());
    }
    if (!Materials.hasDamageEffect(effects)) {
        return;
    }
    Cause cause = create(event.getEntity());
    event.getAffectedEntities().removeIf(victim -> Events.fireAndTestCancel(new DamageEntityEvent(event, cause, victim)));
}
Also used : DamageEntityEvent(com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) Cause(com.sk89q.worldguard.bukkit.cause.Cause) ArrayList(java.util.ArrayList) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud) EventHandler(org.bukkit.event.EventHandler)

Example 2 with DamageEntityEvent

use of com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent in project WorldGuard by EngineHub.

the class EventAbstractionListener method onVehicleDamage.

@EventHandler(ignoreCancelled = true)
public void onVehicleDamage(VehicleDamageEvent event) {
    Entity attacker = event.getAttacker();
    Events.fireToCancel(event, new DamageEntityEvent(event, create(attacker), event.getVehicle()));
}
Also used : DamageEntityEvent(com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) EventHandler(org.bukkit.event.EventHandler)

Example 3 with DamageEntityEvent

use of com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent in project WorldGuard by EngineHub.

the class EventAbstractionListener method onPotionSplash.

@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
    Entity entity = event.getEntity();
    ThrownPotion potion = event.getPotion();
    World world = entity.getWorld();
    Cause cause = create(potion);
    // Fire item interaction event
    Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem()));
    // Fire entity interaction event
    if (!event.isCancelled()) {
        int blocked = 0;
        int affectedSize = event.getAffectedEntities().size();
        boolean hasDamageEffect = Materials.hasDamageEffect(potion.getEffects());
        for (LivingEntity affected : event.getAffectedEntities()) {
            DelegateEvent delegate = hasDamageEffect ? new DamageEntityEvent(event, cause, affected) : new UseEntityEvent(event, cause, affected);
            // Consider the potion splash flag
            delegate.getRelevantFlags().add(Flags.POTION_SPLASH);
            if (Events.fireAndTestCancel(delegate)) {
                event.setIntensity(affected, 0);
                blocked++;
            }
        }
        if (affectedSize > 0 && blocked == affectedSize) {
            // server does weird things with this if the event is modified, so use cached number
            event.setCancelled(true);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) DamageEntityEvent(com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) UseItemEvent(com.sk89q.worldguard.bukkit.event.inventory.UseItemEvent) DelegateEvent(com.sk89q.worldguard.bukkit.event.DelegateEvent) Cause(com.sk89q.worldguard.bukkit.cause.Cause) UseEntityEvent(com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent) ThrownPotion(org.bukkit.entity.ThrownPotion) World(org.bukkit.World) EventHandler(org.bukkit.event.EventHandler)

Aggregations

DamageEntityEvent (com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent)3 EventHandler (org.bukkit.event.EventHandler)3 Cause (com.sk89q.worldguard.bukkit.cause.Cause)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 DelegateEvent (com.sk89q.worldguard.bukkit.event.DelegateEvent)1 UseEntityEvent (com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent)1 UseItemEvent (com.sk89q.worldguard.bukkit.event.inventory.UseItemEvent)1 ArrayList (java.util.ArrayList)1 World (org.bukkit.World)1 AreaEffectCloud (org.bukkit.entity.AreaEffectCloud)1 ThrownPotion (org.bukkit.entity.ThrownPotion)1 PotionEffect (org.bukkit.potion.PotionEffect)1 PotionEffectType (org.bukkit.potion.PotionEffectType)1