Solved Action.LEFT_CLICK_AIR

Discussion in 'Plugin Development' started by TheFl4me, Mar 10, 2016.

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


    I am currently coding something that would count player clicks.
    Somehow though, this action is not working.

    Any idea why? (Nothing to do with my code, because all I did to test this was make a playerInteractEvent broadcast the action name whenever it is called, and it is never called when I click air)
  2. Offline


    This is a bit confusing.. For me it only worked with an item in the hand.
  3. Offline


    Really? Because I only checked with a emtpy hand, I did not think it would make a difference.

    EDIT: Anybody know a way to do this with emtpy hand?
  4. Offline

    I Al Istannen

  5. Offline


  6. Offline


    No, he needs ignoreCancelled = true.

    @Irantwomiles he just linked an entry in the Javadocs.
  7. Offline

    I Al Istannen

    "If ignoreCancelled is true and the event is cancelled, the method is not called. Otherwise, the method is always called."

    I would translate that to about that:
    if(ignoreCancelled && isCancelled) {
    Me neither. I could swear I read it on the javadocs though. Anyways, it seems to work as i said.

    My Code:
    @EventHandler(ignoreCancelled = true)
    public void onPlayerInteractIgnoreCancelledTrue(PlayerInteractEvent e) {
      System.out.println("PlayerBannedListener.onPlayerInteractIgnoreCancelledTrue(): " + e.getAction());
    @EventHandler(ignoreCancelled = false)
    public void onPlayerInteractIgnoreCancelledFalse(PlayerInteractEvent e) {
      System.out.println("PlayerBannedListener.onPlayerInteractIgnoreCancelledFalse(): " + e.getAction());
    Result while hitting in the air without an item:
    [20:32:37 INFO]: PlayerBannedListener.onPlayerInteractIgnoreCancelledFalse(): LE
    Lordloss and Zombie_Striker like this.
  8. Offline


    Ah okay, was confused by the name. I thought ignoreCancelled implied it would ignore the cancellation of an event, not ignore cancelled events.
  9. Offline

    I Al Istannen

    Yes, I have to check the javadocs every time too. SO annoying. Guess that's what you get for using it so sparingly.
  10. Offline


    I tried both (= false and = true), none of them worked. The event still wasnt called when I clicked the air with an emtpy hand.
  11. Offline


  12. Offline


    @EventHandler(ignoreCancelled = false)
        public void storeClicks(PlayerInteractEvent e) {
  13. Offline


    @I Al Istannen thank you, i learned something.

    @TheFl4me in which gamemode you do this? For me this played a role.
  14. Offline


  15. Offline

    I Al Istannen

    Hmm I copied your code and pasted it. Result:
    Your code.gif

    Are your sure you registered the event?
  16. Offline


    @I Al Istannen

    Oh hey, that's the same Eclipse theme I use :D

    Anyways, would this event still fire if one is left clicking at a solid block with air blocks in between? If not, how can one detect if the player is clicking in the direction of an air block immediately in front of them, even if there is a solid block in range of clicking?
    Last edited: Mar 11, 2016
  17. Offline


    A bit off-topic, but how do you get that eclipse look? :p
  18. Offline


    Ok, somehow its working now even though I didnt change any code.....
    Thanks again everybody for helping.
  19. Offline


    Preferences > General > Theme
  20. Offline


    @AlisiaRose yes it would fire, but it would be LEFT_CLICK_BLOCK instead, which is all the time the case if you "touch" a block with the click.
Thread Status:
Not open for further replies.

Share This Page