Hello, so before getting to this point I actually looked threads and threads and went on google without being able to understand what I've done wrong here.. Could anyone help me? Basically Im trying that when a player join it sets in the keys.yml that they have 0 keys etc under their name althought I always get this specific error: Error: "Call to a member function set() on array" (EXCEPTION) in "~~~" at line 28 PHP: /** @var Config */ public $config; public function onEnable() { $this->config = new Config($this->getDataFolder() . "keys.yml", Config::YAML, []); $this->config = $this->getConfig()->getAll(); $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getLogger()->info("Keys are working properly"); } public function onJoin(PlayerJoinEvent $event){ $name = $event->getPlayer()->getName(); $common["Common Keys"] = 0; $common["Uncommon Keys"] = 0; $common["Rare Keys"] = 0; $common["Legendary Keys"] = 0;//Line 28 $this->config->set($name, $common); If I find my mistake I'll edit my post and let you guys know
In that line you are overwriting your config property of the Config type with an array and an array doesn't have the set method that you're trying to use here: So just remove the "$this->config = $this->getConfig()->getAll();" line and if you need the config as an array then use a different variable for that.
Will try, While searching though I found this thread: https://forums.pmmp.io/threads/arrays-in-config-yaml.1513/ which actually worked and makes it simplier. Basically just use yaml_parse_file. For example: PHP: $name = $event->getPlayer()->getName(); $path = $this->getDataFolder()."keys.yml"; $toArray = yaml_parse_file($path); $toArray["$name"] = ["Common" => 0, "Uncommon" => 0, "Rare" => 0,"Legendary" => 0]; yaml_emit_file($path, $toArray);