Fixed fall handling when flying, closes #2709

This commit is contained in:
Dylan K. Taylor 2019-01-29 13:28:43 +00:00
parent 71d17c50d6
commit a150f39b02

View File

@ -476,9 +476,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
public function setFlying(bool $value){ public function setFlying(bool $value){
if($this->flying !== $value){
$this->flying = $value; $this->flying = $value;
$this->resetFallDistance();
$this->sendSettings(); $this->sendSettings();
} }
}
public function isFlying() : bool{ public function isFlying() : bool{
return $this->flying; return $this->flying;
@ -1410,19 +1413,17 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->allowFlight = $this->isCreative(); $this->allowFlight = $this->isCreative();
if($this->isSpectator()){ if($this->isSpectator()){
$this->flying = true; $this->setFlying(true);
$this->keepMovement = true; $this->keepMovement = true;
$this->despawnFromAll(); $this->despawnFromAll();
}else{ }else{
$this->keepMovement = $this->allowMovementCheats; $this->keepMovement = $this->allowMovementCheats;
if($this->isSurvival()){ if($this->isSurvival()){
$this->flying = false; $this->setFlying(false);
} }
$this->spawnToAll(); $this->spawnToAll();
} }
$this->resetFallDistance();
$this->namedtag->setInt("playerGameType", $this->gamemode); $this->namedtag->setInt("playerGameType", $this->gamemode);
if(!$client){ //Gamemode changed by server, do not send for client changes if(!$client){ //Gamemode changed by server, do not send for client changes
$this->sendGamemode(); $this->sendGamemode();
@ -1679,6 +1680,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->newPosition = null; $this->newPosition = null;
} }
public function fall(float $fallDistance) : void{
if(!$this->flying){
parent::fall($fallDistance);
}
}
public function jump() : void{ public function jump() : void{
(new PlayerJumpEvent($this))->call(); (new PlayerJumpEvent($this))->call();
parent::jump(); parent::jump();
@ -2942,8 +2949,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$ev->call(); $ev->call();
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->sendSettings(); $this->sendSettings();
}else{ }else{ //don't use setFlying() here, to avoid feedback loops
$this->flying = $ev->isFlying(); $this->flying = $ev->isFlying();
$this->resetFallDistance();
} }
$handled = true; $handled = true;