PocketMine-MP 5.21.2 git-09bf203267aca9b83a09640e17bfac0fc7b58ff8
Loading...
Searching...
No Matches
ResourcePacksInfoPacket.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
19use function count;
20
22 public const NETWORK_ID = ProtocolInfo::RESOURCE_PACKS_INFO_PACKET;
23
25 public array $resourcePackEntries = [];
26 public bool $mustAccept = false; //if true, forces client to choose between accepting packs or being disconnected
27 public bool $hasAddons = false;
28 public bool $hasScripts = false; //if true, causes disconnect for any platform that doesn't support scripts yet
29
34 public static function create(array $resourcePackEntries, bool $mustAccept, bool $hasAddons, bool $hasScripts) : self{
35 $result = new self;
36 $result->resourcePackEntries = $resourcePackEntries;
37 $result->mustAccept = $mustAccept;
38 $result->hasAddons = $hasAddons;
39 $result->hasScripts = $hasScripts;
40 return $result;
41 }
42
43 protected function decodePayload(PacketSerializer $in) : void{
44 $this->mustAccept = $in->getBool();
45 $this->hasAddons = $in->getBool();
46 $this->hasScripts = $in->getBool();
47
48 $resourcePackCount = $in->getLShort();
49 while($resourcePackCount-- > 0){
50 $this->resourcePackEntries[] = ResourcePackInfoEntry::read($in);
51 }
52 }
53
54 protected function encodePayload(PacketSerializer $out) : void{
55 $out->putBool($this->mustAccept);
56 $out->putBool($this->hasAddons);
57 $out->putBool($this->hasScripts);
58 $out->putLShort(count($this->resourcePackEntries));
59 foreach($this->resourcePackEntries as $entry){
60 $entry->write($out);
61 }
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handleResourcePacksInfo($this);
66 }
67}
static create(array $resourcePackEntries, bool $mustAccept, bool $hasAddons, bool $hasScripts)