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

How do i create a config.yml

Comments in 'Plugin Development' started by Hotshot_9930, May 2, 2015.

Thread Status:
Not open for further replies.
  1. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Hello, im still a bit new to making pocketmine plugins, and I was wondering if anyone could explain to me how I can create a config.yml
  2. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    What exactly do you mean?
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You can create a config.yml by creating a new Folder in Source Files and call it resources. In there you create a yaml file called config.

    To load the Config on the Server start, use:
    PHP:
    public function onEnable(){
            
    $this->saveDefaultConfig();
            
    $this->reloadConfig();
            }
    An Example for how to use the config:
    PHP:
    $this->getConfig()->get("no-permission");
    $this->getConfig()->get("test-message");
    Code:
    #This is the config
    no-permission: You don't have the permission to perform this command.
    In a Plugin for example:
    PHP:
    case "test":
                        if(
    $sender->hasPermission("Test.test")){
                            
    $sender->sendMessage($this->getConfig()->get("test-message"));
                            return 
    true;
                        } else{
                            
    $sender->sendMessage($this->getConfig()->get("no-permission"));
                            return 
    true;
                        }
    Hittmana likes this.
  4. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    Here is a way that I learned from the great @EvolSoft! Also simpler!
    Remember to add the namespace: pocketmine\utils\Config;
    PHP:
    public function onEnable(){
        
    // Creates the plugin folder
        
    @mkdir($this->getDataFolder());
        
    // Creates the config
        
    $cfg = new Config($this->getDataFolder()) . "config.yml"), Config::YAML));
    }
    Then you can add stuff to configs by using:
    PHP:
    $cfg->set("Number"1);
    // Then save it using:
    $cfg->save();
    Last edited: May 10, 2015
    EvolSoft and Hotshot_9930 like this.
  5. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    I use
    PHP:
    public function onEnable(){
        if(!
    file_exists($this->getDataFolder() . "config.yml")){
          @
    mkdir($this->getDataFolder());
          
    file_put_contents($this->getDataFolder()."config.yml"$this->getResource("config.yml"));
        }
    }
    You should also have a default config.yml file set up in the resource folder
  6. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    You have to close the resource stream using fclose on the resource.
    CrazedMiner likes this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Or simply:
    PHP:
    $this->saveDefaultConfig();
  8. amiremad
    Offline

    amiremad Active Member

    Joined:
    Sep 8, 2015
    Posts:
    193
    Minecraft User:
    amir107
    how to make 2 config files instead of 1
    CraftingMania likes this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    // in main class
    $this->config2 = new Config("config2.yml"Config::YAML$defaultContentsInTheConfig);
Thread Status:
Not open for further replies.

Share This Page

Advertisement