I have this: PHP: class Main extends PluginBase implements Listener { public function onEnable(){ $this->config = (new Config($this->getDataFolder()."config.yml", Config::YAML))->getAll(); // Load config in array $this->players = (new Config($this->getDataFolder()."players.yml", Config::YAML))->getAll(); // Load config in array} the files are in my source plugin, the structure of the plugin is: OITCPE .--resources . .|--config.yml . .|--players.yml .--src . .|--thebigsmileXD . . .|--OITCPE . . . .|--Main.php . . . .|--MakeSound.php .--plugin.yml But i get this error: and i still wonder why. Do i have to put them somewhere else or what?
If you want to load as array, like this: PHP: public function onEnable(){ $this->players = new Config($this->getDataFolder()."players.yml", Config::YAML, array());} To access it as array, PHP: public function blahblah(){ $tmp = $this->players->getAll();}
btw, $this->config is a bad practice, use $this->saveDefaultConfig() instead and you can still access it as array
Why don't you just edit your post? xD also.. doesn't saveDefaultConfig only save, and not get the data? i want to get the data
after saveDefaultConfig, if you want to access the config with array use PHP: $this->getConfig()->getAll();
Still, i get the same Error My code: PHP: class Main extends PluginBase implements Listener { public function onEnable(){ $this->getPlayerConfig(); } public function onDisable(){ //$this->updateConfig(); } public function getPlayerConfig(){ //$this->players = new Config($this->getDataFolder()."players.yml", Config::YAML, array()); // Load config in array $this->saveDefaultConfig(); // Load config in array $this->players=$this->getConfig(); }}
Seems like me, as stupid as i am, forgot to write Into the configs. They get loaded now, and they are in the first OITCPE folder. Thanks for helping.
That error means it can't find the file or something in the file that you specified, in this case you haven't actually got it to save the config. Try this: PHP: class Main extends PluginBase implements Listener { public function onEnable() { $this->saveResource($this->getDataFolder . "config.yml"); //You need to save the file so it actually exists!!! $this->saveResource($this->getDataFolder . "players.yml"); //You need to save the file so it actually exists!!! $this->config = (new Config($this->getDataFolder()."config.yml", Config::YAML))->getAll(); $this->players = (new Config($this->getDataFolder()."players.yml", Config::YAML))->getAll();}
I feel so stupid ;( i just thought i understand.. but no, i dont: PHP: public function getPlayerConfig(){ //$this->players->getAll() = new Config($this->getDataFolder()."players.yml", Config::YAML, array()); // Load config in array @mkdir($this->getDataFolder()); //$this->saveDefaultConfig(); // Load config in array $this->players = new Config($this->getDataFolder()."players.yml", Config::YAML, array());; } The array seems to get filled. But i cant write it to the config.. i thought about PHP: $this->players->save(); but it doesnt seem to save the players set in the array to the file.. This seems to work fine. How do i save the new data to the yml?
If you just want a variable to access the config try this: PHP: $this->config = (new Config($this->plugin->getDataFolder() . "config.yml", Config::YAML))->getAll(); Putting the array() into your variable sets the config to an empty array (to my understanding).
Well, maybe i should explain more in deep what i want to do. I make a plugin, and when you do , i want to check if the player already exists in the config, if not, then set deaths=0, kills=0 and playing to true. after a round playing i want to write the kills and deaths into the config. (or on )