PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
21use function count;
22
27 public const NETWORK_ID = ProtocolInfo::DEATH_INFO_PACKET;
28
29 private string $messageTranslationKey;
31 private array $messageParameters;
32
37 public static function create(string $messageTranslationKey, array $messageParameters) : self{
38 $result = new self;
39 $result->messageTranslationKey = $messageTranslationKey;
40 $result->messageParameters = $messageParameters;
41 return $result;
42 }
43
44 public function getMessageTranslationKey() : string{ return $this->messageTranslationKey; }
45
47 public function getMessageParameters() : array{ return $this->messageParameters; }
48
49 protected function decodePayload(ByteBufferReader $in) : void{
50 $this->messageTranslationKey = CommonTypes::getString($in);
51
52 $this->messageParameters = [];
53 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; $i++){
54 $this->messageParameters[] = CommonTypes::getString($in);
55 }
56 }
57
58 protected function encodePayload(ByteBufferWriter $out) : void{
59 CommonTypes::putString($out, $this->messageTranslationKey);
60
61 VarInt::writeUnsignedInt($out, count($this->messageParameters));
62 foreach($this->messageParameters as $parameter){
63 CommonTypes::putString($out, $parameter);
64 }
65 }
66
67 public function handle(PacketHandlerInterface $handler) : bool{
68 return $handler->handleDeathInfo($this);
69 }
70}
static create(string $messageTranslationKey, array $messageParameters)