$level = $this->getPlugin()->getServer()->getLevelByName("test"); $pos = new Position(100, 78, 100, $level); $dirt = BlockFactory::get(BlockIRT); $air = BlockFactory::get(Block::AIR); if($this->getPlugin()->time > 0) { $level->setBlock($pos, $dirt, true, true); } if($this->getPlugin()->time == 0) { $level->setBlock($pos, $air, true, true); } } ^^^^^ My code keeps giving an error "Call to a member function setBlock() on null" how would I fix this?
What is onRun? Anyway, $level is assigned a null instead of a Level object. That means I couldn't get the world. You can either make sure the world name is correct or you can use the Server::loadLevel() function I will.
public function onRun($tick) { It is a function. Second I get that the code cannot find the world. How do I make it so the code can register it as NonNull?
The function name can be freely decided anywhere. I guess I'm using Task, but I'm not sure. Writing it in the question is a better way. The solution to this problem is general error handling. You can see that getLevelByName returns Level or null (?Level). GitHub(Server.php) Check the return value is Level. PHP: $level = $this->getPlugin()->getServer()->getLevelByName("test");if (!($level instanceof Level)) { //error handling...}