Solved Checking for Action.RIGHT_CLICK_AIR

Discussion in 'Plugin Development' started by Kevinzuman22, Dec 18, 2019.

Thread Status:
Not open for further replies.
  1. I am currently trying to have something happen when a player right-clicks with a certain item in their main hand. To check if they right click, I use this:
    Code:
    if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)
    With this, whenever I right-click a block with the item, it works, but not when right-clicking the air. The same with when using left-clicks instead of right-clicks. And even when not even checking for any certain type of Action.

    Has there come an alternative way of doing this, or is this just simply a bug?

    PS: I am developing against Spigot 1.14.4.
     
  2. Offline

    Vassilios

    Try using .equals() instead of ==.
     
  3. Online

    timtower Administrator Administrator Moderator

    @Kevinzuman22 Did you try printing what kind of action you do get?
     
  4. Offline

    KarimAKL

    @Vassilios Enum's equals(Object) method looks like this:
    Code:Java
    1. public final boolean equals(Object other) {
    2. return this==other;
    3. }

    Still, == is prefered over that because it's null safe.
     
  5. It prints when right-clicking a block, but not when right-clicking the air, which would indicate that the PlayerInteractEvent isn't being called when right-clicking the air.
     
  6. Offline

    KarimAKL

  7. That is indeed what I did, but nothing is being printed when either left or right-clicking the air.
    I tried it with this
    Code:
    System.out.print(e.getAction);
     
    Last edited: Dec 19, 2019
  8. Offline

    KarimAKL

    @Kevinzuman22 I've read that PlayerInteractEvent is cancelled by default if you're clicking (left or right, doesn't matter) air; do you have (ignoreCancelled = true) in your @EventHandler?
     
    Strahan and Kevinzuman22 like this.
  9. @KarimAKL I did, and now it works. Thanks a lot!
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page