ItemInHand not detecting?

Discussion in 'Plugin Development' started by xigsag, Aug 2, 2013.

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

    xigsag

    .getItemInHand() only detects items at full durability.

    I am trying to change the damage value of a custom weapon.
    I don't know if there are any better ways to change damage values, but I'm guessing not.

    By using EntityDamageByEntityEvent, I did .setDamage(4); after detecting that what the player had in his/her
    hand was that custom weapon. But it only damaged once when it was full durabilty, and not do any damage afterwards.

    I've tried setting the durability of the weapon to full after every hit, but it works occasionally. I've also done up a BukkitTask that runs 1 second after the hit, to see if it's actually regenning the durability.

    All I need is to set this exact weapon's damage to this exact damage value. If possible, cancelling the damage event of any other item, so that the player can only damage mobs when the item in his/her hand is a weapon. (Wood-Diamond Sword, Wood-Diamond Axe);

    help plox
     
  2. Offline

    Tarestudio

    xigsag
    how do you check the item in hand?
     
  3. Offline

    xigsag

    Tarestudio
    Code:java
    1. player.getItemInHand()
    2.  
    3. //or
    4.  
    5. player.getInventory().getItemInHand()
     
  4. Offline

    historio

    xigsag I think its this one.

    Code:java
    1. player.getInventory().getItemInHand()
     
  5. Offline

    xigsag

    historio
    inb4, I already know what the method is to get the item in the player's hand. The thing is, it only detects it if its at full durability.
    Code:java
    1. p.getInventory.getItemInHand();
    2. // and
    3. p.getItemInHand();
    4.  
    5. // work pretty much the same btw.
    6.  
    7. // let's say i want to check if the item in the player's
    8. // hand is the item "Excalibur()".
    9.  
    10. if(p.getItemInHand.equals(Excalibur())){
    11. e.setDamage(4);
    12. }else{
    13. e.setCancelled(true);
    14. }


    That only detects when Excalibur() is at full durability.
     
  6. Offline

    Tarestudio

    xigsag
    Well i think a ItemsStack only equals if its data equals as well. Durability is saved as data, so your Exkalibur() is always at full durability, the item in hand not.
    Change your check to equal Type/Material and needed metadata.
     
  7. Offline

    xigsag

    Tarestudio
    Well shit, I forgot I could check for
    Code:java
    1. p.getItemInHand().getItemMeta().equals(Excalibur().getItemMeta());

    Thanks!

    Alright, now that I've got that check working, how do I check if the item in hand is not empty? Because it gives me an error every time I try to check for an empty hand's meta data, which obviously isn't going to work.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  8. Offline

    Samthelord1

    !p.getiteminhand null bla bla
     
  9. Offline

    xigsag

Thread Status:
Not open for further replies.

Share This Page