Hi! How do i create an array into my config and how do i call it? Sorry, i don't have any code as i wan't to learn this. Example: Code: InspectorGadget: IP: 0.0.0.0 RTG: IP: 0.0.0.1 The list should not be overwritten and it needs to go continously... I've tried PHP: array_push() but yet to find a better solution.. Thanks
Use yaml_parse_file to convert the config to a PHP array, use yaml_emit_file to save an array into a file in YAML-recognizable format. PHP: $path = $this->getDataFolder()."config.yml";$toArray = yaml_parse_file($path);$toArray["Anonymous"] = ["IP" => "127.0.0.1"];yaml_emit_file($path, $toArray);
Thanks but your code works for individual YAML addition? What I mean is it has to be like a format for an example something like "Groups.php" on PurePerms. Whenever someone does /addgroup it automatically sets the correct format and it doesn't overwrite any... I tried looking into PurePerms's SRC but i couldn't understand.
Because SOF3 says not to. And I am on his side. PocketMine's Config::set() and Config::get() are crap. Just use yaml_parse/yaml_emit, json_encode/json_decode or file_get_contents/file_put_contents. I know it's a pain to parse and emit it, but I don't think there's a direct one-step command way of doing it. So, in my example, I copy everything in the YAML file into an array $toArray. Then I add key "Anonymous" to the array, then save the modified array using yaml_emit
I never said exactly so. Facts here again, try to induce this mess into your own knowledge: (new Config($path))->getAll() is pointless if you aren't initializing any data there. Use yaml_parse_file() instead of using the complex calls in it. Config class simply serves convenience methods to manipulate the array that backs the data of the config. Therefore all Config operations can be replaced by array manipulation. But this doesn't mean that the Config class is completely useless. It is not a criminal offence to use a Config class. But you will make a fool of yourself if you replace a simple call on yaml_parse_file() with the complexities of a Config class.