Solved Trying to hide the name of an NPC with packets and datawatcher

Discussion in 'Spigot Plugin Development' started by VivianMusic, Mar 10, 2020.

  1. I am trying to hide the name of my NPCs with packets. I am currently using a DataWatcher to enable all layers of the skin, but I can't figure out how to actually hide their name above their head. Please help!

    Currently I have
    Code (Text):
      DataWatcher dataWatcher = npc.getDataWatcher();
            dataWatcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 127);
    which is enabling their mask and such, but I don't entirely know what the values mean. Can anyone try to explain...? I've looked through the DataWatcherObject class and don't understand it.

    Looking at https://wiki.vg/Protocol#Entity_Metadata and https://wiki.vg/Entity_metadata#Entity_Metadata_Format I can see that the index relating to CustomNameVisible is "3" but I don't really know what to do with it
     
    #1 VivianMusic, Mar 10, 2020
    Last edited: Mar 10, 2020
  2. Maybe the packets are conflicting/overwriting each other. Try delaying them by a tick.
     
  3. The name of the player entity is always visible except for 2 cases:
    1. Viewer and player entity belong to the same scoreboard team with hide nametags option.
    2. Player entity has a passenger (which can be invisible).
     
  4. Or entities in a scoreboard team with the always hide nametag option.
     
  5. Code (Text):
            org.bukkit.scoreboard.Scoreboard scoreboard = player.getScoreboard();

            Team npcs = null;

            for(Team team : scoreboard.getTeams()) {
                if(team.getName().equals("npcs")) {
                    npcs = team;
                    break;
                }
            }

            if(npcs == null) {
                npcs = scoreboard.registerNewTeam("npcs");
            }

            npcs.setNameTagVisibility(NameTagVisibility.NEVER);
            npcs.addEntry(npcName);
    This works great!

    [​IMG]
     
    • Like Like x 1