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

Config

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

  1. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    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");
    }


    }
  2. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    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]
    
  3. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    At first thanks :3 but it didn't work :(

    Attached Files:

  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $this->badwords = new Config($this->getDataFolder() . "/Badwords/" ".yml" Config::YAML); 
    How should a file only called ".yml" exist?
    Vaivez66 and applqpak like this.
  5. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    I don't know xD. Wirklich du hilfst mir hier aber nicht in der Gruppe dein Ernst ._. xD.
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    English only. :p
    Vaivez66 likes this.
  7. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    ok Please help me i want to make an array which save in the config words please help :D
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    $this->badwords = new Config($this->getDataFolder() . "Badwords/" "badwords.yml" Config::YAML, array(
      
    "Badwords" => [
      
    "poop""eggs""bunny""shoe"
    ],
    ));
    Last edited: Feb 7, 2016
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Typo at "array()" ;)
    Vaivez66 likes this.
  10. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Oops. i fixed it lol
  11. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    I made it so but it doesn't wont to work and output this error Message :D


    [WARNING]: RuntimeException: "yaml_parse(): end of stream reached without finding document 0" (E_WARNING) in "/src/pocketmine/utils/Config" at line 148


    PHP:
    <?php

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

           
        }
       
       
       
       
  12. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    U didn't even make the folder. You did
    PHP:
    @mkdir($this->getDataFolder() . "/Badwords");
    Its supposed to be:
    PHP:
    @mkdir($this->getDataFolder() . "Badwords/");
    PocketKiller and Vaivez66 like this.
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Well, actually:
    PHP:
    new Config($this->getDataFolder() . "/Badwords/" "badwords.yml" Config::YAML , array(
        
    "Badwords" => [
            
    "fuck" "fick" "bastard" "fettsack"
        
    ],
    ))
    The @mkdir is correct.
  14. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    The Console output the same error Message before ?!?



    PHP:
    <?php

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

           
        }
       
       
       
       
  15. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    <?php

    namespace 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.
    WitherTube likes this.
  16. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    I made it thanks :D 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 ^^
  17. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    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.
    WitherTube likes this.
  18. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    you created one "manual" and one with ->saveDefaultConfig()

    you need to delete one thing xD (i would delete the saveDefaultConfig() ^^)
    WitherTube likes this.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is a bad practice to use the @ operator. Rather, check if(!is_dir()) before calling mkdir().
    WitherTube and CraftYourBukkit like this.

Share This Page

Advertisement