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

Solved ArmorInventory instance error!?

Discussion in 'Development' started by 7awariGamer, Apr 19, 2020.

  1. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    :44:14] [Server thread/CRITICAL]: TypeError: "Return value of pocketmine\entity\Living::getArmorInventory() must be an instance of pocketmine\inventory\ArmorInventory, null returned" (EXCEPTION) in "src/pocketmine/entity/Living" at line 427


    PHP:
    public static function armorsHealth($player)
          {
             if(
    $player instanceof Player)
              {
                 
    $l $player->getArmorInventory()->getLeggings()->getDamage();
                 
    $b $player->getArmorInventory()->getBoots()->getDamage();
                 
    $c $player->getArmorInventory()->getChestplate()->getDamage();
                 
    $h $player->getArmorInventory()->getHelmet()->getDamage();
                 
    $armorhealth = ((100 100) - ((($l $b $c $h) / 4) / 100)) * 100;
                 if(
    $armorhealth !== null) return $armorhealth;
              } else
                  {
                     
    MTask::cancelMTask();
                  }
          }
    PHP:
    class Mtask extends Task implements Listener {
       
        public function 
    __construct($sender)
          {
             
    $this->sender $sender;
          }
         
        public function 
    onRun(int $currentTick)
          {
             
    $sender $this->sender;
             
    $hud Main::$cfg->get("hud");
             
    $hud str_replace([    "{line}""{health}",     "{armors}",    "{combatlog}"],
                                [
    "\n",
                                 
    Main::playerHealth($sender),
                                 
    Main::armorsHealth($sender),
                                 
    Main::combatLog($sender)], $hud);
                               
             
    $sender->sendPopup($hud);
          }
       
        public static function 
    cancelMTask()
          {
             
    $this->getHandler()->cancel();
          }
    }
    I tried some tricks to fix it but bruh, nothing is working
     
    Last edited: Apr 19, 2020
  2. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    The Player object wasn't closed I had to check if it isn't close then cancel the task...
    Thx for platz1de
     
  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.