Solved Phpstan

Discussion in 'Development' started by ErikX, May 29, 2021.

  1. ErikX

    ErikX Baby Zombie

    Messages:
    116
    GitHub:
    ErikPDev
    Recently I've been trying to fix PHPstan in my plugin.

    No matter what I try this stays.
    PHP:
    Problem found in ErikPDev/AdvanceDeaths/DeathContainer.php at line 40. :

    Call to an undefined method pocketmine\event\entity\EntityDamageEvent::getDamager()
    The code:
    PHP:
     /**
        * Convert variables to proper Data
        *
        * @param \pocketmine\entity\Entity|Player $entity
        * @param string $keyWord
        *
        * @return string
        */
        
    function ExecuteHelper($entity$keyWord){
            
    /** @param EntityDamageByEntityEvent $entity->GetLastDamageCause() */
            
    switch( strtolower($keyWord) ){
                case 
    "{name}":
                    if(!
    $entity instanceof Player){
                        return 
    $entity->getNameTag();
                    }
                    return 
    $entity->getName();
                case 
    "{killer}":
                    if(!
    $entity->getLastDamageCause()->getDamager() instanceof Player){
                        return 
    $entity->getLastDamageCause()->getDamager()->getNameTag();
                    }
                    return 
    $entity->getLastDamageCause()->getDamager()->getName();
                case 
    "{killercurrenthealth}":
                    return 
    $entity->getLastDamageCause()->getDamager()->getMaxHealth();
                case 
    "{killermaxhealth}":
                    return 
    $entity->getLastDamageCause()->getDamager()->getMaxHealth();
                case 
    "{weapon}":
                    return 
    $entity->getLastDamageCause()->getDamager()->getInventory()->getItemInHand()->getName();
            }
            return 
    "?";
        }
    Any tips or fixes?
     
  2. ErikX

    ErikX Baby Zombie

    Messages:
    116
    GitHub:
    ErikPDev
    I've solved this, I just created a variable called $LastDamageCause then set the param to EntityDamageByEntityEvent.
     

Share This Page

  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.