I just set nametag for entities on EntitySpawnEvent but the nametag of entities do not visible . I have tried to use setNameTagVisible(true) and setNameTagAlwaysVisible(true) but both dont work for me @@ Anyone know how to make nametag of entity visible ?Thanks
No (( My code : Code: public function onEntitySpawn(EntitySpawnEvent $e) { $mobs = $e->getEntity(); if($mobs instanceof Zombie || $mobs instanceof Skeleton || $mobs instanceof Spider){ foreach($this->main->getServer()->getOnlinePlayers() as $p) { $level = $this->main->getLevel($p); //if($mobs->distance($p) <= 50) { $name = $mobs->getNameTag(); $mobs->setNameTag($name."\nLevel ".$level); $mobs->setNameTagVisible(true); $mobs->setNameTagAlwaysVisible(true); //} } } }
While I don't know about your nametag display issue, I'd suggest running a check through a different function, like isNearPlayer($mobs), and if the mob is within range, break the foreach loop and return true. That way, in your listener, you could just use PHP: if($this->main->isNearPlayer($mobs)){ //set the entities nametag once, rather than 2 or 3 times if there are more players within range.} else { //No players are within range of the entity.} Also, I believe you can use PHP: if($mobs instanceof (Zombie || Skeleton || Spider)) {} to make it easier than writing out the $mobs instanceof so many times.