74 if(!file_exists($this->path)){
75 $logger->
debug(
"Resource packs path $path does not exist, creating directory");
77 }elseif(!is_dir($this->path)){
78 throw new \InvalidArgumentException(
"Resource packs path $path exists and is not a directory");
81 $resourcePacksYml = Path::join($this->path,
"resource_packs.yml");
82 if(!file_exists($resourcePacksYml)){
83 copy(Path::join(\
pocketmine\RESOURCE_PATH,
"resource_packs.yml"), $resourcePacksYml);
86 $resourcePacksConfig =
new Config($resourcePacksYml, Config::YAML, []);
88 $this->serverForceResources = (bool) $resourcePacksConfig->get(
"force_resources",
false);
90 $logger->
info(
"Loading resource packs...");
92 $resourceStack = $resourcePacksConfig->get(
"resource_stack", []);
93 if(!is_array($resourceStack)){
94 throw new \InvalidArgumentException(
"\"resource_stack\" key should contain a list of pack names");
97 foreach(Utils::promoteKeys($resourceStack) as $pos => $pack){
98 if(!is_string($pack) && !is_int($pack) && !is_float($pack)){
99 $logger->
critical(
"Found invalid entry in resource pack list at offset $pos of type " . gettype($pack));
102 $pack = (string) $pack;
104 $newPack = $this->loadPackFromPath(Path::join($this->path, $pack));
106 $this->resourcePacks[] = $newPack;
107 $index = strtolower($newPack->getPackId());
108 $this->uuidList[$index] = $newPack;
110 $keyPath = Path::join($this->path, $pack .
".key");
111 if(file_exists($keyPath)){
113 $key = Filesystem::fileGetContents($keyPath);
114 }
catch(\RuntimeException $e){
117 $key = rtrim($key,
"\r\n");
118 if(strlen($key) !== 32){
121 $this->encryptionKeys[$index] = $key;
124 $logger->
critical(
"Could not load resource pack \"$pack\": " . $e->getMessage());
128 $logger->
debug(
"Successfully loaded " . count($this->resourcePacks) .
" resource packs");
191 foreach($resourceStack as $pack){
192 $uuid = strtolower($pack->getPackId());
193 if(isset($uuidList[$uuid])){
194 throw new \InvalidArgumentException(
"Cannot load two resource pack with the same UUID ($uuid)");
196 $uuidList[$uuid] = $pack;
197 $resourcePacks[] = $pack;
199 $this->resourcePacks = $resourcePacks;
200 $this->uuidList = $uuidList;
230 $id = strtolower($id);
233 unset($this->encryptionKeys[$id]);
234 }elseif(isset($this->uuidList[$id])){
235 if(strlen($key) !== 32){
236 throw new \InvalidArgumentException(
"Encryption key must be exactly 32 bytes long");
238 $this->encryptionKeys[$id] = $key;
240 throw new \InvalidArgumentException(
"Unknown pack ID $id");