diff --git a/src/pocketmine/resourcepacks/ResourcePackException.php b/src/pocketmine/resourcepacks/ResourcePackException.php new file mode 100644 index 0000000000..b5f43ecf39 --- /dev/null +++ b/src/pocketmine/resourcepacks/ResourcePackException.php @@ -0,0 +1,28 @@ +get("resource_stack", []) as $pos => $pack){ try{ $packPath = $this->path . DIRECTORY_SEPARATOR . $pack; - if(file_exists($packPath)){ - $newPack = null; - //Detect the type of resource pack. - if(is_dir($packPath)){ - $logger->warning("Skipped resource entry $pack due to directory resource packs currently unsupported"); - }else{ - $info = new \SplFileInfo($packPath); - switch($info->getExtension()){ - case "zip": - case "mcpack": - $newPack = new ZippedResourcePack($packPath); - break; - default: - $logger->warning("Skipped resource entry $pack due to format not recognized"); - break; - } - } - - if($newPack instanceof ResourcePack){ - $this->resourcePacks[] = $newPack; - $this->uuidList[strtolower($newPack->getPackId())] = $newPack; - } - }else{ - $logger->warning("Skipped resource entry $pack due to file or directory not found"); + if(!file_exists($packPath)){ + throw new ResourcePackException("File or directory not found"); } - }catch(\Throwable $e){ - $logger->logException($e); + if(is_dir($packPath)){ + throw new ResourcePackException("Directory resource packs are unsupported"); + } + + $newPack = null; + //Detect the type of resource pack. + $info = new \SplFileInfo($packPath); + switch($info->getExtension()){ + case "zip": + case "mcpack": + $newPack = new ZippedResourcePack($packPath); + break; + } + + if($newPack instanceof ResourcePack){ + $this->resourcePacks[] = $newPack; + $this->uuidList[strtolower($newPack->getPackId())] = $newPack; + }else{ + throw new ResourcePackException("Format not recognized"); + } + }catch(ResourcePackException $e){ + $logger->critical("Could not load resource pack \"$pack\": " . $e->getMessage()); } } diff --git a/src/pocketmine/resourcepacks/ZippedResourcePack.php b/src/pocketmine/resourcepacks/ZippedResourcePack.php index 30c184d564..40ef7cc237 100644 --- a/src/pocketmine/resourcepacks/ZippedResourcePack.php +++ b/src/pocketmine/resourcepacks/ZippedResourcePack.php @@ -67,19 +67,19 @@ class ZippedResourcePack implements ResourcePack{ $this->path = $zipPath; if(!file_exists($zipPath)){ - throw new \InvalidArgumentException("Could not open resource pack $zipPath: file not found"); + throw new ResourcePackException("File not found"); } $archive = new \ZipArchive(); if(($openResult = $archive->open($zipPath)) !== true){ - throw new \InvalidStateException("Encountered ZipArchive error code $openResult while trying to open $zipPath"); + throw new ResourcePackException("Encountered ZipArchive error code $openResult while trying to open $zipPath"); } if(($manifestData = $archive->getFromName("manifest.json")) === false){ if($archive->locateName("pack_manifest.json") !== false){ - throw new \InvalidStateException("Could not load resource pack from $zipPath: unsupported old pack format"); + throw new ResourcePackException("Unsupported old pack format"); }else{ - throw new \InvalidStateException("Could not load resource pack from $zipPath: manifest.json not found in the archive root"); + throw new ResourcePackException("manifest.json not found in the archive root"); } } @@ -87,7 +87,7 @@ class ZippedResourcePack implements ResourcePack{ $manifest = json_decode($manifestData); if($manifest === null or !self::verifyManifest($manifest)){ - throw new \InvalidStateException("Could not load resource pack from $zipPath: manifest.json is invalid or incomplete"); + throw new ResourcePackException("manifest.json is invalid or incomplete"); } $this->manifest = $manifest;