[SOLVED] Giving players Enchanted weapons.

Discussion in 'Plugin Development' started by Ctex, May 1, 2012.

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

    Ctex

    A quick question, how do i give a player an enchanted weapon? Eg.

    Code:
    inv.addItem(new ItemStack(Material.BOW, 1));
    Making that Bow have Power V
     
  2. Offline

    Kierrow

    There you go. (Should work, haven't tested it...)

    Code:
    ItemStack item = new ItemStack(Material.BOW, 1);
     
    item.addEnchantment(Enchantment.POWER, 5);
     
    inv.addItem(item);
    Hope this helps.

    Okay, I'm sorry, its not Enchantment.POWER.

    Check here to find the correct one, but its probably Enchantment.ARROW_DAMAGE

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
    Ctex likes this.
  3. Offline

    Ctex

    Just tested it out and it works like a charm, thx a lot for your help :)

    And to anyone whom might been interrested here is the code:

    For normal and safe enchants that follows the normal enchanting levels its:

    Code:
    Player player = (Player) sender;
    PlayerInventory inv = (PlayerInventory) player.getInventory();
     
    ItemStack item = new ItemStack(Material.BOW, 1);
    item.addEnchantment(Enchantment.ARROW_KNOCKBACK, 2);
    inv.addItem(item);

    And for unsafe enchants like 20+ Power on a bow its:

    Code:
    Player player = (Player) sender;
    PlayerInventory inv = (PlayerInventory) player.getInventory();
     
    ItemStack item = new ItemStack(Material.BOW, 1);
    item.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 20);
    inv.addItem(item);
    Again, thanks Kierrow for your help :)
     
    nicholasntp and Kierrow like this.
Thread Status:
Not open for further replies.

Share This Page