75 if(!file_exists($this->path)){
76 $logger->
debug(
"Resource packs path $path does not exist, creating directory");
78 }elseif(!is_dir($this->path)){
79 throw new \InvalidArgumentException(
"Resource packs path $path exists and is not a directory");
82 $resourcePacksYml = Path::join($this->path,
"resource_packs.yml");
83 if(!file_exists($resourcePacksYml)){
84 copy(Path::join(\
pocketmine\RESOURCE_PATH,
"resource_packs.yml"), $resourcePacksYml);
87 $resourcePacksConfig =
new Config($resourcePacksYml, Config::YAML, []);
89 $this->serverForceResources = (bool) $resourcePacksConfig->get(
"force_resources",
false);
91 $logger->
info(
"Loading resource packs...");
93 $resourceStack = $resourcePacksConfig->get(
"resource_stack", []);
94 if(!is_array($resourceStack)){
95 throw new \InvalidArgumentException(
"\"resource_stack\" key should contain a list of pack names");
98 foreach(Utils::promoteKeys($resourceStack) as $pos => $pack){
99 if(!is_string($pack) && !is_int($pack) && !is_float($pack)){
100 $logger->
critical(
"Found invalid entry in resource pack list at offset $pos of type " . gettype($pack));
103 $pack = (string) $pack;
105 $newPack = $this->loadPackFromPath(Path::join($this->path, $pack));
107 $printableId = $newPack->getPackId()->toString();
108 $this->uuidList[$printableId] = $newPack;
109 $this->resourcePacks[] = $newPack;
111 $keyPath = Path::join($this->path, $pack .
".key");
112 if(file_exists($keyPath)){
114 $key = Filesystem::fileGetContents($keyPath);
115 }
catch(\RuntimeException $e){
118 $key = rtrim($key,
"\r\n");
119 if(strlen($key) !== 32){
122 $this->encryptionKeys[$printableId] = $key;
125 $logger->
critical(
"Could not load resource pack \"$pack\": " . $e->getMessage());
129 $logger->
debug(
"Successfully loaded " . count($this->resourcePacks) .
" resource packs");
192 foreach($resourceStack as $pack){
193 $printableId = $pack->getPackId()->toString();
194 if(isset($uuidList[$printableId])){
195 throw new \InvalidArgumentException(
"Cannot load two resource pack with the same UUID ($printableId)");
197 $uuidList[$printableId] = $pack;
198 $resourcePacks[] = $pack;
200 $this->resourcePacks = $resourcePacks;
201 $this->uuidList = $uuidList;
231 $printableId = $id->toString();
234 unset($this->encryptionKeys[$printableId]);
235 }elseif(isset($this->uuidList[$printableId])){
236 if(strlen($key) !== 32){
237 throw new \InvalidArgumentException(
"Encryption key must be exactly 32 bytes long");
239 $this->encryptionKeys[$printableId] = $key;
241 throw new \InvalidArgumentException(
"Unknown pack ID $printableId");