Item Dura working with enchantments

Discussion in 'Plugin Development' started by boomboompower, Sep 4, 2015.

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

    boomboompower

    Basically what im trying to do is make it in my plugin that if the player has the enchantment "Unbreaking" or Enchantment.DURABILITY it doesn't just take 1 durability off the item I am holding. The reason I need this is because I have a block break event that cancels when a player goes to break a block unless its a ore, if its an ore it takes 1 dura off the item the player is holding. I need it to work with the Unbreaking enchantment, can anyone please help?
     
  2. Offline

    teej107

  3. Offline

    boomboompower

    I have done this in one of the events:
    Code:
    if (dp.containsEnchantment(Enchantment.DURABILITY)) {
                    dp.setDurability((short) (d + 0.5));
    
    "d" is:
    Code:
    short d = p.getItemInHand().getDurability();
    
    "dp" is:
    Code:
    ItemStack dp = p.getItemInHand();
    
    and yes, I know you can't get half durability but I was just testing.
     
  4. Offline

    teej107

    @boomboompower you need to set the durability in a scheduled task since the BlockBreakEvent is fired before the actual block breaking.
     
    boomboompower likes this.
  5. Offline

    boomboompower

    Yes I know I can find info about it here: http://wiki.bukkit.org/Scheduler_Programming
    But which one would I use (I haven't used scheduler in a plugin before) thx for the help so far :)
     
  6. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page