From f27c6fcf70eb0cd46a664b642f144ad2399ca287 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 31 May 2018 18:30:21 +0100 Subject: [PATCH] ResourcePack: slightly better handling of bad configs --- .../resourcepacks/ResourcePackManager.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/resourcepacks/ResourcePackManager.php b/src/pocketmine/resourcepacks/ResourcePackManager.php index 0def9ff2bf..55a94b02e1 100644 --- a/src/pocketmine/resourcepacks/ResourcePackManager.php +++ b/src/pocketmine/resourcepacks/ResourcePackManager.php @@ -66,8 +66,20 @@ class ResourcePackManager{ $logger->info("Loading resource packs..."); - foreach($resourcePacksConfig->get("resource_stack", []) as $pos => $pack){ + $resourceStack = $resourcePacksConfig->get("resource_stack", []); + if(!is_array($resourceStack)){ + throw new \InvalidArgumentException("\"resource_stack\" key should contain a list of pack names"); + } + + foreach($resourceStack as $pos => $pack){ try{ + $pack = (string) $pack; + }catch(\ErrorException $e){ + $logger->critical("Found invalid entry in resource pack list at offset $pos of type " . gettype($pack)); + continue; + } + try{ + /** @var string $pack */ $packPath = $this->path . DIRECTORY_SEPARATOR . $pack; if(!file_exists($packPath)){ throw new ResourcePackException("File or directory not found");