Throw exceptions when trying to add closed entities or tiles to levels

This commit is contained in:
Dylan K. Taylor 2017-10-20 18:22:28 +01:00
parent 30211bee82
commit 7b04049bb7

View File

@ -2479,9 +2479,13 @@ class Level implements ChunkManager, Metadatable{
* @throws LevelException * @throws LevelException
*/ */
public function addEntity(Entity $entity){ public function addEntity(Entity $entity){
if($entity->isClosed()){
throw new \InvalidArgumentException("Attempted to add a garbage closed Entity to Level");
}
if($entity->getLevel() !== $this){ if($entity->getLevel() !== $this){
throw new LevelException("Invalid Entity level"); throw new LevelException("Invalid Entity level");
} }
if($entity instanceof Player){ if($entity instanceof Player){
$this->players[$entity->getId()] = $entity; $this->players[$entity->getId()] = $entity;
} }
@ -2494,6 +2498,9 @@ class Level implements ChunkManager, Metadatable{
* @throws LevelException * @throws LevelException
*/ */
public function addTile(Tile $tile){ public function addTile(Tile $tile){
if($tile->isClosed()){
throw new \InvalidArgumentException("Attempted to add a garbage closed Tile to Level");
}
if($tile->getLevel() !== $this){ if($tile->getLevel() !== $this){
throw new LevelException("Invalid Tile level"); throw new LevelException("Invalid Tile level");
} }