So I'm trying to clear a chest inventory on transaction, aka when the player brings it to there inventory, but since the its PlayerInventory it clears the players inventory itself. Is there anyway i can lear the chest inventory but not the player inventory
Can you show us what you have been trying? I suppose you could do a check of whether or not the inventory is an instanceof pocketmine\tile\Chest.
PHP: ublic function onTransaction(InventoryTransactionEvent $event){ $transactions = $event->getTransaction()->getTransactions(); $player = null; $chestinv = null; $action = null; foreach($transactions as $transaction){ $inv1 = $transaction->getInventory(); if($inv1 instanceof PlayerInventory) { foreach($inv1->getViewers() as $assumed) if($assumed instanceof Player) { $item = Item::get(Item::PAPER); $player = $assumed; if($transaction->getTargetItem()->getCustomName() === TF::GREEN.TF::BOLD."Level I Book") { $inv1->clearAll(); $this->plugin->utils->sendLevel1BookMenu($assumed); }
Have you tried it and are sure? As far as I can tell, his suggestion would work. It also appears to be that way considering how Muqsit used it in ChestShop.
Have you tried it and are sure? As far as I can tell, his suggestion would work. It also appears to be that way considering how Muqsit used it in Chest yes but his checks to see if its has certian data,i just want to clear the inventory but cant since the inventory holder is Player
Not tested, but try this out. PHP: public function onTransaction(InventoryTransactionEvent $event){ $transactions = $event->getTransaction()->getTransactions(); $player = null; $chest = null; $item = null; foreach($transactions as $transaction){ $item = $transaction->getTargetItem(); $holder = $transaction->getInventory()->getHolder(); if($holder instanceof Player){ $player = $holder; } else if($holder instanceof Chest){ //pocketmine\tile\Chest not pocketmine\block\Chest :P $chest = $holder; } } if($player !== null and $chest !== null){ $event->setCancelled(); if($item->getId() == Item::PAPER and $item->getCustomName() === TextFormat::GREEN.TextFormat::BOLD."Level I Book"){ $player->getInventory()->clearAll(); //call whatever else you need :P } } }