So, I have been experimenting with different ways to save data to my config file every time my plugin is disabled. So far, I have found nothing that works easily, consistently, or in the way I was expecting. So, I'm asking if a plugin developer here has a clear concise way to write to a config file. Also, If you could take a look at my plugin here: https://github.com/LostTeam/SpawnInvis I would be grateful of your help.
As a matter of fact, config means configuration, which means options, which means to let the user edit options like server.properties and pocketmine.yml. Why do you love using config.yml to save data so much? Anyway, in your code: saveDefaultConfig() already does the job of saveResource("config.yml", false). You don't need to do it twice. Run saveDefaultConfig before getConfig(), because before that, the config file may not have been initialized yet. https://github.com/LostTeam/SpawnInvis/blob/master/src/SpawnInvis/Main.php#L85 You do not seem to be doing anything here at all? All you did is to branch the processor without actually doing anything.
In the disable function, I had a bit of code that was supposed to save the last setting to the config. I removed it and let there be return statements instead because it didn't work. I want to replace those with a working method of saving to the config file.
My Methode is to usw config.yml : PHP: Public $Text1;Public function onEnable(){$this->getLogger()->info("was activated");@mkdir($this->getDataFolder() . "config.yml);If (empty->get("Text1"){$config->set("Text1" , "Text1");}$this->Text1 = $config->get("Text1");}Public Function onCommand (CommandSender $sender , Command $cmd, $label, array $args){Switch(strtolower($event->getName()){case "info" :$sender->sendMessage($this->Text1);Return true;} I hope i helped you .They are maybe any mistakes because i tipped on my mobile phone with german auto-correction xD.
xD i mean PHP: if( empty($config->get("Text1"))){$config->set("Text1" , "Text1);} As i wrote it i was very tired and didn't think about it .
I'm a jerk xD. I forgot many things wait : Before: PHP: @mkdir($this->getDataFolder() . "config.yml"); After x PHP: @mkdir($this->getDataFolder());$config = new Config ($this->getDataFolder() . "config.yml" , Config::YAML);