Solved config

Discussion in 'Development' started by Teamblocket, May 6, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    hey , I've seen plugins make files and folder and then stores the data in a file with the players name , can someone give me an example of this to save/create a players file , like make a file when they join idk how to explain this sorry if i sound everywhere
     
  2. thelucyclub

    thelucyclub Spider Jockey

    Messages:
    28
    GitHub:
    thelucyclub
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    just make a config with player's name and store relevant data
     
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    but i want it to create a file when the player joins , name.yml , teamblocket.yml etc
     
  5. thelucyclub

    thelucyclub Spider Jockey

    Messages:
    28
    GitHub:
    thelucyclub
     
  6. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    PHP:
    public function onJoin(PlayerJoinEvent $event){
        if(!
    is_dir($this->getDataFolder())){
                @
    mkdir($this->getDataFolder());
        }
        if(!
    file_exists($this->getDataFolder().$event->getPlayer()->getName().".yml")){
            
    $config = new Config($this->getDataFolder().$event->getPlayer()->getName().".yml"CONFIG::YAML);
            
    $config->set("name"$event->getPlayer()->getName());
            
    // simply stores player name, you can store more info as you wish.
        
    }
    }
     
    Teamblocket likes this.
  7. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    If you check if a directory exists, you don't need to add the stfu operator (@)
     
  8. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    how would i be able to save the file into a folder in the resource folder
     
  9. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    Oh, I forgot to include this, make sure to do
    PHP:
    $config->save();
    You can save the file in a folder in the resource folder by entering $getDataFolder."/folderName/".$event->getPlayer()->getName().".yml"
    Instead
     
  10. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    thhhxxx!!!!
     
    Sandertv likes this.
  11. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Code:
    08.05 18:48:09 [Server] INFO Warning: file_put_contents(/plugins/GuiKits//players/Steve.yml): failed to open stream: No such file or directory in phar:///jar/pocketmine/arufa/1.0.8/Arufa.phar/src/pocketmine/utils/Config.php on line 205
     
  12. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    You added an extra slash, remove this extra slash and tell me how it goes.
     
  13. Lowkey

    Lowkey Slime

    Messages:
    94
    getDataFolder() is not a variable! Why are you putting an $ on it? Ugh, I hate it when people mislead learners.

    OR you just made a typo
     
    HimbeersaftLP and jasonwynn10 like this.
  14. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    Sorry typo.
    It's getDataFolder()
     
  15. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Same error just with one less slash
     
  16. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    Could you send the exact code you did?
     
  17. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Code:
    public function onJoin(PlayerJoinEvent $event){
        if(!is_dir($this->getDataFolder())){
                @mkdir($this->getDataFolder());
        }
        if(!file_exists($this->getDataFolder()."players/".$event->getPlayer()->getName().".yml")){
            $config = new Config($this->getDataFolder()."players/".$event->getPlayer()->getName().".yml", CONFIG::YAML);
            $config->set("name", $event->getPlayer()->getName());
            $config->save();
            // simply stores player name, you can store more info as you wish.
        }
    }
     
  18. Lowkey

    Lowkey Slime

    Messages:
    94
    You're using Arufa. We do not support spoons here
     
  19. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    You need to create the "players" directory as well.

    So maybe something like
    PHP:
    public function onJoin(PlayerJoinEvent $event){
        @
    mkdir($this->getDataFolder());
        @
    mkdir($this->getDataFolder() . "players/");
        if(!
    file_exists($this->getDataFolder()."players/".$event->getPlayer()->getName().".yml")){
            
    $config = new Config($this->getDataFolder()."players/".$event->getPlayer()->getName().".yml"CONFIG::YAML);
            
    $config->set("name"$event->getPlayer()->getName());
            
    $config->save();
            
    // simply stores player name, you can store more info as you wish.
        
    }
    }
     
    [deleted] likes this.
  20. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    ok , done I've changed to PMMP but the error is still their
    Code:
    09.05 16:13:11 [Server] INFO Warning: file_put_contents(/plugins/GuiKits/players/Teamblocket.yml): failed to open stream: No such file or directory in phar:///jar/pocketmine/pmmp/1.0.7/PocketMine-MP.phar/src/pocketmine/utils/Config.php on line 208
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.