PocketMine-MP 5.27.1 git-9af3cde03fabbe4129c79e46dc87ffa0fff446e6
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 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 public function getWorldTemplateId() : UuidInterface{ return $this->worldTemplateId; }
49
50 public function getWorldTemplateVersion() : string{ return $this->worldTemplateVersion; }
51
52 protected function decodePayload(PacketSerializer $in) : void{
53 $this->mustAccept = $in->getBool();
54 $this->hasAddons = $in->getBool();
55 $this->hasScripts = $in->getBool();
56 $this->worldTemplateId = $in->getUUID();
57 $this->worldTemplateVersion = $in->getString();
58
59 $resourcePackCount = $in->getLShort();
60 while($resourcePackCount-- > 0){
61 $this->resourcePackEntries[] = ResourcePackInfoEntry::read($in);
62 }
63 }
64
65 protected function encodePayload(PacketSerializer $out) : void{
66 $out->putBool($this->mustAccept);
67 $out->putBool($this->hasAddons);
68 $out->putBool($this->hasScripts);
69 $out->putUUID($this->worldTemplateId);
70 $out->putString($this->worldTemplateVersion);
71 $out->putLShort(count($this->resourcePackEntries));
72 foreach($this->resourcePackEntries as $entry){
73 $entry->write($out);
74 }
75 }
76
77 public function handle(PacketHandlerInterface $handler) : bool{
78 return $handler->handleResourcePacksInfo($this);
79 }
80}
static create(array $resourcePackEntries, bool $mustAccept, bool $hasAddons, bool $hasScripts, UuidInterface $worldTemplateId, string $worldTemplateVersion)