error: "Call to a member function getDamage() on array" (EXCEPTION) in "plugins/.../repair/Repair" at line 63 CODE: case "fixall": if (!($sender instanceof Player)) { $sender->sendMessage("Run this command ingame."); return true; } $item = $sender->getInventory()->getContents(); $cost = (int)($this->getConfig()->get("cost")) * $sender->getInventory()->getContents()->getDamage(); $eco = EconomyAPI::getInstance(); if ($eco->myMoney($sender) < $cost) { $sender->sendMessage("• §cNot enough money. ($cost)"); return true; }else if (!isset(self::$pending[$sender->getName()]) || self::$pending[$sender->getName()] < time()) { self::$pending[$sender->getName()] = time() + 10; $sender->sendMessage("• §eAre you sure to repair all item? This will cost you §c" . $eco->getMonetaryUnit() . $cost . "§e. Type §c/fix§e again to confirm."); return true; }else { unset(self::$pending[$sender->getName()]); $eco->reduceMoney($sender, $cost); foreach($sender->getInventory()->getContents() as $index => $item){ if($item->getDamage() > 0){ $sender->getInventory()->setItem($index, $item->setDamage(0)); } } foreach($sender->getArmorInventory()->getContents() as $index => $item){ if($item->getDamage() > 0){ $sender->getArmorInventory()->setItem($index, $item->setDamage(0)); } } $sender->sendMessage("• §aDone. §c(-" . $eco->getMonetaryUnit() . $cost . ")"); } return true;
The error is pretty self explanatory. What do you expect PHP: $sender->getInventory()->getContents()->getDamage(); to return?
$totaldamage = 0; foreach($sender->getInventory()->getContents() as $index => $item){ if(($damage = $item->getDamage()) > 0){ $totaldamage = $totaldamage + $damage; } $cost = (configcost) * $totaldamage;