'Pocketmine: BlockPlaceEvent, add items when chest is placed

What I want to do is some kit, whenever I place a chest, it will fill items inside it. This is my code so far.

public function onBlockPlace(BlockPlaceEvent $event): void {
        $dataConfig = CustomConfig::get("data.yml");
        $block = $event->getBlock();
        $item = $event->getItem();
        $player = $event->getPlayer();
        $server = $player->getServer();
        $world = $player->getWorld();


        if ($item->getId() === ItemIds::CHEST && $item->getMeta() !== 0) {
            $chest = new Chest($world, $block->getPosition());
            $kits = $dataConfig->getConfig()->getAll(true);
            $meta = $item->getMeta();


            // add items on the chest
            foreach ($kits as $id) {
                $kit = $dataConfig->getConfig()->get($id);
                if ($kit["meta"] === $meta) {
                    $chest->setName($kit["display"]);
                    $items = $dataConfig->getConfig()->getNested("$id.chest.items");


                    foreach ($items as $key => $value) {
                        $itemKit = ItemKit::fromArray($value, $key);
                        $chest->getInventory()->addItem($itemKit->getItem());
                    }


                    break;
                }
            }


            $world->addTile($chest);
            $world->setBlock($block->getPosition(), $block);
            $item->pop();
            $event->cancel();
        }
    }

It would add the items on the chest, and show the chest in the world, the problem is that now the default behavior is gone, for example, the blockplace sound, pairevent, etc. But if I were to remove the event.cancel(), and have this:

            $world->addTile($chest);
            // $world->setBlock($block->getPosition(), $block);
            // $item->pop();
            // $event->cancel();

The title of the chest is the name of the item. Like for example the name of the chest item is Awesome kit, I want the title of the chest tile to be just Awesome, but what happened is the title is the Awesome kit.

This is the result of those two:

            $world->addTile($chest);
            $world->setBlock($block->getPosition(), $block);
            $item->pop();
            $event->cancel();

Image1

            $world->addTile($chest);
            // $world->setBlock($block->getPosition(), $block);
            // $item->pop();
            // $event->cancel();

Image2

How do I achieve the first one, but still having the default behavior?



Solution 1:[1]

I found an old GitHub bug issue from 2017: https://github.com/pmmp/PocketMine-MP/issues/1554

Apparently the PMMP Team couldn't replicate it, so the issue got closed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LolXDDev