PocketMine-MP 5.21.2 git-09bf203267aca9b83a09640e17bfac0fc7b58ff8
Loading...
Searching...
No Matches
DeathInfoPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
18use function count;
19
24 public const NETWORK_ID = ProtocolInfo::DEATH_INFO_PACKET;
25
26 private string $messageTranslationKey;
28 private array $messageParameters;
29
34 public static function create(string $messageTranslationKey, array $messageParameters) : self{
35 $result = new self;
36 $result->messageTranslationKey = $messageTranslationKey;
37 $result->messageParameters = $messageParameters;
38 return $result;
39 }
40
41 public function getMessageTranslationKey() : string{ return $this->messageTranslationKey; }
42
44 public function getMessageParameters() : array{ return $this->messageParameters; }
45
46 protected function decodePayload(PacketSerializer $in) : void{
47 $this->messageTranslationKey = $in->getString();
48
49 $this->messageParameters = [];
50 for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; $i++){
51 $this->messageParameters[] = $in->getString();
52 }
53 }
54
55 protected function encodePayload(PacketSerializer $out) : void{
56 $out->putString($this->messageTranslationKey);
57
58 $out->putUnsignedVarInt(count($this->messageParameters));
59 foreach($this->messageParameters as $parameter){
60 $out->putString($parameter);
61 }
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handleDeathInfo($this);
66 }
67}
static create(string $messageTranslationKey, array $messageParameters)