After adding 3 worlds (with onRM commented out) the config.yml would look like this: Code: --- worlds: - world: blocks: "1" - world2: blocks: "1" - world3: blocks: "1" ... Which looks like this when you var_dump: Code: array(3) { [0]=> array(1) { ["world"]=> array(1) { ["blocks"]=> string(1) "1" } } [1]=> array(1) { ["world2"]=> array(1) { ["blocks"]=> string(1) "1" } } [2]=> array(1) { ["world3"]=> array(1) { ["blocks"]=> string(1) "1" } } } After running onRM on "world2" the config looks like this: Code: --- worlds: 1: world2: blocks: "1" 2: world3: blocks: "1" ... Why? Since array_search is searching the array for a value and returning the corresponding key, if $name in onRM is "world2" then it will always return false (because the value of each element is an array not a string), and then remove the element at index 0 I don't know what is planned here, but it seems unnecessary to use nested arrays. You could use a separate worlds.yml for this data and simplify things by removing the nesting. If you must, then I think you'll need to do something like this: Code: public function onRM($name) { $array = $this->config->get("worlds"); foreach($array as $key => $value) { if (isset($value[$name])) unset($array[$key]); } $this->config->set("worlds", $array); $this->config->save(); }
@InspectorGadget Use Config::getAll() and set that to a global var 'array' (accessed by $this->array) to check if something exists use isset($this->array[$myVar]); to remove something use unset($this->array[$myVar]); then when PluginBase::/onDisable() is called unlink the previous config file @unlink($pathToConfig); then do (new Config($pathToConfig, Config::YAML, $this->array)->save(); now you can remove objects or keys with ease and you dont have to check a file everytime.
Here is base code: PHP: public function onEnable(){ $this->array = (new Config($this->getDataFolder() . "/config.yml", Config::YAML))->getAll();}public function onDisable(){ @unlink($this->getDataFolder() . "/config.yml"); (new Config($this->getDataFolder() . "/config.yml", Config::YAML, $this->array))->save();}public function removeWorld($name){ unset($this->array[$name]);}public function removeBlock($world, $blockId){ unset($this->array[$world][$blockId]);}
Yours seem to be easy Awzaw. That said, i'll also give a try to what ImagicalGamer suggested for the sake of learning... Thanks @ImagicalGamer and @Awzaw