#sendEquipmentChange not working

1 messages · Page 1 of 1 (latest)

misty river
#

I have this code:
@EventHandler
public void onItemSwap(PlayerItemHeldEvent event) {

    Player player = event.getPlayer();

    if (isActivated.contains(player.getUniqueId())) {

        player.sendMessage("activated: " + player);
        for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {

            if (onlinePlayer == player) continue;
            onlinePlayer.sendEquipmentChange(player, EquipmentSlot.HAND, new ItemStack(Material.AIR));

        }

    } else {

        player.sendMessage("deactivated");
        for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {

            if (onlinePlayer == player) continue;
            onlinePlayer.sendEquipmentChange(player, EquipmentSlot.HAND, new ItemStack(Material.AIR));

        }

    }
}

And it's supposed to make the item invisible on item swap if it is activate. But for some reason, it does activate, it does send the "activated", it does get the players, but it doesn't send the equipment change packet... Does anyone know why?

#

nah found the problem

#

have to make the thing happen 1 tick later

sonic matrix
#

yeah I was gonna say

#

since you're swapping the item, the event is called right before Spigot changes the actual value