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

Add a name in sentence

Discussion in 'Development' started by Matrox, Aug 11, 2018.

  1. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Hello I would like to know how added the name a player in a sentence ?


    Exemple :

    $sender->sendMessage("Hello name");
     
  2. Nawaf1b

    Nawaf1b Silverfish

    Messages:
    17
    To get Player Name
    Code:
    if($sender instanceof Player){ $name = $sender->getName();}
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    public function onJoin(PlayerJoinEven $event): void{
    $player $event->getPlayer();
    $name $player->getName();

    $player->sendMessage("Hello there, $name"); //send message to player only
    $player->sendPopup("Hello there, $name"); //send tip message to player only
    $player->addTitle("Hello there"$name); //send title and subtitle to player only
    $this->getServer()->broadcastMessage("$name has joined"); //send message to everyone in server
    $this->getServer()->broadcastPopup("$name has joined"); //send tip message to everyone in server
    $this->getServer()->broadcastTitle("Hello there"$name); //send title and subtitle to everyone in server
    }
     
  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.