Skip to content

Commit

Permalink
Improve checks for Position::equals() and Location::equals() (#929)
Browse files Browse the repository at this point in the history
* Add files via upload

* Position::$level can be null.

* Use getLevel() in place of $level

because of WeakPosition.
  • Loading branch information
Muqsit authored and dktapps committed Jul 4, 2017
1 parent 1a6517e commit b8a3030
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/pocketmine/level/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,11 @@ public function getPitch(){
public function __toString(){
return "Location (level=" . ($this->isValid() ? $this->getLevel()->getName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)";
}

public function equals(Vector3 $v){
if($v instanceof Location){
return parent::equals($v) and $v->yaw == $this->yaw and $v->pitch == $this->pitch;
}
return parent::equals($v);
}
}
6 changes: 6 additions & 0 deletions src/pocketmine/level/Position.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,10 @@ public function setComponents($x, $y, $z){
return $this;
}

public function equals(Vector3 $v){
if($v instanceof Position){
return parent::equals($v) and $v->getLevel() === $this->getLevel();
}
return parent::equals($v);
}
}

0 comments on commit b8a3030

Please sign in to comment.