Fixed plugins causing crashes by using Level->unload() and add a warning

yes, we don't want you to use this, but it still shouldn't crash if it can be prevented...
This commit is contained in:
Dylan K. Taylor 2017-09-25 09:46:09 +01:00
parent 3c02a6a8ed
commit 28bce8d48c
2 changed files with 12 additions and 5 deletions

View File

@ -983,13 +983,16 @@ class Server{
if($level === $this->getDefaultLevel() and !$forceUnload){ if($level === $this->getDefaultLevel() and !$forceUnload){
throw new \InvalidStateException("The default level cannot be unloaded while running, please switch levels."); throw new \InvalidStateException("The default level cannot be unloaded while running, please switch levels.");
} }
if($level->unload($forceUnload) === true){
unset($this->levels[$level->getId()]);
return true; return $level->unload($forceUnload);
} }
return false; /**
* @internal
* @param Level $level
*/
public function removeLevel(Level $level) : void{
unset($this->levels[$level->getId()]);
} }
/** /**

View File

@ -473,6 +473,8 @@ class Level implements ChunkManager, Metadatable{
} }
/** /**
* @internal DO NOT use this from plugins, it's for internal use only. Use Server->unloadLevel() instead.
*
* Unloads the current level from memory safely * Unloads the current level from memory safely
* *
* @param bool $force default false, force unload of default level * @param bool $force default false, force unload of default level
@ -507,6 +509,8 @@ class Level implements ChunkManager, Metadatable{
$this->server->setDefaultLevel(null); $this->server->setDefaultLevel(null);
} }
$this->server->removeLevel($this);
$this->close(); $this->close();
return true; return true;