Fixed resource packs with comments in manifest

MOJANG, THERE'S NO SUCH THING AS COMMENTS IN STANDARD JSON
This commit is contained in:
Dylan K. Taylor
2018-12-27 15:35:00 +00:00
parent a71af952ba
commit 6417cff618
3 changed files with 55 additions and 5 deletions

View File

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace pocketmine\resourcepacks;
use Ahc\Json\Comment as CommentedJsonDecoder;
class ZippedResourcePack implements ResourcePack{
/**
@ -86,10 +88,13 @@ class ZippedResourcePack implements ResourcePack{
$archive->close();
$manifest = json_decode($manifestData);
if($manifest === null){
throw new ResourcePackException("Failed to parse manifest.json: " . json_last_error_msg());
//maybe comments in the json, use stripped decoder (thanks mojang)
try{
$manifest = (new CommentedJsonDecoder())->decode($manifestData);
}catch(\RuntimeException $e){
throw new ResourcePackException("Failed to parse manifest.json: " . $e->getMessage(), $e->getCode(), $e);
}
if(!self::verifyManifest($manifest)){
throw new ResourcePackException("manifest.json is missing required fields");
}