PHP: public function setUpMessages(Player $p, $test){ $cfg = new Config($this->getDataFolder() . "/playerdata/" . $p->getName() . ".json", Config::JSON); switch($lang){ case "test"; $cfg->set("rgergeefe", "jnefjefj"); $cfg->save(); $this->getLogger()->info("Ok"); }public function onJoin(PJE $e){ $cfg = new Config($this->getDataFolder() . "/playerdata/" . $p->getName() . ".json", Config::JSON);$p = $e->getPlayer();$this->setUpMessages($p, "test");}} Console write Ok,but dont set to config
I have PHP: case "test"; $cfg->set("rgergeefe", "jnefjefj"); $cfg->save(); //<---- $this->getLogger()->info("Ok");
I think you have forgot “$cfg->get();“ PHP: case "test"; $cfg->get("rgergeefe"); $cfg->set("rgergeefe", "jnefjefj"); $cfg->save(); //<---- $this->getLogger()->info("Ok");
Not sure if that's the cause, but you're using switch() on an undefined variable? That's nonsense. You use $configuration->get() to get the value of something in the config. Not to... initialize it or something.
Ok switch now using on defined variable, but not add PHP: public function setUpMessages(Player $p, $test){ $cfg = new Config($this->getDataFolder() . "/playerdata/" . $p->getName() . ".json", Config::JSON); switch($test){ case "test"; $cfg->set("rgergeefe", "jnefjefj"); $cfg->save(); $this->getLogger()->info("Ok"); }
Because it returns null, or an empty string perhaps. It doesn't do anything, it returns a value from the configuration. If it doesn't find it, it returns something empty.
I tried without switch and always not work too. PHP: public function setUpMessages(Player $p, $test){ $cfg = new Config($this->getDataFolder() . "/playerdata/" . $p->getName() . ".json", Config::JSON); $cfg->set("rgergeefe", "jnefjefj"); $cfg->save(); $this->getLogger()->info("Ok"); }
Could I just ask if you perhaps forgot to make the folders this config file should be in? Also, the first / before playerdata should be removed.
I must use PlayerLoginEvent? EDIT: I used PlayerLoginEvent and it working.. If there is not some way to use it in playerjoinevent i use this.