what's wrong with my code? the level with the name Gorzen located on PockeMine/worlds/world and Gorzen is the only world i have PHP: public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool { if(strtolower($command->getName()) == "world"){ $world = $sender->getPlayer()->getLevel()->getName();//Gorzen var_dump($world);//Gorzen var_dump($this->getServer()->getLevelByName($world));//NULL var_dump($this->getServer()->getLevelByName('world'));//instanceof pocketmine\level\Level return true; } } i made this post because my issue on github got closed https://github.com/pmmp/PocketMine-MP/issues/2778
Try this: PHP: $world = $sender->getLevel()->getFolderName(); Let me emphasize that levels are identified by their folder name and not their "display" name. This is also why Server->getLevelByName("world") returns the desired Level object in your case. It's the correct name.
then shouldn't it be getLevelByFolderName(); PHP: $world = $sender->getLevel()->getFolderName();var_dump($this->getServer()->getLevelByName($world); returned Code: string(6) "Gorzen" object(pocketmine\level\Level)#10763 (0) { }
You're absolutely right to point out this discrepancy, however, I personally would prefer to keep the shorter method name. But in the upcoming backwards-incompatible version 4.0 your suggestion is (kind of) addressed in the following commit: https://github.com/pmmp/PocketMine-MP/commit/e341f3dce233c60a7e5715bc0ec6f857675d4c73