pocketmine\inventory\ChestInventory::onClose PHP Method

onClose() public method

public onClose ( Player $who )
$who pocketmine\Player
    public function onClose(Player $who)
    {
        if ($this->getHolder()->getLevel() instanceof Level) {
            /** @var TrappedChest $block */
            $block = $this->getHolder()->getBlock();
            if ($block instanceof TrappedChest) {
                if ($block->isActivated()) {
                    $block->deactivate();
                }
            }
        }
        if (count($this->getViewers()) === 1) {
            $pk = new BlockEventPacket();
            $pk->x = $this->getHolder()->getX();
            $pk->y = $this->getHolder()->getY();
            $pk->z = $this->getHolder()->getZ();
            $pk->case1 = 1;
            $pk->case2 = 0;
            if (($level = $this->getHolder()->getLevel()) instanceof Level) {
                $level->addChunkPacket($this->getHolder()->getX() >> 4, $this->getHolder()->getZ() >> 4, $pk);
            }
        }
        parent::onClose($who);
    }

Usage Example

 public function onClose(Player $who)
 {
     if (count($this->getViewers()) === 1) {
         $pk = new BlockEventPacket();
         $pk->x = $this->right->getHolder()->getX();
         $pk->y = $this->right->getHolder()->getY();
         $pk->z = $this->right->getHolder()->getZ();
         $pk->case1 = 1;
         $pk->case2 = 0;
         if (($level = $this->right->getHolder()->getLevel()) instanceof Level) {
             $level->addChunkPacket($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4, $pk);
         }
     }
     parent::onClose($who);
 }
All Usage Examples Of pocketmine\inventory\ChestInventory::onClose