Solved NMS 1.16.5 - Send fake armor packet

Discussion in 'Plugin Development' started by byteswing, Dec 27, 2023.

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


    hi everyone, in this code I am trying to send a packet that will display a leather helmet on the player's head.
    but after logging on to the server, only the diamond helmet is visible on the head (I thought that before displaying the helmet on the head, you first need the player to already have a helmet)

    how can I make the leather armor display?

    public void onJoin(PlayerJoinEvent e) {

    public void handHead(Player p) {
    CraftPlayer player = ((CraftPlayer) p);
    player.getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET));
    List<Pair<EnumItemSlot, net.minecraft.server.v1_16_R3.ItemStack>> list = new ArrayList();
    list.add(new Pair<>(EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(new ItemStack(Material.LEATHER_HELMET))));
    PacketPlayOutEntityEquipment equipment = new PacketPlayOutEntityEquipment(player.getEntityId(),list);
    for (Player l : Bukkit.getOnlinePlayers()) {
    CraftPlayer cp = (CraftPlayer) l;

    publicfinalclass TickPacket extends JavaPlugin implements Listener {
       private ProtocolManager protocolManager;// Declaration of ProtocolManager variable
       publicvoid onEnable(){
            protocolManager = ProtocolLibrary.getProtocolManager();// Initialize ProtocolManager
            registerPacketListener();// Call the method to register packet listener
       publicvoid onDisable(){
            protocolManager.removePacketListeners(this);// Remove packet listeners when the plugin is disabled
       // Method to register a packet listener
       privatevoid registerPacketListener(){
            protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT){
               publicvoid onPacketSending(PacketEvent event){// Method called when a packet is being sent
                    PacketContainer packet = event.getPacket();// Get the packet being sent
                    Player player = event.getPlayer();// Get the player associated with the event
                   if(packet.getType()== PacketType.Play.Server.ENTITY_EQUIPMENT){// Check if the packet type is ENTITY_EQUIPMENT
                        PacketContainer newItemPacket = packet.deepClone();// Create a deep copy of the original packet
                        List<Pair<EnumWrappers.ItemSlot, ItemStack>> list =new ArrayList<>();// Create a list to hold item slot and item stack pairs
                       // Add leather armor to the list for different equipment slots
                        list.add(new Pair<>(ItemSlot.HEAD, new ItemStack(Material.LEATHER_HELMET)));
                        list.add(new Pair<>(ItemSlot.CHEST, new ItemStack(Material.LEATHER_CHESTPLATE)));
                        list.add(new Pair<>(ItemSlot.LEGS, new ItemStack(Material.LEATHER_LEGGINGS)));
                        list.add(new Pair<>(ItemSlot.FEET, new ItemStack(Material.LEATHER_BOOTS)));
                       for(Player p : Bukkit.getOnlinePlayers()){// Iterate through all online players
                           if(player.getUniqueId()== p.getUniqueId())continue;// Skip the current player
                           // Add the items from the main hand and offhand of other players to the list
                            list.add(new Pair<>(ItemSlot.MAINHAND, p.getInventory().getItemInMainHand()));
                            list.add(new Pair<>(ItemSlot.OFFHAND, p.getInventory().getItemInOffHand()));
                            newItemPacket.getIntegers().write(0, p.getEntityId());// Set the entity ID for the new packet
                            newItemPacket.getSlotStackPairLists().write(0, list);// Set the slot stack pairs list for the new packet
                            event.setPacket(newItemPacket);// Update the packet being sent to the new modified packet
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Dec 27, 2023
Thread Status:
Not open for further replies.

Share This Page