Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to create a config with array()?

Comments in 'Plugin Development' started by WitherTube, Feb 20, 2016.

  1. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    hey :D
    i have the problem that i want to save an array() in the Config but it fails every time when i started it :(.
    I have a resource folder with a config.yml and an other Config which spawns automatically ?Do you can help me in this Problem please :D?


    PHP:
    <?php
    /*
    *

    *  _      _     _____  __   __  _____  _____   _____  __   __   ______  ______
    * | |    | |(_)|__ __||  | |  ||  ___||     \ |__ __||  | |  | |  __  || _____|
    * | |    | || |  | |  |  |_|  || |___ | (__) \  | |  |  | |  | | |__|_|| |____
    * | |____| || |  | |  |   _   ||  ___||      |  | |  |  | |  | |  __  ||  ____|   
    * |   __   || |  | |  |  | |  || |___ |  | \ |  | |  |  |_|  | | |__| || |____
    * |__/  \__||_|  |_|  |__| |_ ||_____||__| \_|  |_|  |_______| |______||______|
    * This plugin was made by WitherTube :D.
    * It was published on PocketMine-Forum , GitHub or Twitter ^^.
    * For upcoming News follow me on Twitter and maybe subscribe my channel :D.
    *
    *
    * @author WitherTube
    * @link Twitter : https://twitter.com/WitherDevPE
    * @link YouTube : https://www.youtube.com/channel/UCBcXzwKx27T1OEXCU9_NZiQ
    * @link Pocketmine : https://forums.pocketmine.net/members/withertube.40392/
    * @link GitHub : it is disable :(
    *
    */
    namespace Withertube ;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\utils\Config;

    class 
    ChatSafe extends PluginBase implements Listener {
        public 
    $cfg;
        public 
    $badwords = array();

    public function 
    onEnable(){
    $this->getLogger()->info("wurde aktiviert");
    if (!
    is_dir($this->getDataFolder())) {
                
    mkdir($this->getDataFolder());
            }
            
    $config = new Config($this->getDataFolder() . "config.yml"Config::YAML, ["badwords" => array(
         
    " bastard " ,
         
    " flugzeuge " ,
        
    )]);
    $this->reloadConfig();
    $this->config $this->getConfig()->getAll();
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }



    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");
    }

           
       
       
       

    }
    //That is the main.php


    #################################
    ###### Plugin made by WitherTube
    #################################

    badwords:
        - 
    bastard
        
    flugzeuge

    //This is the Config.yml
  2. Omar2s2
    Offline

    Omar2s2 New Member

    Joined:
    Dec 23, 2015
    Posts:
    12
    Minecraft User:
    Pop
    Are You Forgot foreach !!
    Must be use Foreach($badwords as $b){

    }
  3. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    str_ireplace accepts arrays. Learn PHP.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please specify the problem. What is "it fails"?
  5. basprohop
    Offline

    basprohop Active Member Plugin Developer

    Joined:
    Aug 8, 2015
    Posts:
    128
    Plugins:
    3
    Minecraft User:
    basprohop

Share This Page

Advertisement