I want to create a plugin which send the mess "FULL" when player's inv is full. But nothing happen Code: //AutoSell public function isInventoryFull($player){ $inv = $player->getInventory(); if($event->getPlayer()->getInventory()->firstEmpty() === -1) { $player->sendMessage("FULLFULLFULLFULLFULLFULLFULLFULLFULL"); return true; } }
is it right? Code: public function isInventoryFull($event){ $player = $event->getPlayer(); if($player->getInventory()->firstEmpty() === -1) { $player->sendMessage("FULLFULLFULLFULLFULLFULLFULL"); return true; } }
If you know how to use events (if not tell me I'll explain), look here https://github.com/pmmp/PocketMine-MP/tree/stable/src/pocketmine/event what you need is an inventory event to check when the inventory is updated, https://github.com/pmmp/PocketMine-...event/inventory/InventoryTransactionEvent.php this should do, now you're going to listen to that event, and when called check if inventory is full. If inventory is full send the message. Tips : To get the player in this event it's $event->getTransaction()->getSource(); To get the inventory you get the player inventory; Use an ide to have automatic imports; ( right now it's pocketmine\event\inventory\InventoryTransactionEvent );
PHP: if (!$p->getInventory()->canAddItem(Item::get(ItemIds::AIR))){ $ev->setCancelled(); $p->sendTip("FULLFULLFULLFULLFULLFULLFULLFULLFULL"); } Don't over think it!
What you just did is useless it'll never get called lol if you can't item it just doesn't send it, plus where do you call that fuction
PHP: /*** @param InventoryPickupItemEvent $ev* @priority HIGHEST* @ignoreCancelled TRUE*/public function onInventoryPickupItem(InventoryPickupItemEvent $ev): void{ $inv = $ev->getInventory(); if($inv instanceof PlayerInventory){ $player = $inv->getHolder(); if(!$inv->canAddItem($ev->getItem()->getItem())){ $player->sendTip("WEE WOO WEE WOO"); $ev->setCancelled(); } }}