Adding enchants to items

Discussion in 'Plugin Development' started by XxZHALO13Xx, Jun 26, 2015.

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

    XxZHALO13Xx

    How do u add enchants to items? i created a method to add items to a player when he does a command

    Code:
    public void add1(Player p, ItemStack itemStack, ItemMeta itemMeta){
            p.getInventory().addItem(new ItemStack(Material.DIAMOND_BOOTS));
            p.getInventory().addItem(new ItemStack(Material.DIAMOND_LEGGINGS));
            p.getInventory().addItem(new ItemStack(Material.DIAMOND_CHESTPLATE));
            p.getInventory().addItem(new ItemStack(Material.DIAMOND_HELMET));
            p.getInventory().addItem(new ItemStack(Material.DIAMOND_BOOTS));
        }
     
  2. Offline

    MCMatters

    @XxZHALO13Xx ItemMeta#addEnchantment or something similar
     
  3. Offline

    XxZHALO13Xx

    @MCMatters

    Code:
     p.getInventory().addItem(new ItemStack(Material.DIAMOND_HELMET).
            getItemMeta().addEnchant(new Enchantment.PROTECTION_ENVIRONMENTAL, 3));
    It says cannot find symbol PROTECTION_ENVIROMENTAL.
     
  4. Offline

    MCMatters

    you are trying to initialize a Enum? Learn how to use Enums and Constructors and you will solve this.
     
  5. Offline

    XxZHALO13Xx

    @MCMatters i used to know how to do this, but i stopped plugins for a long time and i just am getting back into it. Could u please help?
     
  6. Offline

    MCMatters

    @XxZHALO13Xx i am helping, read javadocs and the docs on Enums and Constructors, read them and tell me when your done. When you are done, tell me the syntax of an Enum and a Constructor and ill help you if you are still stuck
     
  7. Offline

    nj2miami

    Remove 'new' from 'new Enchantment....' I don't see why @MCMatters could not simply tell you that.
     
Thread Status:
Not open for further replies.

Share This Page