Enchanting Items on Command

Discussion in 'Plugin Development' started by ClankyMichael, Jun 4, 2012.

  1. Offline

    ClankyMichael

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Ok so im trying to make a plugin where when you type a command it gives you a certain sword and an enchant with it but i tried everything and i cant seem to find a way to do the enchanting part.

    Here is the code i tried using.

    Code:
    ((Player) sender).getInventory().addItem(new ItemStack(276, 1));
    ((Player) sender).getInventory().getItem(276).addEnchantment(new EnchantmentWrapper(16), 1);
    I'm still kinda new at this so please no hate :)
  2. Offline

    jamietech

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    First you'll need to ensure that the CommandSender is a player otherwise you'll get super fun errors trying to cast the sender to a player. Note that when getting the item it uses the item slot not the item ID so you'll have to check that they're holding the item. Probably best to move the item in their hand (if any) to a free slot or tell them off for not having a free slot, then put the item there with player.setItemInHand(ItemStack); and add an enchant with player.getItemInHand().addEnchantment(Enchantment enchantment, int level);
  3. Offline

    ClankyMichael

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    it says player can not be resolved to a variable
  4. Offline

    ClankyMichael

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    nvm i already fixed my problem

Share This Page