onSlotChange() is an internal function. You should not use it. Use addItem() to add items, and remove(), and setSlot().
PHP: use pocketmine\tile\Chest;$chest = $event->getBlock()->getLevel()->getTile($event->getBlock());if($chest instanceof Chest){ // execute logic here}