mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Use hasHandlers() for events in player movement processing pathway
this should offer a minor performance improvement.
This commit is contained in:
parent
cd6abbe0bb
commit
d03e4d17ec
@ -133,14 +133,18 @@ class HungerManager{
|
||||
if(!$this->enabled){
|
||||
return 0;
|
||||
}
|
||||
$ev = new PlayerExhaustEvent($this->entity, $amount, $cause);
|
||||
$ev->call();
|
||||
if($ev->isCancelled()){
|
||||
return 0.0;
|
||||
$evAmount = $amount;
|
||||
if(PlayerExhaustEvent::hasHandlers()){
|
||||
$ev = new PlayerExhaustEvent($this->entity, $amount, $cause);
|
||||
$ev->call();
|
||||
if($ev->isCancelled()){
|
||||
return 0.0;
|
||||
}
|
||||
$evAmount = $ev->getAmount();
|
||||
}
|
||||
|
||||
$exhaustion = $this->getExhaustion();
|
||||
$exhaustion += $ev->getAmount();
|
||||
$exhaustion += $evAmount;
|
||||
|
||||
while($exhaustion >= 4.0){
|
||||
$exhaustion -= 4.0;
|
||||
@ -159,7 +163,7 @@ class HungerManager{
|
||||
}
|
||||
$this->setExhaustion($exhaustion);
|
||||
|
||||
return $ev->getAmount();
|
||||
return $evAmount;
|
||||
}
|
||||
|
||||
public function getFoodTickTimer() : int{
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user