mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Player: move toggle* rollback handling to network session
this allows network sessions to react to it how they want, or (in the case of things like Specter) perhaps ignore it.
This commit is contained in:
parent
80a6fc5dd1
commit
f332550e52
@ -2145,38 +2145,37 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
||||
return false;
|
||||
}
|
||||
|
||||
public function toggleSprint(bool $sprint) : void{
|
||||
public function toggleSprint(bool $sprint) : bool{
|
||||
$ev = new PlayerToggleSprintEvent($this, $sprint);
|
||||
$ev->call();
|
||||
if($ev->isCancelled()){
|
||||
$this->sendData($this);
|
||||
}else{
|
||||
$this->setSprinting($sprint);
|
||||
return false;
|
||||
}
|
||||
$this->setSprinting($sprint);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function toggleSneak(bool $sneak) : void{
|
||||
public function toggleSneak(bool $sneak) : bool{
|
||||
$ev = new PlayerToggleSneakEvent($this, $sneak);
|
||||
$ev->call();
|
||||
if($ev->isCancelled()){
|
||||
$this->sendData($this);
|
||||
}else{
|
||||
$this->setSneaking($sneak);
|
||||
return false;
|
||||
}
|
||||
$this->setSneaking($sneak);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function toggleFlight(bool $fly) : void{
|
||||
public function toggleFlight(bool $fly) : bool{
|
||||
$ev = new PlayerToggleFlightEvent($this, $fly);
|
||||
if(!$this->allowFlight){
|
||||
$ev->setCancelled();
|
||||
}
|
||||
$ev->setCancelled(!$this->allowFlight);
|
||||
$ev->call();
|
||||
if($ev->isCancelled()){
|
||||
$this->networkSession->syncAdventureSettings($this);
|
||||
}else{ //don't use setFlying() here, to avoid feedback loops
|
||||
$this->flying = $fly;
|
||||
$this->resetFallDistance();
|
||||
return false;
|
||||
}
|
||||
//don't use setFlying() here, to avoid feedback loops - TODO: get rid of this hack
|
||||
$this->flying = $fly;
|
||||
$this->resetFallDistance();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function animate(int $action) : bool{
|
||||
|
@ -362,16 +362,24 @@ class SimpleSessionHandler extends SessionHandler{
|
||||
$this->player->jump();
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_SPRINT:
|
||||
$this->player->toggleSprint(true);
|
||||
if(!$this->player->toggleSprint(true)){
|
||||
$this->player->sendData($this->player);
|
||||
}
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_STOP_SPRINT:
|
||||
$this->player->toggleSprint(false);
|
||||
if(!$this->player->toggleSprint(false)){
|
||||
$this->player->sendData($this->player);
|
||||
}
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_SNEAK:
|
||||
$this->player->toggleSneak(true);
|
||||
if(!$this->player->toggleSneak(true)){
|
||||
$this->player->sendData($this->player);
|
||||
}
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_STOP_SNEAK:
|
||||
$this->player->toggleSneak(false);
|
||||
if(!$this->player->toggleSneak(false)){
|
||||
$this->player->sendData($this->player);
|
||||
}
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_GLIDE:
|
||||
case PlayerActionPacket::ACTION_STOP_GLIDE:
|
||||
@ -423,7 +431,9 @@ class SimpleSessionHandler extends SessionHandler{
|
||||
|
||||
$isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING);
|
||||
if($isFlying !== $this->player->isFlying()){
|
||||
$this->player->toggleFlight($isFlying);
|
||||
if(!$this->player->toggleFlight($isFlying)){
|
||||
$this->session->syncAdventureSettings($this->player);
|
||||
}
|
||||
$handled = true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user