1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved How to store all online player names in an array?

Discussion in 'Plugin Help' started by ATVExtremeGamer, Sep 12, 2021.

  1. ATVExtremeGamer

    ATVExtremeGamer Creeper

    Messages:
    4
    GitHub:
    atvextremegamer
    hi
    i need to store all online player's username in an array
    any help is appreciated, thanks!
     
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    PHP:
    $players = array();
    foreach(
    $this->getServer()->getOnlinePlayers() as $player)
    {
      
    $players[] = $player->getName();
    }

    return 
    $players;
    I think this should work?
     
    Agent, Axon, NTT and 1 other person like this.
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    PHP:
    $players array_map(function($player){
        return 
    $player->getName();
    }, 
    array_values($this->getServer()->getOnlinePlayers()));
    Haven't messed with php for a long time, but should work.
     
    Axon, ATVExtremeGamer and minijaham like this.
  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.