I am trying to make a messages.yml where people can edit the message PHP: <?phpnamespace Kaz;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\Player;use pocketmine\Server;use pocketmine\utils\TextFormat as O;use pocketmine\utils\Config;class Main extends PluginBase implements Listener{ public function onEnable(){ @mkdir($this->getDataFolder()); $this->saveResource("config.yml"); $this->config= new Config($this->getDataFolder() . "config.yml",Config::YAML); $this->getServer()->getPluginManager()->registerEvents($this, $this);} public function onJoin(PlayerJoinEvent $event){ $player = $event->getPlayer(); $name = $event->getPlayer()->getName(); $player->sendMessage($this->getConfig()->get("join-message")); }} I made a resources folder with config.yml which looks like this PHP: join-message: test they didn't work.. sorry I'm new to making configs..
try this PHP: <?phpnamespace Kaz;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\Player;use pocketmine\Server;use pocketmine\utils\TextFormat as O;use pocketmine\utils\Config;class Main extends PluginBase implements Listener{ public function onEnable(){ $this->saveDefaultConfig(); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onJoin(PlayerJoinEvent $event){ $player = $event->getPlayer(); $name = $event->getPlayer()->getName(); $player->sendMessage($this->getConfig()->get("join-message")); }} and for your config PHP: join-message: "message"
You can load a config in 2 ways. One by calling it under a Config class onEnable() and another one is $this->saveDefaultConfig() ; which you pre-make a config and then you call it. After having a look at your config which you made earlier. Code: join-message: "" That's "" means it is a string, if it's not placed nothing will work and you'll have errors. It's a good practice to add a "" on strings.
error Code: [01:25:08] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'Kaz v1.0.0': yaml_parse(): end of stream reached without finding document 0 on Kaz\Main [01:25:08] [Server thread/CRITICAL]: ErrorException: "yaml_parse(): end of stream reached without finding document 0" (EXCEPTION) in "/src/pocketmine/utils/Config" at line 145
If I'm not mistaken, it should be onEnable() PHP: $this->saveResource("messages.yml"); And then call it back. Refer here: (another method) https://github.com/InspectorGadget/RightSideHUD/blob/master/src/RTG/RightSideHUD/Loader.php#L48
The saveDefaultConfig() is simply an alias of saveResource("config.yml"). The getConfig() method will do multiple things: 1. If the config is already loaded, return the config 2. If the config is not loaded yet, try to create a config file at config.yml using new Config() 3. Parse config.yml from resources folder of plugin. If there is a property that exists in the resources one but not in the user-editable one, fill it with the default value from the resources one. On the other hand, "" is not only a good practice but also a should. If you put nothing there, it would become a null rather than an empty string, which might lead to strict type errors. The plugin should be responsible for casting it to string.
use: @mkdir($this->getDataFolder()); $this->saveDefaultConfig(); $this->getResource("config.yml"); and when uses the config yml message: $player->sendMessage($this->getConfig()->get("join-message"));