make a cost of repair all item

Discussion in 'Plugin Help' started by BaoNam99, Feb 8, 2019.

  1. BaoNam99

    BaoNam99 Spider

    Messages:
    11
    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;
     
  2. Muqsit

    Muqsit Chicken Verified

    Messages:
    1,517
    GitHub:
    muqsit
    The error is pretty self explanatory. What do you expect
    PHP:
    $sender->getInventory()->getContents()->getDamage();
    to return?
     
  3. BaoNam99

    BaoNam99 Spider

    Messages:
    11
    damaged total of inventory
     
  4. Gianluxx

    Gianluxx Silverfish

    Messages:
    18
    GitHub:
    Gianluxx
    $totaldamage = 0;
    foreach($sender->getInventory()->getContents() as $index => $item){
    if(($damage = $item->getDamage()) > 0){
    $totaldamage = $totaldamage + $damage;
    }
    $cost = (configcost) * $totaldamage;
     
  5. BaoNam99

    BaoNam99 Spider

    Messages:
    11
    thanks
     

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.