I'm trying to set value to config , but it's not working (It keep old value) please help me PHP: public function getConfig() : Config{return new Config(Loader::getInstance()->getDataFolder() . "/test/" . $this->getSessionName() . ".json", Config::JSON);} So, getConfig() returns valid config object Then I'm setting value to config PHP: $test->getConfig()->set("all", "$b[3]");$test->getConfig()->save(); Code is 100% executed, but it don't work (I must point to "all" already exists in config before setting) When I go to json file and remove "all" then code works and set "all" :/ Edit: I tried to set normal string like $test->getConfig("set", "test"); and it still don't work
You need to use set in the first call, not save: PHP: $test->getConfig()->set("all", (string) $b[3]);$test->getConfig()->save();
Sorry it was only typo when I was posting code here (I'm going to correct it) , but in my plugin I have $test->getConfig()->set("all", "$b[3]"); instead of save() and problem still happens.
You must do: PHP: $config = $test->getConfig();$config->set("all", $b[3]);$config->save(); With your method it creates the config, changes in the config something without saving the changes. Then he creates again a config and saves the unchanged config.
Oh, now I see the problem. you discard everything you have changed by creating a new cfg object. either save your object in getConfig (for example as a class member/variable or do this: PHP: $cfg = $test->getConfig();$cfg->set("all", (string) $b[3]);$cfg->save(); or change your getConfig function: PHP: public function getConfig() : Config{ if(!isset($this->config) || (!$this->config instance Config)){ $this->config = new Config(Loader::getInstance()->getDataFolder() . "/test/" . $this->getSessionName() . ".json", Config::JSON); } return $this->config;}