1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

EntityDamageByEntityEvent Help

Discussion in 'Development' started by JarguarLoveMC, Jun 8, 2020.

  1. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    It just doesn't work, no error either, i did register all event/listener
    PHP:
                if($event instanceof EntityDamageByEntityEvent){
                    
    $e $event->getEntity();
                    
    $d $event->getDamager();               
                    if (
    $e instanceof Player && $d instanceof Player) {
                        if(
    $e->hasEffect(Effect::INVISIBILITY)) {
                            
    $e->removeEffect(Effect::INVISIBILITY);
                        }
                        if(
    $d->hasEffect(Effect::INVISIBILITY)) {
                            
    $d->removeEffect(Effect::INVISIBILITY);                       
                        }
                }
            }
    Any help would be greatly appreciate
     
  2. fevio

    fevio Spider Jockey

    Messages:
    33
    Try at $event->getDamager() , $event->getEntity()->getLastDamageCause()->getDamager()
     
  3. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    The code seems to be correct, but I would try updating two things.
    1. removeEffect() already checks if the player has the effect, there's no need of checking it again.
    2. Call the EntityDamageByEntityEvent event directly on the listener, again, there's no need of checking if EntityDamageEvent is an instance of it.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.