Hey the title says it all. I want to create a Config.yml with a array calls $badwords but i don't know how to do it :/.So do you can help me please ??I made the big part of it but it didn't work :/ <?php namespace Withertube ; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\event\player\PlayerChatEvent; use pocketmine\utils\TextFormat as Color; class ChatSafe extends PluginBase implements Listener { public $badwords = array(); public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getLogger()->info("wurde aktiviert"); @mkdir($this->getDataFolder()); @mkdir($this->getDataFolder() . "/Badwords"); $this->cfg = $this->getConfig(); $this->saveDefaultConfig(); } public function onChat(PlayerChatEvent $event) { $this->badwords = new Config($this->getDataFolder() . "/Badwords/" . ".yml" , Config::YAML); $msg = $event->getMessage(); $badwords = $this->cfg->get("badwords"); $neuersatz = str_ireplace($badwords,"****",$msg); $event->setMessage($neuersatz); } public function onDisable(){ $this->getLogger()->info("wurde deaktiviert"); } }
PHP: $config = new Config($this->getDataFolder() . "config.yml", Config::YAML); You should check set function. PHP: $content = array();$config->set("ArrayExample",$content); And please, use PHP tags. Code: [PHP] your code [/PHP]
PHP: $this->badwords = new Config($this->getDataFolder() . "/Badwords/" . ".yml" , Config::YAML); How should a file only called ".yml" exist?
PHP: $this->badwords = new Config($this->getDataFolder() . "Badwords/" . "badwords.yml" , Config::YAML, array( "Badwords" => [ "poop", "eggs", "bunny", "shoe"],));
I made it so but it doesn't wont to work and output this error Message [WARNING]: RuntimeException: "yaml_parse(): end of stream reached without finding document 0" (E_WARNING) in "/src/pocketmine/utils/Config" at line 148 PHP: <?phpnamespace Withertube ;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerChatEvent;use pocketmine\utils\TextFormat as Color;use pocketmine\utils\Config;class ChatSafe extends PluginBase implements Listener { public $badwords = array(); public $config;public function onEnable(){$this->getServer()->getPluginManager()->registerEvents($this, $this);$this->getLogger()->info("wurde aktiviert");@mkdir($this->getDataFolder());@mkdir($this->getDataFolder() . "/Badwords");$this->cfg = $this->getConfig();$this->saveDefaultConfig();}public function onChat(PlayerChatEvent $event){$this->badwords = new Config($this->getDataFolder() . "Badwords/" . "badwords.yml" , Config::YAML , array( "Badwords" => [ "fuck" , "fick" , "bastard" , "fettsack" ], ));$msg = $event->getMessage();$badwords = $this->cfg->get("badwords");$neuersatz = str_ireplace($badwords,"****",$msg);$event->setMessage($neuersatz);}public function onDisable(){$this->getLogger()->info("wurde deaktiviert");} }
U didn't even make the folder. You did PHP: @mkdir($this->getDataFolder() . "/Badwords"); Its supposed to be: PHP: @mkdir($this->getDataFolder() . "Badwords/");
Well, actually: PHP: new Config($this->getDataFolder() . "/Badwords/" . "badwords.yml" , Config::YAML , array( "Badwords" => [ "fuck" , "fick" , "bastard" , "fettsack" ],)) The @mkdir is correct.
The Console output the same error Message before ?!? PHP: <?phpnamespace Withertube ;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerChatEvent;use pocketmine\utils\TextFormat as Color;use pocketmine\utils\Config;class ChatSafe extends PluginBase implements Listener { public $badwords = array(); public $config;public function onEnable(){$this->getServer()->getPluginManager()->registerEvents($this, $this);$this->getLogger()->info("wurde aktiviert");@mkdir($this->getDataFolder());@mkdir($this->getDataFolder() . "/Badwords");$this->cfg = $this->getConfig();$this->saveDefaultConfig();}public function onChat(PlayerChatEvent $event){$this->badwords = new Config($this->getDataFolder() . "/Badwords/" . "badwords.yml" , Config::YAML , array( "Badwords" => [ "fuck" , "fick" , "bastard" , "fettsack" ], ));$msg = $event->getMessage();$badwords = $this->cfg->get("badwords");$neuersatz = str_ireplace($badwords,"****",$msg);$event->setMessage($neuersatz);}public function onDisable(){$this->getLogger()->info("wurde deaktiviert");} }
PHP: <?phpnamespace Withertube;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerChatEvent;use pocketmine\utils\TextFormat as Color;use pocketmine\utils\Config;class ChatSafe extends PluginBase implements Listener{ public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getLogger()->info("wurde aktiviert"); @mkdir($this->getDataFolder()); $this->saveDefaultConfig(); $this->reloadConfig(); } public function onChat(PlayerChatEvent $event) { $msg = $event->getMessage(); $badwords = $this->getConfig()->get("badwords"); $neuersatz = str_ireplace($badwords, "****", $msg); $event->setMessage($neuersatz); } public function onDisable() { $this->getLogger()->info("wurde deaktiviert"); }} Important: You need to have a config file in your resources folder.
I made it thanks but there are now two configs : one that i created in the Folder Badwords the other spawns automaticlly alone xD. Do can help me which Config i chose and what i must write in it please ?? //sorry for my bad English ^^
When you run the plugin source folder via DevTools all the code will be executed too. That's why you have two configs, because PHP: new Config() exists. But, don't worry, it's not a issue.
you created one "manual" and one with ->saveDefaultConfig() you need to delete one thing xD (i would delete the saveDefaultConfig() ^^)