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

How to get player's name in a configuration file?

Comments in 'Plugin Development' started by Mat, Apr 17, 2015.

  1. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    Hello guys , I need help for a plugin for my private server . How do I take the nick of a new player and transfer it in a config file ?
    -Steve Joined the game .
    > Plugins save the nick Steve in the config file ;
    #Other Configuration #
    Steve : true
    -Steve Left the game
    -Player Joined the game
    > Plugin save the nick Player in the config file ;
    #Other Configuration #
    Steve : true
    Player : true

    Thanks a lot! :D
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    You will need to call the code below when player joins.
    Code:
    $player = $event->getPlayer(); #gets the player -> $player
            $c = $this->getResource("config.yml");
            $o = stream_get_contents($c);
            fclose($c);
            file_put_contents($this->getDataFolder() . "config.yml", $player); #puts the $player into config file.    
    
    I don't have the chance to test the code, but I think it will work as long as you call it under JoinEvent.
    Last edited: Apr 17, 2015
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It will override the file every time.
    HotFireyDeath likes this.
  4. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    I changed it. Does it work now?
  5. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    PHP:
    if(!$this->players->exists($event->getPlayer()->getName()){
    $this->players->set($event->getPlayer()->getName());
    }
    Not the best way, but it is a start. Also, try reading the docs: docs.pocketmine.net
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PixelGuy75 likes this.

Share This Page

Advertisement