Player: move flight toggling to its own method

This commit is contained in:
Dylan K. Taylor 2018-08-14 19:21:13 +01:00
parent d8198d8130
commit b3d8d10bec

View File

@ -2411,6 +2411,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
} }
public function toggleFlight(bool $fly) : void{
$ev = new PlayerToggleFlightEvent($this, $fly);
$this->server->getPluginManager()->callEvent($ev);
if($ev->isCancelled()){
$this->sendSettings();
}else{
$this->setFlying($fly);
}
}
public function animate(int $action) : bool{ public function animate(int $action) : bool{
$this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $action)); $this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $action));
if($ev->isCancelled()){ if($ev->isCancelled()){
@ -2442,13 +2452,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"])); $this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"]));
return true; return true;
}elseif($isFlying !== $this->isFlying()){ }elseif($isFlying !== $this->isFlying()){
$this->server->getPluginManager()->callEvent($ev = new PlayerToggleFlightEvent($this, $isFlying)); $this->toggleFlight($isFlying);
if($ev->isCancelled()){
$this->sendSettings();
}else{
$this->flying = $ev->isFlying();
}
$handled = true; $handled = true;
} }