Solved Event Handler - RIGHT_CLICK_AIR and RIGHT_CLICK_BLOCK errors

Discussion in 'Plugin Development' started by eve0021, Apr 27, 2017.

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

    eve0021

    Solved: Found out that you need to check if the item from the main hand is being used.

    Code:
    if(e.getHand()== EquipmentSlot.HAND){
                    if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
                        e.getPlayer().sendMessage("Event triggered");
                    }
                }

    Does have a solution for single trigger click only?

    Code:
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e) {
       try {
         if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
           e.getPlayer().sendMessage("Event triggered");
         }
       } catch (Exception ex) {
         System.out.println("ERROR in onPlayerInteract method;");
         ex.printStackTrace();
       }
    }
    
    Player->looks at air->right clicks->Event Triggers once-> no error
    Player->looks at a block (eye level)->Event Triggers Twince-> no error

    My code seems to trigger twice when I click on a block but not on air?
     
    Last edited: Apr 27, 2017
Thread Status:
Not open for further replies.

Share This Page