Solved Right Click Air not working?

Discussion in 'Plugin Development' started by gamerzap, Sep 30, 2012.

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

    Malikk

    I know this is getting old, but I'm still having the same issue.

    Vandrake gamerzap

    Using only this code, with no other plugins...
    Code:
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event){
            plugin.LogMessage("-----PlayerInteract-----");
            plugin.LogMessage("Action Type: " + event.getAction().name());
            plugin.LogMessage("Holding: " + event.getPlayer().getItemInHand().getType().name());
            plugin.LogMessage("Cancelled: " + event.isCancelled());
        }
    
    It outputs like this
    Show Spoiler

    18:31:26 [INFO] [MobCatcher] -----PlayerInteract-----
    18:31:26 [INFO] [MobCatcher] Action Type: RIGHT_CLICK_AIR
    18:31:26 [INFO] [MobCatcher] Holding: COOKIE
    18:31:26 [INFO] [MobCatcher] Cancelled: true
    18:31:37 [INFO] [MobCatcher] -----PlayerInteract-----
    18:31:37 [INFO] [MobCatcher] Action Type: LEFT_CLICK_BLOCK
    18:31:37 [INFO] [MobCatcher] Holding: COOKIE
    18:31:37 [INFO] [MobCatcher] Cancelled: false
    18:31:38 [INFO] [MobCatcher] -----PlayerInteract-----
    18:31:38 [INFO] [MobCatcher] Action Type: RIGHT_CLICK_BLOCK
    18:31:38 [INFO] [MobCatcher] Holding: COOKIE
    18:31:38 [INFO] [MobCatcher] Cancelled: false
    18:31:41 [INFO] [MobCatcher] -----PlayerInteract-----
    18:31:41 [INFO] [MobCatcher] Action Type: LEFT_CLICK_AIR
    18:31:41 [INFO] [MobCatcher] Holding: COOKIE
    18:31:41 [INFO] [MobCatcher] Cancelled: true
    18:31:52 [INFO] [MobCatcher] -----PlayerInteract-----
    18:31:52 [INFO] [MobCatcher] Action Type: RIGHT_CLICK_AIR
    18:31:52 [INFO] [MobCatcher] Holding: MONSTER_EGG
    18:31:52 [INFO] [MobCatcher] Cancelled: true
    18:31:54 [INFO] [MobCatcher] -----PlayerInteract-----
    18:31:54 [INFO] [MobCatcher] Action Type: LEFT_CLICK_AIR
    18:31:54 [INFO] [MobCatcher] Holding: MONSTER_EGG
    18:31:54 [INFO] [MobCatcher] Cancelled: true
    18:31:57 [INFO] [MobCatcher] -----PlayerInteract-----
    18:31:57 [INFO] [MobCatcher] Action Type: LEFT_CLICK_BLOCK
    18:31:57 [INFO] [MobCatcher] Holding: MONSTER_EGG
    18:31:57 [INFO] [MobCatcher] Cancelled: false
    18:31:58 [INFO] [MobCatcher] -----PlayerInteract-----
    18:31:58 [INFO] [MobCatcher] Action Type: RIGHT_CLICK_BLOCK
    18:31:58 [INFO] [MobCatcher] Holding: MONSTER_EGG
    18:31:58 [INFO] [MobCatcher] Cancelled: false


    So all playerInteract events on air are cancelled before they are sent to any plugins. How are we supposed to determine whether or not another plugin is wanting to cancel this event?

    gamerzap Did you really not have to change anything at all to fix this? I've had this problem very consistently for months and I've not been able to find a solution.
     
  2. Offline

    Vandrake

    whats the problem?XD Can't remember this. What are you tryign to do?
     
  3. Offline

    gamerzap

    Well, I did change one thing, but I just fixed a faulty line of code, which didn't solve my problem until I removed some lag too. I don't know why your's is getting cancelled, do you have any other plugins?
     
  4. Offline

    Malikk

    I need to be able to distinguish when another plugin cancels playerInteract, but clicks on air are starting off cancelled.

    No, this is the only plugin on my server atm, and I'm not cancelling any playerInteracts myself.

    Perhaps this is just how it's supposed to be? Is this a normal behavior for PlayerInteract?
     
  5. Offline

    Cirno

    I know I see the Solved tag, but if I remember correctly, Bukkit events can now bypass the whole cancelled thing. using @EventHandler(ignoreCancelled=true) I think.
     
  6. Offline

    Malikk

    I know that, but that doesn't really help. I need to be able to determine whether another plugin has cancelled the event or whether bukkit has cancelled the event.
     
  7. Offline

    Cirno

    https://github.com/Bukkit/Bukkit/bl.../bukkit/event/player/PlayerInteractEvent.java
    Looking there, I didn't see anything about cancelling the event itself. Just set up a localhost server, export your plugin into that and start it up. See if it works or not.
     
  8. Offline

    Malikk

    I'm already testing this on a local server. It's the only plugin and playerInteract for clicks on air are cancelled before they get to my plugin. I'm just trying to figure out if this is a normal behavior because I can't make any sense of it.
     
  9. Offline

    gamerzap

    Hmmm... I have no idea. It might be something unrelated on your computer, but I doubt it... I just don't know...
     
  10. Offline

    Derthmonuter

    Malikk gamerzap Vandrake nisovin

    I'm getting the same exact problem as Malikk here is. I need to listen to left clicks on air with a written book. Works like a charm when clicking anything but air, where I get a NullPointerException. It's frustrating beyond belief, and it looks like the event is getting cancelled even though it shouldn't--why do we even have the ability to check if air is involved in the event if it only leads to immediate cancellation?

    Since gamerzap with Vandrake's code has seemed to fix this problem, I would much appreciate it if he could post a snippet here for me to see. As for Malikk, he was in the same boat as me, so if you've found anything out Malikk I'd love to see it. :) As for nisovin, you've never failed to help me before, so mind tossing in some advice?
     
  11. Offline

    desht

    RIGHT/LEFT_CLICK_AIR blocks arriving cancelled by default is by design, although I'd argue it's a poor design, since as stated before, it makes it very hard to know if the event was cancelled at construction time or by another plugin.

    To see why, look at the PlayerInteractEvent constructor, in particular this line of code:
    PHP:
    useClickedBlock clickedBlock == null Result.DENY Result.ALLOW
    and these methods:
    PHP:
    public boolean isCancelled() {
        return 
    useInteractedBlock() == Result.DENY;
    }
     
    public 
    void setCancelled(boolean cancel) {
            
    setUseInteractedBlock(cancel Result.DENY useInteractedBlock() == Result.DENY Result.DEFAULT : useInteractedBlock());
            
    setUseItemInHand(cancel Result.DENY useItemInHand() == Result.DENY Result.DEFAULT : useItemInHand());
    }
    In other words, this event conflates the event's block-interact action (ALLOW/DENY) with the cancelled status of the event.

    Update: if event.useItemInHand() returns Result.ALLOW or Result.DEFAULT even when the event is cancelled, I believe that should indicate that the event arrived cancelled-by-default, and wasn't cancelled by another plugin.
     
    1mpre55 likes this.
  12. Offline

    AVOCARDO

    Just a quicky to an old one. Maybe you could look for left click air? instead of right click air. The PlayerInteractEvent will pick that up...

    R

    AVO
     
  13. Offline

    gamerzap

    It picks up both for me.
     
  14. Offline

    moo3oo3oo3

    I feel you bro. People are posting pretty much the same answer every time
     
  15. Offline

    Skionz

    Googlelover1234 likes this.
Thread Status:
Not open for further replies.

Share This Page