hi, I have a problem with my plugin, it created no config.yml file and therefore does not save? how to solve this? source here https://github.com/Praxthisnovcht/CustomChat
Its correct ? PHP: // sets prefix for player if ((strtolower ( $command->getName () ) == "setprefix") && isset ( $args [0] ) && isset ( $args [1] )) { $playerName = $args [0]; $p = $sender->getServer ()->getPlayerExact ( $playerName ); if ($p == null) { $sender->sendMessage ( "player " . $playerName . " is not online!" ); exit (); } $prefix = $args [1]; $this->pgin->getConfig ()->set ( $p->getName ().".prefix", $prefix ); $this->pgin->getConfig ()->save ();
It's logic that it doesn't work! You must get the config file first. Try to add it at the start of onCommand() function PHP: $this->config = $this->plugin->getConfig()->getAll();
However you made a lot of errors in your code. First of all, don't use the construct variable ($this->pgin) to get the config. Simply declare a new variable.
For start, init this PHP: $this->pgin = new Config($this->getDataFolder()."config.yml", Config::YAML);
This isn't needed; his config is in $this->pgin->getConfig() and PocketMine PluginBase class will do everything for him! How many times do I need to tell you? If you can't understand my language, fine, go to https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/plugin/PluginBase.php and read the code yourself $this->pgin is his PluginBase object not a config file apparently.
PHP: @mkdir($this->getDataFolder()); //Create plugin folder$this->config = new Config($this->getDataFolder() . "Config.yml", Config::YAML, array());
Just do $this->saveDefaultConfig() and PocketMine will do all these for you. And <? echo strtolower("DO NOT DEFINE \$this->config YOURSELF") ?>.
Then why save it as a field... Just keep using $this->getConfig()! Maybe this is better in some ways though because getConfig() checks if the config exists every time, but there isn't really much lagginess.
But that's very minimum time use. Any other useless line you write spends more time than the difference here. The only difference is an extra isset() call (or !== null check; I forgot).