Is it possible to make an item equipable like an armor ?

Discussion in 'Spigot Plugin Development' started by Froyzz, Jun 4, 2016.

  1. Hi guys !,
    I want to make a compass equipable like a hat, i did when the player do a right click on the air or on a block it equip the compass, but is it possible to make when the player is in his inventory, he can move the compass into the hat slot ?
    Thank you :)
     
  2. Listen for inventory click event,
     
  3. No, because a compass isn't a valid helmet. Think about it, every hat plugin has to use a command to equip your hat. If they could let you drag it into the helmet slot, I'm fairly sure that's what they would use
     
  4. Hmm, so is it posisble or not ahah ?
    ProjJoosh said yes and Redrield not :x
     
  5. It is possible to set items into slots that they shouldn't be in, but the items won't really do anything unless you're manually checking for the specific item on events. Also note that most items set in the helmet slot will show on the player's model even if it isn't supposed to.

    Just call PlayerInventory#setHelmet to set the item, and PlayerInventory#getHelmet to retrieve it.
     
    • Winner Winner x 1
  6. Thanks i did it, and is it possible to check if the player is trying to place an item in the armor slots ?
     
  7. Inkzzz

    Resource Staff

    Yes, Inventory Click Event, just get the type of inventory, and slot id and work from there.
     
    • Agree Agree x 1
  8. Thanks ! i did that:
    Code (Text):
                            if (event.getCursor().getType() == Material.COMPASS){
                                 ItemStack compass = new ItemStack(Material.COMPASS);
                                    ItemMeta compassM = compass.getItemMeta();
                                    compassM.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 10, true);
                                    compassM.addEnchant(Enchantment.PROTECTION_EXPLOSIONS, 10, true);
                                    compassM.addEnchant(Enchantment.PROTECTION_FIRE, 10, true);
                                    compassM.addEnchant(Enchantment.PROTECTION_PROJECTILE, 10, true);
                                    compass.setItemMeta(compassM);
                                    p.setItemOnCursor(null);
                                    p.getInventory().setHelmet(compass);
    But why when i place my compass on my helmet slot, it does nothing ?
    I thinks that's because if (event.getCursor().getType() == Material.COMPASS){ doesn't works cause there's p.setItemOnCursor(null); but, how can i remove the item in the cursor after i click on the helmet slot ?