PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
ResourcePackClientResponsePacket.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
21 public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CLIENT_RESPONSE_PACKET;
22
23 public const STATUS_REFUSED = 1;
24 public const STATUS_SEND_PACKS = 2;
25 public const STATUS_HAVE_ALL_PACKS = 3;
26 public const STATUS_COMPLETED = 4;
27
28 public int $status;
30 public array $packIds = [];
31
36 public static function create(int $status, array $packIds) : self{
37 $result = new self;
38 $result->status = $status;
39 $result->packIds = $packIds;
40 return $result;
41 }
42
43 protected function decodePayload(PacketSerializer $in) : void{
44 $this->status = $in->getByte();
45 $entryCount = $in->getLShort();
46 $this->packIds = [];
47 while($entryCount-- > 0){
48 $this->packIds[] = $in->getString();
49 }
50 }
51
52 protected function encodePayload(PacketSerializer $out) : void{
53 $out->putByte($this->status);
54 $out->putLShort(count($this->packIds));
55 foreach($this->packIds as $id){
56 $out->putString($id);
57 }
58 }
59
60 public function handle(PacketHandlerInterface $handler) : bool{
61 return $handler->handleResourcePackClientResponse($this);
62 }
63}