Solved Action.LEFT_CLICK_AIR

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

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

    TheFl4me

    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

    Lordloss

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

    TheFl4me

    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

    Irantwomiles

  6. Offline

    HoeMC

    No, he needs ignoreCancelled = true.

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

    I Al Istannen

    @HoeMC
    "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:
    Code:
    if(ignoreCancelled && isCancelled) {
      return;
    }
    @Irantwomiles
    Me neither. I could swear I read it on the javadocs though. Anyways, it seems to work as i said.

    My Code:
    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:
    Code:
    [20:32:37 INFO]: PlayerBannedListener.onPlayerInteractIgnoreCancelledFalse(): LE
    FT_CLICK_AIR
     
    Lordloss and Zombie_Striker like this.
  8. Offline

    HoeMC

    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

    @HoeMC
    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

    TheFl4me

    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

    Zombie_Striker

  12. Offline

    TheFl4me

    Code:
    @EventHandler(ignoreCancelled = false)
        public void storeClicks(PlayerInteractEvent e) {
            Bukkit.broadcastMessage(e.getAction().toString());
        }
     
  13. Offline

    Lordloss

    @I Al Istannen thank you, i learned something.

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

    TheFl4me

    Survival
     
  15. Offline

    I Al Istannen

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

    Are your sure you registered the event?
     
  16. Offline

    AlisiaRose

    @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

    Rowinvd

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

    TheFl4me

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

    GamerzKing

    Preferences > General > Theme
     
  20. Offline

    Lordloss

    @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