package com.owenoclee.peacefulplayer.listeners;

import com.owenoclee.peacefulplayer.permissions.Permissions;
import com.owenoclee.peacefulplayer.helper.Mobs;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

public class Pacified implements Listener {

    //Cancel pacified player attempt to damage hostile mob
    @EventHandler
    public void onAttack(EntityDamageByEntityEvent attackEvent) {
        Entity attacker = attackEvent.getDamager();
        if(attacker instanceof Projectile) {
            if(!(((Projectile)attacker).getShooter() instanceof Player))
                return;
            attacker = (Player)((Projectile)attackEvent.getDamager()).getShooter();
        }
        Entity victim = attackEvent.getEntity();
        if(attacker instanceof Player && attacker.hasPermission(Permissions.PACIFIED.getPermission()) && (Mobs.isHostile(victim) || Mobs.isNeutral(victim)) ) {
            attackEvent.setDamage(0);
            attackEvent.setCancelled(true);
        }
    }

}

@@ -362,33 +362,189 @@
 ity.
-EntityDamageByEntityEvent
+AreaEffectCloudApplyEvent;%0Aimport org.bukkit.event.entity.EntityDamageByEntityEvent;%0Aimport org.bukkit.event.entity.PotionSplashEvent;%0Aimport org.bukkit.projectiles.ProjectileSource
 ;%0A%0Ap
@@ -1265,16 +1265,16 @@
 age(0);%0A
-
         
@@ -1326,10 +1326,935 @@
 %0A    %7D%0A%0A
+    @EventHandler%0A    public void onLingeringPotionEffect(AreaEffectCloudApplyEvent areaEffectEvent) %7B%0A        ProjectileSource thrower = areaEffectEvent.getEntity().getSource();%0A        if(thrower instanceof Player && ((Player)thrower).hasPermission(Permissions.PACIFIED.getPermission())) %7B%0A            areaEffectEvent.getAffectedEntities().removeIf(mob -%3E Mobs.isHostile(mob) %7C%7C Mobs.isNeutral(mob));%0A        %7D%0A    %7D%0A%0A    @EventHandler%0A    public void onPotionEffect(PotionSplashEvent splashEvent) %7B%0A        ProjectileSource thrower = splashEvent.getEntity().getShooter();%0A        if(thrower instanceof Player && ((Player)thrower).hasPermission(Permissions.PACIFIED.getPermission())) %7B%0A            splashEvent.getAffectedEntities().forEach(mob -%3E %7B%0A                        if(Mobs.isHostile(mob) %7C%7C Mobs.isNeutral(mob))%0A                            splashEvent.setIntensity(mob, 0);%0A                    %7D);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

Fix pacified players dealing damage using splash/lingering potions