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

Solved Error in my Plugin

Discussion in 'Development' started by Jonas, May 11, 2017.

  1. Jonas

    Jonas Baby Zombie

    Messages:
    192
    When i interact with a Enchanted Golden Apple then i will get 200 Hearts and one Enchanted Golden Apple will remove but all is right only the item remove will not work.
    Here is my Error:
    Code:
    [Server] [PocketMine] [15:41:49] CRITICAL> "Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'SoupFFA v1.0.0': Expected Item[], got integer on Main\SoupFFA
    [Server] [PocketMine] [15:41:49] CRITICAL> InvalidArgumentException: "Expected Item[], got integer" (EXCEPTION) in "/src/pocketmine/inventory/BaseInventory" at line 335
    
    Here is my Code from the PlayerInteractEvent.
    PHP:
    public function onInteract(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            
    $getItemId $player->getInventory()->getItemInHand()->getId();
            if(
    $getItemId === Item::ENCHANTED_GOLDEN_APPLE){
                
    $player->setMaxHealth(100);
                
    $player->sendMessage($this->prefix" Du hast nun 100 Herzen");
                
    $player->setHealth(100);
                
    $player->getInventory()->removeItem($player->getInventory()->getItemInHand()->getCount() - 1);
            }
    }
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You're trying to remove an integer from the inventory of a player. That's not going to work. Instead, you should remove an item OBJECT from the inventory, not the count.
    PHP:
    $hand $player->getInventory()->getItemInHand();
    $player->getInventory()->removeItem($hand->setCount($hand->getCount 1));
     
    Jonas likes this.
  3. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    This seems illogical:
    PHP:
    $player->getInventory()->removeItem($player->getInventory()->getItemInHand()->getCount() - 1);
     
    Sandertv likes this.
  4. Jonas

    Jonas Baby Zombie

    Messages:
    192
    Thanks
     
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Why is this not in the facepalm section... :facepalm::facepalm:
     
    Sandertv likes this.
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    That's pretty good, but it could be improved ;)
    PHP:
    $hand $player->getInventory()->getItemInHand();
    $handclone = clone $hand;
    $handclone->setCount($handclone->getCount() - 1);
    $player->getInventory()->setItemInHand($handclone);
    I would think the clone isn't even needed also...
     
    mal0ne_23 likes this.
  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.