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

How to find if player is Online?

Comments in 'Plugin Development' started by Hittmana, Feb 9, 2016.

  1. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    How can I detect if the player is Online. I need to know if the player is on the server or not.
  2. MineBuilderFR
    Offline

    MineBuilderFR Active Member

    Joined:
    Mar 14, 2015
    Posts:
    56
    Minecraft User:
    MineBuilderFR
    PHP:
    if($player->isOnline()){
    //
    }
  3. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    What do i set $player to and do i have to
    PHP:
    use
    anything?
  4. MineBuilderFR
    Offline

    MineBuilderFR Active Member

    Joined:
    Mar 14, 2015
    Posts:
    56
    Minecraft User:
    MineBuilderFR
    PHP:
    use pocketmine\Player;
    Want to know if the player (pseudo) is online? :

    PHP:
    $player $event->getPlayer()->getName("Pseudo");
    if(
    $player->isOnline()){
    //
    }
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    // Search for a player with a name that starts with $name or is $name
    if($player $this->getServer()->getPlayer($name)){
    //Online
    } else{
    //Offline
    }
    // Search for a player with a name that is $name
    if($player $this->getServer()->getPlayerExact($name)){
    //Online
    } else{
    //Offline
    }
    Last edited: Feb 10, 2016
  6. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    FIX
    PHP:
    if($player $this->getServer()->getPlayer($name)){
    //Online
    } else{
    //Offline
    }
  7. MineBuilderFR
    Offline

    MineBuilderFR Active Member

    Joined:
    Mar 14, 2015
    Posts:
    56
    Minecraft User:
    MineBuilderFR
  8. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Thank you guys!
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Fixed, thanks
    Nawaf_Craft1b likes this.
  10. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Wait how does that check if the player is online?
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    If he's not online it returns null
  12. TutoGamerWalid
    Offline

    TutoGamerWalid Active Member

    Joined:
    Jun 11, 2015
    Posts:
    69
    Minecraft User:
    TutoGamerWalid
    PHP:
    $player->sendMessage("players count($this->players) !");
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    What the..?
    HotFireyDeath and applqpak like this.
  14. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    What?.....
  15. TutoGamerWalid
    Offline

    TutoGamerWalid Active Member

    Joined:
    Jun 11, 2015
    Posts:
    69
    Minecraft User:
    TutoGamerWalid
    PHP:
    public $players = [];

    public function 
    onJoin(PlayerJoinEvent $event){
      
    $player $event->getPlayer();
      if(isset(
    $this->players[$player->getName()])){
      
    $player->sendMessage("players online ? ".count($this->players)." !");
      }
    }
  16. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Can you please don't go on your phone in school because it seems like you didn't listened when you learned to read
    HotFireyDeath, applqpak and Vaivez66 like this.
  17. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    All i need is that right? I already defined $players as $challenged ($challenged is who is being challenged) and $name is the sender
  18. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Here is code this should help:
    PHP:
    <?php

    namespace Hittmana\ChallengerPE;              

    use 
    pocketmine\event;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    class 
    MainClass extends PluginBase implements Listener
    {
        public function 
    onEnable()
            {
            
    $this->getLogger()->info("ChallengerPE enabled v1.0.4");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }
        public function 
    onDisable()
            {
            
    $this->getLogger()->info("ChallengerPE disabled v1.0.4");
            }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args)
            {
            if(
    $sender instanceof Player)
            {
                
    $name $sender->getName();
                
    $challenged $this->getServer()->getPlayer($args[0])->getDisplayName();  
                
    $thing $args[1];
                if (
    $command->getName() === "challenge")
                    {
                    
    $player $this->getPlayer()->getName($challenged);
                    if (
    $challenged $this->getServer()->getPlayer($challenged)){
                    
    $this->getServer()->broadcastMessage($name " challenges " $challenged " to " $thing);
                    }
                    else
                    {
                        
    $sender->sendMessage($challenged "cant be found!");
                    }
                    }
            }
        }
    }
  19. TutoGamerWalid
    Offline

    TutoGamerWalid Active Member

    Joined:
    Jun 11, 2015
    Posts:
    69
    Minecraft User:
    TutoGamerWalid
    It's normal I use my phone
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please stop posting invalid solutions.

    First of all, what is meant by "the player"?
    getPlayerExact is more practical for this purpose. You don't want to know that PEMapModder_ is online if you are checking if PEMapModder is online.
    HotFireyDeath and applqpak like this.

Share This Page

Advertisement