From 1d5c741f28f4e706b168300d5daebb8c34d8a050 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 12 Jul 2018 19:25:48 +0100 Subject: [PATCH] PluginBase: Automatically save default config if it doesn't exist (#2285) I wasn't sure whether this would be considered a bug fix or a feature. Nonetheless, it's a behavioural change, so it belongs in 3.1 if anywhere. Prior to this, plugins would be required to call saveDefaultConfig() before calling getConfig() or anything else. Calling getConfig() without saveDefaultConfig() first would generate an empty configuration file. Instead, it now saves the default config before loading it. --- src/pocketmine/plugin/PluginBase.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/plugin/PluginBase.php b/src/pocketmine/plugin/PluginBase.php index bba7231e9..e28f75a49 100644 --- a/src/pocketmine/plugin/PluginBase.php +++ b/src/pocketmine/plugin/PluginBase.php @@ -256,7 +256,9 @@ abstract class PluginBase implements Plugin{ } public function reloadConfig(){ - @mkdir($this->dataFolder); + if(!$this->saveDefaultConfig()){ + @mkdir($this->dataFolder); + } $this->config = new Config($this->configFile); if(($configStream = $this->getResource("config.yml")) !== null){ $this->config->setDefaults(yaml_parse(Config::fixYAMLIndexes(stream_get_contents($configStream))));