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

Player registered in server

Comments in 'Plugin Development' started by GamesLoad, May 21, 2015.

  1. GamesLoad
    Offline

    GamesLoad Active Member

    Joined:
    Jun 28, 2014
    Posts:
    106
    Minecraft User:
    GamesLoad
    Hello I wanted to ask for help to you on this question how do I know how many players are registered in a server? The plugin should read the folder players how many players there are and write them with a number.
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Write them in a File at join(if not exists) and count() them.
  3. GamesLoad
    Offline

    GamesLoad Active Member

    Joined:
    Jun 28, 2014
    Posts:
    106
    Minecraft User:
    GamesLoad
    you can give me an example?
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Create a file and use
    PHP:
    private $players;

    public function 
    onEnable(){
    $this->players = new Config($this->getDataFolder()."players.yml"Config::YAML);
    }

    public function 
    onJoin(PlayerJoinEvent $event){
    $player $event->getPlayer();
    if(
    $this->players->exists(strtolower($player->getName()))){

    } else{
    $this->players->set(strtolower($player->getName()));
    $this->players->save();
    }
    }
  5. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    I would:

    PHP:
    count(glob($server->getDataFolder()."players/*"));
    Where $server is an instance of \pocketmine\Server...
  6. GamesLoad
    Offline

    GamesLoad Active Member

    Joined:
    Jun 28, 2014
    Posts:
    106
    Minecraft User:
    GamesLoad
    ok and maybe if I would like to see the number on a sign
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you are on linux, this may be faster:
    PHP:
    $cnt = (int) `ls $dir | wc -l`;
    LDX likes this.

Share This Page

Advertisement