Use hasHandlers() for events in player movement processing pathway

this should offer a minor performance improvement.
This commit is contained in:
Dylan K. Taylor
2023-08-23 14:26:17 +01:00
parent cd6abbe0bb
commit d03e4d17ec
2 changed files with 21 additions and 15 deletions

View File

@ -1330,18 +1330,20 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$deltaAngle = abs($this->lastLocation->yaw - $to->yaw) + abs($this->lastLocation->pitch - $to->pitch);
if($delta > 0.0001 || $deltaAngle > 1.0){
$ev = new PlayerMoveEvent($this, $from, $to);
if(PlayerMoveEvent::hasHandlers()){
$ev = new PlayerMoveEvent($this, $from, $to);
$ev->call();
$ev->call();
if($ev->isCancelled()){
$this->revertMovement($from);
return;
}
if($ev->isCancelled()){
$this->revertMovement($from);
return;
}
if($to->distanceSquared($ev->getTo()) > 0.01){ //If plugins modify the destination
$this->teleport($ev->getTo());
return;
if($to->distanceSquared($ev->getTo()) > 0.01){ //If plugins modify the destination
$this->teleport($ev->getTo());
return;
}
}
$this->lastLocation = $to;