Trying to hide the item in hand to other players with packet in 1.16.1 but having a problem

Discussion in 'Plugin Development' started by Koraizon, Oct 10, 2020.

  1. Offline


    Hey, I'm trying to do a plugin for a game and I wanted to be able to hide the item in hand to other players.
    So I searched on internet what i could use to do that and i learned about packet.
    I understood packet like just sprite that you show but that aren't actually physical i think.
    So i did a bit of research on how i could change the items in hand to show just air with packet.
    After a while I thought i had done it but i have a bit of a problem.
    That's the code I'm using:

        public void PlayerItem(PlayerItemHeldEvent e) {
            Player p = e.getPlayer();
            final List<com.mojang.datafixers.util.Pair<EnumItemSlot, ItemStack>> equipmentList = new ArrayList<>();
            equipmentList.add(new com.mojang.datafixers.util.Pair<>(EnumItemSlot.MAINHAND, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.AIR))));
            PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(p.getEntityId(), equipmentList);
            for(Player player : Bukkit.getOnlinePlayers()) {
                if(!(p.equals(player))) {
                    PlayerConnection pc = ((CraftPlayer)player).getHandle().playerConnection;

    So basically, when the player change the item he hold, his main hand should change to air to everyone except from him but when i use it the item became air but come back right after so it don't work and I don't understand why...
    I already tried to use a RunTaskLater or make a Priority for the event because i thought that maybe it put the item after the PlayerItemHeldEvent but it didn't work either

Share This Page