Check for closed target Levels in Position (#241)

More foolproof
This commit is contained in:
Dylan K. Taylor
2017-01-09 13:18:28 +00:00
committed by GitHub
parent 0a3fd8737a
commit 6fbb9b6083
3 changed files with 46 additions and 4 deletions

View File

@ -53,7 +53,18 @@ class WeakPosition extends Position{
return Server::getInstance()->getLevel($this->levelId);
}
public function setLevel(Level $level){
/**
* @param Level|null $level
*
* @return $this
*
* @throws \InvalidArgumentException if the specified Level has been closed
*/
public function setLevel(Level $level = null){
if($level !== null and $level->isClosed()){
throw new \InvalidArgumentException("Specified level has been unloaded and cannot be used");
}
$this->levelId = ($level !== null ? $level->getId() : -1);
return $this;
}