How to change a nametag with or without protocollib

So i’ve been searching for the past year and out of all the solutions to change the nametag of a player 2 have been standing out one is using reflection and another is just using protocollib.

The problem im facing is that i cant get the nametag right just as i want it!

ProtocolLib Solution

public static void changePlayerNameTag(Player player, String newName) {
    // Update nametag for other players
    ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(EssentialsNicks.getPlugin(), PacketType.Play.Server.PLAYER_INFO) {
        @Override
        public void onPacketSending(PacketEvent event) {
            if (event.getPacket().getPlaye`your text`rInfoAction().read(0) != EnumWrappers.PlayerInfoAction.ADD_PLAYER) return;
            List<PlayerInfoData> newPlayerInfoDataList = new ArrayList<PlayerInfoData>();
            List<PlayerInfoData> playerInfoDataList = event.getPacket().getPlayerInfoDataLists().read(0);
            for (PlayerInfoData playerInfoData : playerInfoDataList) {
                if (playerInfoData == null || playerInfoData.getProfile() == null || Bukkit.getPlayer(playerInfoData.getProfile().getUUID()) == null) { //Unknown Player
                    newPlayerInfoDataList.add(playerInfoData);
                    continue;
                }
                // Check if the player's UUID matches the specific player's UUID
                if (!playerInfoData.getProfile().getUUID().equals(player.getUniqueId())) {
                    newPlayerInfoDataList.add(playerInfoData);
                    continue;
                }
                WrappedGameProfile profile = playerInfoData.getProfile();
                // Create a new profile with the desired name and the original profile's properties (including the skin)
                WrappedGameProfile newProfile = new WrappedGameProfile(profile.getUUID(), ChatColor.translateAlternateColorCodes('&', newName));
                newProfile.getProperties().putAll(profile.getProperties());
                PlayerInfoData newPlayerInfoData = new PlayerInfoData(newProfile, playerInfoData.getLatency(), playerInfoData.getGameMode(), playerInfoData.getDisplayName());
                newPlayerInfoDataList.add(newPlayerInfoData);
            }
            event.getPacket().getPlayerInfoDataLists().write(0, newPlayerInfoDataList);
        }
    });

    Bukkit.getOnlinePlayers().forEach(onlinePlayer -> {
        protocolManager.sendServerPacket(onlinePlayer, packet);
        onlinePlayer.hidePlayer(player);
        onlinePlayer.showPlayer(player);
    });
}

Reflection

 public static void changeName(String name, Player player) {
        try {
            Method getHandle = player.getClass().getMethod("getHandle");
            Object entityPlayer = getHandle.invoke(player);
            Class<?> entityHuman = entityPlayer.getClass().getSuperclass();
            Field gameProfileField;
            int majVersion = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().split("\.")[3].replaceAll("(v|R[0-9]+)", "").split("_")[0]);
            int minVersion = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().split("\.")[3].replaceAll("(v|R[0-9]+)", "").split("_")[1]);
            if (majVersion >= 1 && minVersion >= 9) {
                gameProfileField = entityHuman.getDeclaredField("bS");
            } else {
                gameProfileField = entityHuman.getDeclaredField("bH");
            }
            gameProfileField.setAccessible(true);
            gameProfileField.set(entityPlayer, new GameProfile(player.getUniqueId(), name));
            for (Player players : Bukkit.getOnlinePlayers()) {
                players.hidePlayer(player);
                players.showPlayer(player);
            }
        } catch (NoSuchMethodException | SecurityException | InvocationTargetException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }

Each own has its own problem and im tryna just have the best of both worlds kinda like hypixel

Common Problems
Player’s own nametag doesn’t change (Client Side)

ProtocolLib’s Problems
Changed nametag doesn’t work with teams

Reflection’s Problems
For Reflection it changes your very own minecraft name (obviously only on the server) the problem im facing with Reflection is that its gonna make minecraft and all of the other plugins commands unusuable also you can’t even tab to get your or the changed name.

Honestly if i can just fix the problem with protocolLib nametag that doesn’t work with teams i would be happy but i kinda want the player’s own nametag to change also ????.

If anybody knows something i don’t please i beg for your help!

New contributor

ludgerr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật