mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Player: reduce duplicated code in PlayerActionPacket handler
This commit is contained in:
parent
4f8f334436
commit
b003295d01
@ -2746,40 +2746,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
$this->jump();
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_SPRINT:
|
||||
$ev = new PlayerToggleSprintEvent($this, true);
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if($ev->isCancelled()){
|
||||
$this->sendData($this);
|
||||
}else{
|
||||
$this->setSprinting(true);
|
||||
}
|
||||
$this->toggleSprint(true);
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_STOP_SPRINT:
|
||||
$ev = new PlayerToggleSprintEvent($this, false);
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if($ev->isCancelled()){
|
||||
$this->sendData($this);
|
||||
}else{
|
||||
$this->setSprinting(false);
|
||||
}
|
||||
$this->toggleSprint(false);
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_SNEAK:
|
||||
$ev = new PlayerToggleSneakEvent($this, true);
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if($ev->isCancelled()){
|
||||
$this->sendData($this);
|
||||
}else{
|
||||
$this->setSneaking(true);
|
||||
}
|
||||
$this->toggleSneak(true);
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_STOP_SNEAK:
|
||||
$ev = new PlayerToggleSneakEvent($this, false);
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if($ev->isCancelled()){
|
||||
$this->sendData($this);
|
||||
}else{
|
||||
$this->setSneaking(false);
|
||||
}
|
||||
$this->toggleSneak(false);
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_GLIDE:
|
||||
case PlayerActionPacket::ACTION_STOP_GLIDE:
|
||||
@ -2804,6 +2780,26 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function toggleSprint(bool $sprint) : void{
|
||||
$ev = new PlayerToggleSprintEvent($this, $sprint);
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if($ev->isCancelled()){
|
||||
$this->sendData($this);
|
||||
}else{
|
||||
$this->setSprinting($sprint);
|
||||
}
|
||||
}
|
||||
|
||||
public function toggleSneak(bool $sneak) : void{
|
||||
$ev = new PlayerToggleSneakEvent($this, $sneak);
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if($ev->isCancelled()){
|
||||
$this->sendData($this);
|
||||
}else{
|
||||
$this->setSneaking($sneak);
|
||||
}
|
||||
}
|
||||
|
||||
public function handleAnimate(AnimatePacket $packet) : bool{
|
||||
if(!$this->spawned or !$this->isAlive()){
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user