Code: public function onJoin(PlayerJoinEvent $e){ $el = $e->getPlayer()->getName(); $this->conf["Players"][] = "$el"; $this->conf->setAll($this->con); $this->conf->save(); } it says Code: "Cannot use object of type pocketmine\utils\Config as array" I just want to make if player join server, save join player's name in conf.yml
PHP: public function onJoin(PlayerJoinEvent $e){ $el = $e->getPlayer()->getName(); $players = $this->conf->get("Players"); if (!in_array($el, $players)) { $players[] = $el; $this->conf->set("Players", $players); $this->conf->save(); }}
You didn't set "Players" on config. PHP: public function onJoin(PlayerJoinEvent $e){ $el = $e->getPlayer()->getName(); $players = $this->conf->get("Players"); if (!$players) { $this->conf->set("Players", []); $this->conf->save(); } if (!in_array($el, $players)) { $players[] = $el; $this->conf->set("Players", $players); $this->conf->save(); }}
I added Code: @mkdir ($this->getDataFolder()); $this->conf = new Config ($this->getDataFolder()."conf.yml",Config::YAML,[ "Players" ]); $this->con = $this->conf->getAll(); but still same
PHP: public function onJoin(PlayerJoinEvent $e){ $el = $e->getPlayer()->getName(); $c = $this->conf->getAll(); $c["Players"][] = "$el"; $this->conf->setAll($c); $this->conf->setAll($this->con); // this will overrid your attempt to save player's name... ??? $this->conf->save();}