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

getPlayers() Not Working!

Comments in 'Plugin Development' started by Calrizer, Mar 23, 2015.

  1. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Hi I'm trying to get this line to work but it keeps returning the error:
    Fatal error: Call to a member function getPlayers() on null

    Here's the code:
    PHP:
    $online count($this->plugin->getServer()->getLevelByName($world)->getPlayers());
    The $world variable is already declared.

    Any suggestions?

    -Calrizer
  2. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    Try this it should work ! (If $world is already declared !)
    PHP:
    $online count($this->plugin->getServer()->getLevelByName($world)->getPlayer());

    //You just have to remove the "s" at players !
    Because getPlayers(); doesn't exists only but getPlayer(); work !

    Quote me i f you need help !
  3. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Sill returning the same error :(
  4. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    I have antoher idea but don't know if it work :

    PHP:
    foreach($this->plugin->getPlayer()->getLevel($world)->getPlayers() as $levelplayers){

    $online $levelplayers;
    }
  5. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    $world is declared but it may not contain a valid level name. Note that if you are under Windows, case may be not be significant, but it is in PocketMien.

    Anyway, getLevelByName is returning null (couldn't find the world you requested), so getPlayers() fails.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't post if you don't know what you are even doing!
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Only getPlayers() exist, not getPlayer().
    Falk likes this.
  8. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    getPlayer() dose exist.... getPlayer()->getName()
  9. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Not on Level it doesn't.
    Andrey Nazarchuk, LDX and CrazedMiner like this.
  10. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    PHP:
    $temp = [];
    foreach(
    $this->getServer()->getOnlinePlayers() as $p){
         if(
    $p->getLevel()->getName() === $world){
              
    $temp[] = $p->getName();
         }
    }
    $value count($temp);
    im not sure if this works but i find this more logical xD
    LDX and CrazedMiner like this.
  11. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Yah, I was thinking of something like this as well :p
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Do you understand PHP... Didn't you see we are talking about context of a Level? If it's 12:20 there and you can't think, don't post without thinking :p
  13. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Lol I stopped posting and and started coding :p
  14. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    Never heard of atrted coding before
    CrazedMiner likes this.
  15. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    lol

Share This Page

Advertisement