mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 10:53:05 +00:00
Position: add getLevelNonNull()
this allows assuming that a position has a valid world in places where it's never expected to not be valid. Since this is the vast majority of usages, it eliminates a lot of possible null-pointer warnings given by static analysers. TODO: Consider whether we can make Position->getLevel/World use this behaviour out of the box in the next major version.
This commit is contained in:
@ -1743,7 +1743,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
}
|
||||
|
||||
if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){
|
||||
if(!$this->switchLevel($pos->getLevel())){
|
||||
if(!$this->switchLevel($pos->getLevelNonNull())){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1849,7 +1849,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
$pitch = $pitch ?? $pos->pitch;
|
||||
}
|
||||
$from = Position::fromObject($this, $this->level);
|
||||
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
|
||||
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevelNonNull() : $this->level);
|
||||
$ev = new EntityTeleportEvent($this, $from, $to);
|
||||
$ev->call();
|
||||
if($ev->isCancelled()){
|
||||
|
Reference in New Issue
Block a user