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

Display NameTag bug

Discussion in 'Development' started by kaliiks, Dec 17, 2016.

  1. kaliiks

    kaliiks Zombie

    Messages:
    250
    I spawned Entity Human with nametag and after server restart nameteag is not visible
    full code here:
    PHP:
    <?php
    namespace WallCore;

    use 
    pocketmine\entity\Human;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerCommandPreprocessEvent;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\nbt\tag\DoubleTag;
    use 
    pocketmine\nbt\tag\FloatTag;
    use 
    pocketmine\nbt\tag\ListTag;
    use 
    pocketmine\nbt\tag\StringTag;

    class 
    NPCManager implements Listener
    {
        public function 
    onCommand(PlayerCommandPreprocessEvent $event)
        {
            {
                
    $cmd explode(" "strtolower($event->getMessage()));
                
    $player $event->getPlayer();
                if (
    $cmd[0] === "/npc") {
                    
    $block $player;
                    
    $npc = new Human($player->chunk,
                        new 
    CompoundTag("", [
                                
    "Pos" => new ListTag("Pos", [
                                    new 
    DoubleTag(""$block->getX()),
                                    new 
    DoubleTag(""$block->getY()),
                                    new 
    DoubleTag(""$block->getZ())
                                ]),
                                
    "Motion" => new ListTag("Motion", [
                                    new 
    DoubleTag(""0),
                                    new 
    DoubleTag(""0),
                                    new 
    DoubleTag(""0)
                                ]),
                                
    "Rotation" => new ListTag("Rotation", [
                                    new 
    FloatTag(""0),
                                    new 
    FloatTag(""360)
                                ]),
                                
    "Skin" => new CompoundTag("Skin", [
                                    
    "Data" => new StringTag("Data"$player->getSkinData())
                                ])
                            ]
                        ));


                    
    $npc->spawnToAll();
                    
    $npc->setNameTagVisible(true);
                    
    $npc->setNameTagAlwaysVisible(true);
                    
    $npc->setNameTag("§l§eSkyWars");
                    
    $npc->setMaxHealth(99999999);
                    
    $npc->setHealth(99999999);

                }

                
    $event->setCancelled(true);
            }
        }
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Try with $entity->setDataProperty instead, tho setNameTagVisible should be doing the trick.

    Possibly, the server might not have shut down correctly. You can execute /save-all before shutting the server down and after spawning the $npc.

    If that didn't help, you can execute this during EntitySpawnEvent...
    PHP:
    if ($entity->getNameTag() == "§l§eSkyWars") {
        
    $entity->setNameTagVisible(true);
        
    $entity->setNameTagAlwaysVisible(true);
    }
     
    InspectorGadget likes this.
  3. kaliiks

    kaliiks Zombie

    Messages:
    250
    Thanks!
     
  4. kaliiks

    kaliiks Zombie

    Messages:
    250
    Now when I spawn Entity i can not use chat
     
  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.