Guys, how do you do PHP: Server::getInstance()->unloadLevel(); ? I used this for my skywars plugin: PHP: Server::getInstance()->unloadLevel('Skywars"); This works fine for loadLevel(), but when i do unloadLevel(), i get: Code: 31.01 09:56:36 [Server] CRITICAL Could not pass event pocketmine\event\player\PlayerMoveEvent to Teleport v1: Argument 1 passed to pocketmine\Server::unloadLevel() must be an instance of pocketmine\level\Level, string given, called in /plugins/SpawnTeleport/src/Teleport/main.php on line 1035 and defined on Teleport\main
There are many ways, but I will only list the most common 3: Server::getInstance() This is considered as a bad practice because includes the usage of a static property, I don't know why it's included in the API of PocketMine, but don't use it anyways xD $this->getServer() This is allowed in many places, you can access this Safe property inside any class that extends the PluginBase one. $player->getserver() The same as above, but accessed within a player object, it's also Safe.
The actual issue is that you need to do Server::getInstance()->unloadLevel(Server::getInstance()->getLevelByName("SkyWars")); Although statically accessing the Server is bad practice, this won't cause an issue.
lel no, i mean get a level instance! :3 p.s what is the difference between Server::getInstance() and the others?
That the one that you're using is considered as a BAD PRACTICE xD it's the same way to access the API, but with a different start point xD
OK! P.s just a random question, In the: PHP: public function __construct() What would you put here to get the Level instance so you can store it as a var? PHP: public function __construct(<Is it Level Here?> $level){ $lev = $level;}
You give string in function unloadLevel,but will be give pocketmine\level\Level,use this Code: $lvl = Server::getInstance()->getLevelByName("LevelName"); Server::getInstance()->unloadLevel($lvl);