PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
DeathPacketHandler.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\network\mcpe\handler;
25
35
37 public function __construct(
38 private Player $player,
39 private NetworkSession $session,
40 private InventoryManager $inventoryManager,
41 private Translatable|string $deathMessage
42 ){}
43
44 public function setUp() : void{
45 $this->session->sendDataPacket(RespawnPacket::create(
46 $this->player->getOffsetPosition($this->player->getSpawn()),
47 RespawnPacket::SEARCHING_FOR_SPAWN,
48 $this->player->getId()
49 ));
50
52 $parameters = [];
53 if($this->deathMessage instanceof Translatable){
54 $language = $this->player->getLanguage();
55 if(!$this->player->getServer()->isLanguageForced()){
56 [$message, $parameters] = $this->session->prepareClientTranslatableMessage($this->deathMessage);
57 }else{
58 $message = $language->translate($this->deathMessage);
59 }
60 }else{
61 $message = $this->deathMessage;
62 }
63 $this->session->sendDataPacket(DeathInfoPacket::create($message, $parameters));
64 }
65
66 public function handlePlayerAction(PlayerActionPacket $packet) : bool{
67 if($packet->action === PlayerAction::RESPAWN){
68 $this->player->respawn();
69 return true;
70 }
71
72 return false;
73 }
74
75 public function handleContainerClose(ContainerClosePacket $packet) : bool{
76 $this->inventoryManager->onClientRemoveWindow($packet->windowId);
77 return true;
78 }
79
80 public function handleRespawn(RespawnPacket $packet) : bool{
81 if($packet->respawnState === RespawnPacket::CLIENT_READY_TO_SPAWN){
82 $this->session->sendDataPacket(RespawnPacket::create(
83 $this->player->getOffsetPosition($this->player->getSpawn()),
84 RespawnPacket::READY_TO_SPAWN,
85 $this->player->getId()
86 ));
87 return true;
88 }
89 return false;
90 }
91}
static create(string $messageTranslationKey, array $messageParameters)
static create(Vector3 $position, int $respawnState, int $actorRuntimeId)