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); }}
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));
This seems illogical: PHP: $player->getInventory()->removeItem($player->getInventory()->getItemInHand()->getCount() - 1);
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...