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

change nametag of player only for one player

Comments in 'Plugin Development' started by Creeperface, Oct 4, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    I want to change player nametag
    e.g. one player will see "player" and other players will see "name"
    So how can i do that?
  2. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Try:
    PHP:
    $player->setDisplayName("NameYouWant");
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    1. i want to change nametag xD
    2. i want to make change just for one player, setNameTag() change player's nametag for all players
  4. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Did you try using setDisplayName()?
    Using setDisplayName() works for me
  5. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    It might be possible to accomplish this using packets.
    Please don't reply if you don't understand his question. And he's asking about nametags, not display names. Please read the first post thoroughly before you post with a "solution". You know how everyone sees the same nametag as you? He wants to make it so that one player sees his nametag as "player", and all the other players see it as "name".
    What works for you? Be more descriptive.
    Last edited: Oct 4, 2015
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i know, my english is bad.. but i didnt know that much..
    I WANT TO SET NAMETAG
    thebigsmileXD likes this.
  7. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    ok thanks :D
  8. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Oh i understand now :)
  9. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    This might work.
    PHP:
    use pocketmine\Player;
    use 
    pocketmine\entity\Entity;

    /**
    * @param Player $player
    * @param string $nametag
    * @param Player[]|Player $players
    */
    public function customSetNameTag(Player $player$nametag$players){
        
    $player->sendData($players, [Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING$nametag]]);
    }
    Sources
    https://github.com/PocketMine/Pocke...9b5dcd7/src/pocketmine/entity/Entity.php#L295
    https://github.com/PocketMine/Pocke...9b5dcd7/src/pocketmine/entity/Entity.php#L545

    Edit: you should probably use the sendData function instead of making a custom one, it's just the custom method looks a bit cleaner and it looks slightly better.
    Last edited: Oct 5, 2015
    Creeperface and PEMapModder like this.
  10. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Sorry didn't see your reply.
    PEMapModder likes this.
  11. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    @Lambo's method is better. Didn't notice that sendData allows partial sending.
    Lambo likes this.
  13. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace

Share This Page

Advertisement