From 517609dc2e5852299b2e54d05fa9e13e89931b42 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 1 Sep 2017 18:32:37 +0100 Subject: [PATCH] Cleaned up plugin property reading --- src/pocketmine/plugin/PluginDescription.php | 27 +++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/plugin/PluginDescription.php b/src/pocketmine/plugin/PluginDescription.php index 006e01e06..9f63b2156 100644 --- a/src/pocketmine/plugin/PluginDescription.php +++ b/src/pocketmine/plugin/PluginDescription.php @@ -74,11 +74,11 @@ class PluginDescription{ $this->name = str_replace(" ", "_", $this->name); $this->version = (string) $plugin["version"]; $this->main = $plugin["main"]; - $this->api = array_map(function($v){ return (string) $v; }, !is_array($plugin["api"]) ? [$plugin["api"]] : $plugin["api"]); if(stripos($this->main, "pocketmine\\") === 0){ throw new PluginException("Invalid PluginDescription main, cannot start within the PocketMine namespace"); } + $this->api = array_map("strval", (array) $plugin["api"] ?? []); $this->compatibleMcpeProtocols = array_map("intval", (array) ($plugin["mcpe-protocol"] ?? [])); if(isset($plugin["commands"]) and is_array($plugin["commands"])){ @@ -99,22 +99,17 @@ class PluginDescription{ $this->extensions[$k] = is_array($v) ? $v : [$v]; } } - if(isset($plugin["softdepend"])){ - $this->softDepend = (array) $plugin["softdepend"]; - } - if(isset($plugin["loadbefore"])){ - $this->loadBefore = (array) $plugin["loadbefore"]; - } - if(isset($plugin["website"])){ - $this->website = $plugin["website"]; - } - if(isset($plugin["description"])){ - $this->description = $plugin["description"]; - } - if(isset($plugin["prefix"])){ - $this->prefix = $plugin["prefix"]; - } + $this->softDepend = (array) ($plugin["softdepend"] ?? $this->softDepend); + + $this->loadBefore = (array) ($plugin["loadbefore"] ?? $this->loadBefore); + + $this->website = (string) ($plugin["website"] ?? $this->website); + + $this->description = (string) ($plugin["description"] ?? $this->description); + + $this->prefix = (string) ($plugin["prefix"] ?? $this->prefix); + if(isset($plugin["load"])){ $order = strtoupper($plugin["load"]); if(!defined(PluginLoadOrder::class . "::" . $order)){