How Do I Register A Listener For A Right-Click w/ Sword In Hand Event

Discussion in 'Plugin Development' started by mkezar, Mar 17, 2014.

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

    mkezar

    hi. I was wondering How Do I Register A Listener For A Right-Click w/ Sword In Hand Event? Thanks.

    -mkezar
     
  2. Offline

    Dubehh

    mkezar
    Code:java
    1. @Eventhandler
    2. public void onSwordClick(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4.  
    5. if(event.getAction == Action.RIGHT_CLICK_AIR || event.getAction == Action.RIGHT_CLICK_BLOCK){
    6. if(player.getItemInHand() == Material.IRON_SWORD){
    7. // code
    8. }else{
    9. return
    10. }
    11. }


    Something like that :)
     
  3. Offline

    alex123099

    mkezar
    PlayerInteractEvent
    then check if the action is a right click and if the item in hand is a sword
     
  4. Offline

    mkezar

    Dubehh i got the error Incompatible operand types ItemStack and Material for this line of your code:

    (player.getItemInHand() == Material.IRON_SWORD)

    Any way on how to fix this?

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

    travja

    mkezar Use player.getItemInHand().getType()== Material.IRON_SWORD, the way you have it is comparing an itemstack to a material. Not the same thing.
     
  6. Offline

    mkezar

    travja Thank you very much!!! :D Im happy now :)
     
  7. Offline

    Dubehh

Thread Status:
Not open for further replies.

Share This Page