Loading [MathJax]/extensions/MathMenu.js
PocketMine-MP 5.23.3 git-4a4572131f27ab967701ceaaf2020cfbe26e375c
All Classes Namespaces Functions Variables Enumerations Enumerator Pages
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 Ramsey\Uuid\UuidInterface;
20use function count;
21
23 public const NETWORK_ID = ProtocolInfo::RESOURCE_PACKS_INFO_PACKET;
24
26 public array $resourcePackEntries = [];
27 public bool $mustAccept = false; //if true, forces client to choose between accepting packs or being disconnected
28 public bool $hasAddons = false;
29 public bool $hasScripts = false; //if true, causes disconnect for any platform that doesn't support scripts yet
30 private UuidInterface $worldTemplateId;
31 private string $worldTemplateVersion;
32
37 public static function create(array $resourcePackEntries, bool $mustAccept, bool $hasAddons, bool $hasScripts, UuidInterface $worldTemplateId, string $worldTemplateVersion) : self{
38 $result = new self;
39 $result->resourcePackEntries = $resourcePackEntries;
40 $result->mustAccept = $mustAccept;
41 $result->hasAddons = $hasAddons;
42 $result->hasScripts = $hasScripts;
43 $result->worldTemplateId = $worldTemplateId;
44 $result->worldTemplateVersion = $worldTemplateVersion;
45 return $result;
46 }
47
48 protected function decodePayload(PacketSerializer $in) : void{
49 $this->mustAccept = $in->getBool();
50 $this->hasAddons = $in->getBool();
51 $this->hasScripts = $in->getBool();
52 $this->worldTemplateId = $in->getUUID();
53 $this->worldTemplateVersion = $in->getString();
54
55 $resourcePackCount = $in->getLShort();
56 while($resourcePackCount-- > 0){
57 $this->resourcePackEntries[] = ResourcePackInfoEntry::read($in);
58 }
59 }
60
61 protected function encodePayload(PacketSerializer $out) : void{
62 $out->putBool($this->mustAccept);
63 $out->putBool($this->hasAddons);
64 $out->putBool($this->hasScripts);
65 $out->putUUID($this->worldTemplateId);
66 $out->putString($this->worldTemplateVersion);
67 $out->putLShort(count($this->resourcePackEntries));
68 foreach($this->resourcePackEntries as $entry){
69 $entry->write($out);
70 }
71 }
72
73 public function handle(PacketHandlerInterface $handler) : bool{
74 return $handler->handleResourcePacksInfo($this);
75 }
76}
static create(array $resourcePackEntries, bool $mustAccept, bool $hasAddons, bool $hasScripts, UuidInterface $worldTemplateId, string $worldTemplateVersion)