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

Solved Event on Player $args[0]

Discussion in 'Development' started by Th3Ang3lo, Nov 20, 2018.

  1. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    I wanted to perform some event with the Player that was informed in $args[0], I tried to use this but it did not give...

    public function execute(CommandSender $sender, $label, array $args){
    if(!isset($args[0])){
    $sender->sendMessage("Use: /test <player>");
    return true;
    }

    $player = $this->pl->getServer()->getPlayer($args[0]);

    if($args[0] == $player){
    $player->sendMessage("TEST");
    }
    }
     
  2. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    I'm edit if(isset($player))

    my pl Run!
     
  3. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    You don't need verify this, only do:
    PHP:
     if(!is_null($player)){ # IF PLAYER IS ONLINE
           
    $player->sendMessage("TEST");
    }else{
    $sender->sendMessage("Player offline");
    }
     
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    if(!$player $this->pl->getServer($args[0])){
    //player not found 
    return false;
    }

    //do what u want
     
  5. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    PHP:
    $user $args[1];
    $target Server::getInstance()->getPlayer($user);
    if (
    $target == null) {
    $sender->sendMessage("§c{$user} is offline.");
    } else {
    //do what you want
    }
    that should work
     
  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.