Armor Equip Event?

Discussion in 'Plugin Development' started by Ragnarok_, Apr 15, 2017.

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

    Ragnarok_

    Im making this plugin and I can't seem to get the armor equiped. I've tried e.getCurrentItem and such and none of it worked. Please help me, sorry for the short description.
    Code:
    @EventHandler
        public void onHorseMask(InventoryClickEvent e) {
    
            Player p = (Player) e.getWhoClicked();
    
            ItemStack skull = new ItemStack(Material.SKULL_ITEM);
            SkullMeta sm = (SkullMeta) skull.getItemMeta();
            skull.setDurability((short) 3);
            sm.setOwner("gavertoso");
            sm.setDisplayName(ChatColor.AQUA + "Horse Mask " + ChatColor.GOLD + "IV");
            skull.setItemMeta(sm);
    
            if (e.getSlotType() == SlotType.ARMOR) {
                if (p.getInventory().getHelmet() == null) {
                    if (e.getCurrentItem() == skull) {
    
                        p.closeInventory();
                        p.sendMessage(ChatColor.GREEN + "You have equiped a " + sm.getDisplayName());
                        Bukkit.broadcastMessage(ChatColor.RED + "Added Meta - Works");
                        p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 5000000, 4));
                    } else {
                        p.sendMessage(ChatColor.RED + "EEEEEEE");
                        return;
     
  2. Offline

    aztk

    1. use .equals() instead of ==.
    == isn't comparing the values of the object
    2. If you want to call something when you're equipping armor, use something like InventoryDragEvent (answer to your topic of post)
    3. If you want to equip a helmet use
    Code:
    PlayerInventory pi;
    ItemStack helmet;
    
    
    pi.setHelmet(helmet);
     
    Last edited: Apr 16, 2017
Thread Status:
Not open for further replies.

Share This Page