Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved EntityDamageEvent help.

Comments in 'Plugin Development' started by thebigsmileXD, Sep 21, 2015.

  1. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I have this function in my plugin oitc:
    PHP:
        public function damageHandler(EntityDamageEvent $event){
            
    $entity $event->getEntity();
            if(
    $entity instanceof Player && $this->isPlaying($entity)){
                
    $this->getLogger()->info($entity->getName() . " is playing");
                
    $cause $entity->getLastDamageCause();
                if(
    $cause instanceof EntityDamageByEntityEvent){
                    
    $this->getLogger()->info($entity->getName() . " eeeeeeee");
                    
    $hitter $cause->getDamager();
                    if(
    $cause->getEntity() instanceof Arrow){
                        
    $this->getLogger()->info($entity->getName() . " hit by arrow");
                        
    $hitter $hitter->shootingEntity;
                        if(
    $hitter instanceof Player && $this->isPlaying($hitter)){
                            
    $this->getLogger()->info($hitter->getName() . " hit " $entity->getName());
                        }
                    }
                }
            }
        }
    The problem with that is that if i hit another player, "eeeeeee" is not printed the first time i hit an entity, only printed to console the second time or any other hits.
    Why?
    Last edited: Sep 21, 2015
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Contents of $this->isPlaying()?
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Thats not important. It returns true.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Because you are checking lastDamageCause? lastDamageCause is only set on an entity after EntityDamageEvent has completed (and confirmed not cancelled). It is still the previous event (or null) when EntityDamageEvent is being handled. Why don't you just check $event instanceof EntityDamageByEntityEvent? Please do not copy code blindly.
    thebigsmileXD and jojoe77777 like this.
  5. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Actually i haven't just copied it, nice explaination, thank you ^^
    I rewrote the whole thing anyways

Share This Page

Advertisement