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

Online and offline players

Comments in 'Plugin Development' started by TryoneLegendZzz, Oct 15, 2015.

  1. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    how can i tell if a player is online or offline
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    PHP:
    $player->isOnline();
    //or/and
    $player->isConnected();
    GmWM likes this.
  3. GmWM
    Offline

    GmWM Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    181
    Plugins:
    3
    Faster than me :p
    Good job! :D

    EDIT:
    PHP:
    if($player->isOnline()) {
        
    //Code to execute
    }
    Use an if statement :p
    #Useless edit.
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    I
    I was reading docs and suddenly i found this question when i've just seen the answer :D
  5. GmWM
    Offline

    GmWM Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    181
    Plugins:
    3
    You knew the anwser if you weren't looking into the docs? :D
    Taha_The_Hacker likes this.
  6. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    thanks guys :D
  7. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    He liked only your post...
  8. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    I know this is already solved but why don't you just look at the docs? It would be much faster than coming here and waiting for an answer and it's easy to do.
    TryoneLegendZzz likes this.
  9. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    i only use the docs for classes. but i dont know why
  10. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    What's that supposed to mean? Player is a class.
    Taha_The_Hacker likes this.
  11. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    nvm it hard to explain via inter-web
  12. GmWM
    Offline

    GmWM Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    181
    Plugins:
    3
    You got a like from me! :)
    Ake and Taha_The_Hacker like this.
  13. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    The docs are pretty useful, you should look before you create a new thread. Do you not know where to look in the docs for stuff like this? o_O
    Well some people don't know how to read... And then they just ask here when they get lazy.
    Lambo likes this.
  14. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    yes i do i use it all day today. i had freetime the whole day at school
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    A Player instance should not be kept after the player has left the server (as per correct programming practice). In correct practice, the only chance for isOnline to return false is when the player has not spawned yet.
    If you want to check if the player by name is online, you can check with getPlayer, but remember that getPlayer can return null, and you can't call a method upon null.
  16. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    $target $this->getServer()->getPlayerExact($player->getName());

    if(
    $target instanceof pocketmine\Player) { //Checks if player is online
        // Your code
      
    }
      else {
          
    // Do something
      
    }
    ^Should also work
    But keep in mind that i have not tested it.

Share This Page

Advertisement