Why it dont work? Code: <?php declare(strict_types=1); namespace Alan; use pocketmine\scheduler\PluginTask; use pocketmine\Server; use pocketmine\block\Block; use pocketmine\event\Listener; use pocketmine\math\Vector3; use pocketmine\item\Item; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\Level; use pocketmine\plugin\PluginBase; use Alan\Task\DiamondGenTask; class Main extends PluginBase { public function onEnable() { $this->scheduler(); } public function scheduler() { $this->getScheduler()->scheduleRepeatingTask(new DiamondGenTask($this), 5 * 20); } } Here the effect task. Code: <?php namespace Alan\Tasks; use Alan\Main; use pocketmine\scheduler\PluginTask; use pocketmine\Server; use pocketmine\block\Block; use pocketmine\math\Vector3; use pocketmine\Level; use pocketmine\scheduler\Task; use pocketmine\event\Listener; use pocketmine\item\Item; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\block\Block; class DiamondGenTask extends Task { /** @var Main */ private $plugin; /** * CactusTask constructor. * @param Main $plugin */ public function __construct(Main $plugin) { $this->plugin = $plugin; } /** * @param $currentTick */ public function onRun(int $currentTick) { $level = $this->getOwner()->getServer()->getLevelByName('Alazar'); if($level instanceof Level) { $gen = new \pocketmime\block\White_glazed_terracotta(); $tile = $level->getTile(new Vector3($gen->getX() , $gen->getY()+1, $gen->getZ())); if($tile instanceof Chest){ $chest = $tile->getInventory(); $chest->addItem(Item::get(264, 0, 1)); } } } }
there are a few reasons, level may be null, $gen is not defined, coordinates may be wrong, tile is not a chest
There are other errors such as wrong use statement for Level and missing use statement for Chest in DiamondGenTask You instantiated a new Block instance which have no coordinates defined in it and tried to get coordinates from it