Hiding NPC name

Discussion in 'Plugin Development' started by davidclue, Feb 11, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    davidclue

    So pretty self explanatory I can't make npc's without nametags and I've used scoreboards and it doesn't work and I used NMS scoreboard team packets and when I changed the field for "g" it threw me an error for trying to modify the field.
    Code:
    public DeathMessages(Main plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
           
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            this.team = board.registerNewTeam("frozenplayers");
            team.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
        }
    @SuppressWarnings("deprecation")
        public void spawnFakePlayer(Player player, String displayname, World tempW) {
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer world = ((CraftWorld) tempW).getHandle();
    
            Player target = Bukkit.getServer().getPlayer(displayname);
            EntityPlayer npc;
            if (target != null) {
                npc = new EntityPlayer(server, world, new GameProfile(target.getUniqueId(), target.getName()), new PlayerInteractManager(world));
            } else {
                OfflinePlayer op = Bukkit.getServer().getOfflinePlayer(displayname);
                npc = new EntityPlayer(server, world, new GameProfile(op.getUniqueId(), ChatColor.translateAlternateColorCodes('&', displayname)), new PlayerInteractManager(world));
            }
            Location loc = player.getLocation();
            npc.setLocation(loc.getBlockX()+0.5, loc.getBlockY(), loc.getBlockZ()+0.5, loc.getYaw(), loc.getPitch());
            PacketPlayOutEntityHeadRotation rotation = new PacketPlayOutEntityHeadRotation(npc, (byte) ((loc.getYaw() * 256.0F) / 360.0F));
           
            for (Player all : Bukkit.getOnlinePlayers()) {
                PlayerConnection connection = ((CraftPlayer)all).getHandle().playerConnection;
                connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
                connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
                connection.sendPacket(rotation);
            }
            team.addPlayer(npc.getBukkitEntity());
        }
     
Thread Status:
Not open for further replies.

Share This Page