Solved PlayerInteractEvent on Air

Discussion in 'Plugin Development' started by number1_Master, Nov 7, 2012.

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

    number1_Master

    I am having HUGE issues with this. For my plugin Thor, I added Thor's hammer long ago. It worked fine, of course. Recently, since the American Football season came to an end, I have had more time to develop things. I started with a rewrite of Thor.
    When I finished the rewrite, I went to test it all out. A few minor bugs here and there I fixed. Unfortunately, I ran into one huge, head aching bug. I seriously have a headache from it. This is the bug: Under the PlayerInteractEvent, I cannot check for Action.LEFT_CLICK_AIR (or right click). It worked before, why not now?

    Craftbukkit version: git-Bukkit-1.4.2-R0.2-b2455jnks (MC: 1.4.2) (Implementing API version 1.4.2-R0.2)
    Other plugins: NONE! You really thought I would have other plugins! Pfft! :D
    This is The Code I used to test if Action.LEFT_CLICK_AIR was being called (and right click):
    Code:java
    1. @EventHandler(ignoreCancelled = true)
    2. public void onPlayerClick(PlayerInteractEvent e)
    3. {
    4. if(e.getAction() == Action.LEFT_CLICK_AIR) System.out.println("Clicked Air!");
    5. if(e.getAction().equals(Action.LEFT_CLICK_AIR)) System.out.println("Clicked Air!");
    6. if(e.getAction() == Action.RIGHT_CLICK_AIR) System.out.println("Clicked Air!");
    7. if(e.getAction().equals(Action.RIGHT_CLICK_AIR)) System.out.println("Clicked Air!");
    8. }

    None of those lines of code brought up anything. If I wrote Action.LEFT_CLICK_BLOCK (or right click), the action did apear.

    Is this a Craftbukkit bug, or is it just me?

    I have also read (on other posts) that the computer is preventing this. For some, it works on other computers. I find this unusual. I have also read Bukkit has been canceling the even. !? I'm stumped!

    Thank you for the help!
     
  2. Offline

    Malikk

    The event is cancelled before it is even sent to plugins for all playerInteract 'clicks on air'. You're using the annotation ignoreCancelled, so those events are never sent to you.

    I would suggest doing a regular event.isCancelled() && event.isNotAClickOnAir. (Psuedo code obviously, lol) Thats the only way to determine whether or not a plugin has cancelled the event.
     
  3. Offline

    number1_Master

    Thank you! You solved my issue!

    I thought ignoreCancelled only was called when the event was cancelled. Why would bukkit cancel the event?
     
  4. Offline

    Malikk

    I'm not sure. It doesn't make a whole lot of sense, that's just how it is and has been for a long time.
     
    number1_Master likes this.
Thread Status:
Not open for further replies.

Share This Page