68 if(!file_exists($this->path)){
69 $logger->
debug(
"Resource packs path $path does not exist, creating directory");
71 }elseif(!is_dir($this->path)){
72 throw new \InvalidArgumentException(
"Resource packs path $path exists and is not a directory");
75 $resourcePacksYml = Path::join($this->path,
"resource_packs.yml");
76 if(!file_exists($resourcePacksYml)){
77 copy(Path::join(\
pocketmine\RESOURCE_PATH,
"resource_packs.yml"), $resourcePacksYml);
80 $resourcePacksConfig =
new Config($resourcePacksYml, Config::YAML, []);
82 $this->serverForceResources = (bool) $resourcePacksConfig->get(
"force_resources",
false);
84 $logger->
info(
"Loading resource packs...");
86 $resourceStack = $resourcePacksConfig->get(
"resource_stack", []);
87 if(!is_array($resourceStack)){
88 throw new \InvalidArgumentException(
"\"resource_stack\" key should contain a list of pack names");
91 foreach(Utils::promoteKeys($resourceStack) as $pos => $pack){
92 if(!is_string($pack) && !is_int($pack) && !is_float($pack)){
93 $logger->
critical(
"Found invalid entry in resource pack list at offset $pos of type " . gettype($pack));
96 $pack = (string) $pack;
98 $newPack = $this->loadPackFromPath(Path::join($this->path, $pack));
100 $this->resourcePacks[] = $newPack;
101 $index = strtolower($newPack->getPackId());
102 $this->uuidList[$index] = $newPack;
104 $keyPath = Path::join($this->path, $pack .
".key");
105 if(file_exists($keyPath)){
107 $key = Filesystem::fileGetContents($keyPath);
108 }
catch(\RuntimeException $e){
111 $key = rtrim($key,
"\r\n");
112 if(strlen($key) !== 32){
115 $this->encryptionKeys[$index] = $key;
118 $logger->
critical(
"Could not load resource pack \"$pack\": " . $e->getMessage());
122 $logger->
debug(
"Successfully loaded " . count($this->resourcePacks) .
" resource packs");
184 foreach($resourceStack as $pack){
185 $uuid = strtolower($pack->getPackId());
186 if(isset($uuidList[$uuid])){
187 throw new \InvalidArgumentException(
"Cannot load two resource pack with the same UUID ($uuid)");
189 $uuidList[$uuid] = $pack;
190 $resourcePacks[] = $pack;
192 $this->resourcePacks = $resourcePacks;
193 $this->uuidList = $uuidList;
223 $id = strtolower($id);
226 unset($this->encryptionKeys[$id]);
227 }elseif(isset($this->uuidList[$id])){
228 if(strlen($key) !== 32){
229 throw new \InvalidArgumentException(
"Encryption key must be exactly 32 bytes long");
231 $this->encryptionKeys[$id] = $key;
233 throw new \InvalidArgumentException(
"Unknown pack ID $id");