give with Enchantment Help

Discussion in 'Plugin Development' started by adri49400, Jan 15, 2013.

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

    adri49400

    Hello,

    I tried that same bit of code of the bukkit API to add an item with a specific sort of enchantment but when I send my command, nothing happens :confused:

    Code:
    for (Player p2 : plugin.getServer().getOnlinePlayers())
                                    {
                                        p2.sendMessage(ChatColor.GREEN + "GIVE! ");
     
                                        int itemCode = 280;  //use the item code you want here
                                        int effectId = 20;  //use the enchantment code you want here
                                        int enchantmentLevel = 10;
                                        ItemStack stack1 = new ItemStack(itemCode);  //new item of item code
                                        Enchantment myEnchantment = new EnchantmentWrapper(effectId);  //new enchantment of effect id
                                        stack1.addEnchantment(myEnchantment, enchantmentLevel);  //enchant the item
                                     
                                        p2.getInventory().addItem(stack1); // ajoute les ItemStack à l'inventaire
                                        p2.updateInventory(); // met à jour l'inventaire graphiquement côté client
                                    }
    Thx :)
     
  2. Offline

    fireblast709

    try addUnsafeEnchantment(Enchantment, int), as the level is too high
     
  3. Offline

    adri49400

    I add your code juste after this :
    Enchantment myEnchantment = new EnchantmentWrapper(effectId);

    ?
     
  4. Offline

    fireblast709

    my line basically replaces addEnchantment(Enchantment, int)
     
  5. Offline

    adri49400

    Hooo ok sorry ! :) I'll try this evening.

    Thank a lot

    It's Work !!! THX :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page