mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Split PlayerActionPacket handling into two classes, death is now a session state
This commit is contained in:
61
src/pocketmine/network/mcpe/handler/DeathSessionHandler.php
Normal file
61
src/pocketmine/network/mcpe/handler/DeathSessionHandler.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\handler;
|
||||
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
|
||||
use pocketmine\network\mcpe\protocol\RespawnPacket;
|
||||
use pocketmine\Player;
|
||||
|
||||
class DeathSessionHandler extends SessionHandler{
|
||||
|
||||
/** @var Player */
|
||||
private $player;
|
||||
/** @var NetworkSession */
|
||||
private $session;
|
||||
|
||||
public function __construct(Player $player, NetworkSession $session){
|
||||
$this->player = $player;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
public function setUp() : void{
|
||||
$pk = new RespawnPacket();
|
||||
$pk->position = $this->player->getOffsetPosition($this->player->getSpawn());
|
||||
$this->session->sendDataPacket($pk);
|
||||
}
|
||||
|
||||
public function handlePlayerAction(PlayerActionPacket $packet) : bool{
|
||||
switch($packet->action){
|
||||
case PlayerActionPacket::ACTION_RESPAWN:
|
||||
$this->player->respawn();
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_DIMENSION_CHANGE_REQUEST:
|
||||
//TODO: players send this when they die in another dimension
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\handler;
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
|
||||
use pocketmine\network\mcpe\protocol\AnimatePacket;
|
||||
use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
|
||||
@ -123,7 +124,58 @@ class SimpleSessionHandler extends SessionHandler{
|
||||
}
|
||||
|
||||
public function handlePlayerAction(PlayerActionPacket $packet) : bool{
|
||||
return $this->player->handlePlayerAction($packet);
|
||||
$pos = new Vector3($packet->x, $packet->y, $packet->z);
|
||||
|
||||
switch($packet->action){
|
||||
case PlayerActionPacket::ACTION_START_BREAK:
|
||||
$this->player->startBreakBlock($pos, $packet->face);
|
||||
|
||||
break;
|
||||
|
||||
case PlayerActionPacket::ACTION_ABORT_BREAK:
|
||||
case PlayerActionPacket::ACTION_STOP_BREAK:
|
||||
$this->player->stopBreakBlock($pos);
|
||||
break;
|
||||
case PlayerActionPacket::ACTION_START_SLEEPING:
|
||||
//unused
|
||||
break;
|
||||
case PlayerActionPacket::ACTION_STOP_SLEEPING:
|
||||
$this->player->stopSleep();
|
||||
break;
|
||||
case PlayerActionPacket::ACTION_JUMP:
|
||||
$this->player->jump();
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_SPRINT:
|
||||
$this->player->toggleSprint(true);
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_STOP_SPRINT:
|
||||
$this->player->toggleSprint(false);
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_SNEAK:
|
||||
$this->player->toggleSneak(true);
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_STOP_SNEAK:
|
||||
$this->player->toggleSneak(false);
|
||||
return true;
|
||||
case PlayerActionPacket::ACTION_START_GLIDE:
|
||||
case PlayerActionPacket::ACTION_STOP_GLIDE:
|
||||
break; //TODO
|
||||
case PlayerActionPacket::ACTION_CONTINUE_BREAK:
|
||||
$this->player->continueBreakBlock($pos, $packet->face);
|
||||
break;
|
||||
case PlayerActionPacket::ACTION_START_SWIMMING:
|
||||
break; //TODO
|
||||
case PlayerActionPacket::ACTION_STOP_SWIMMING:
|
||||
//TODO: handle this when it doesn't spam every damn tick (yet another spam bug!!)
|
||||
break;
|
||||
default:
|
||||
$this->player->getServer()->getLogger()->debug("Unhandled/unknown player action type " . $packet->action . " from " . $this->player->getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->player->setUsingItem(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function handleEntityFall(EntityFallPacket $packet) : bool{
|
||||
|
Reference in New Issue
Block a user