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

Solved Loading YAML configurations

Comments in 'Plugin Development' started by thebigsmileXD, Aug 14, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    public function onEnable() {
        
    $this->saveResource("config.yml");
        
    $this->saveResource("players.yml");
        
    $this->players = (new Config($this->getDataFolder() . "players.yml"Config::YAML)->getAll();
    }

    public function 
    checkPlayer(Player $player) {
        if(
    in_array($this->players["players"][$player->getName()])) {
            return 
    true;
        }
        return 
    false;
    }
    you should be able to do the rest from that, I'm not 100% sure on how to check if a directory exists in a YAML file but I'm pretty sure it saves as an array so checking if it's there should work.
    Last edited: Aug 17, 2015
    thebigsmileXD likes this.
  2. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    This looks really nice, i'll have a closer look at it and test it out! Thanks!
    CrazedMiner likes this.
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Dang it. Understood it for month now but haven't wrote a tutorial yet :p
  4. I_Is_Payton_
    Offline

    I_Is_Payton_ Active Member Plugin Developer

    Joined:
    Jan 18, 2014
    Posts:
    76
    Plugins:
    1
    Minecraft User:
    I_Is_Payton_
    Bad practice. Unless there is an actual reason for using @ (besides the fact that you want to eliminate error messages), don't use it.
    PEMapModder likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    P.S. actually, saveDefaultConfig() would create the folder.

    @mkdir is one of the common accepted uses of @ :p at least in PocketMine.
    I_Is_Payton_ and hoyinm14mc like this.
  6. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Well, when you do not use saveDefaultConfig, you have to add it.

Share This Page

Advertisement