Solved Interact event (block click) triggers twice

Discussion in 'Spigot Plugin Development' started by MrDienns, May 17, 2017.

  1. Hi Spigletators

    I have a very simple event handler filtering out when a player clicks on a block.
    Code below:
    Code (Text):
    @EventHandler
    public void onBlockClick(PlayerInteractEvent e){
        if(!(e.getAction().equals(Action.RIGHT_CLICK_BLOCK) ||
                e.getAction().equals(Action.LEFT_CLICK_BLOCK))) return;
        e.getPlayer().sendMessage("test");
    }
    This event triggers twice though. Screenshot: http://prntscr.com/f9054g
    Version: http://prntscr.com/f90cfb

    Got any leads on this? This seems really weird.
     
  2. I might be wrong, but could this be because of 1.11 having two "interactive slots", the off hand item and the on hand itemstack? Just a thought, maybe you can check this by printing out the type of interact event.
     
    • Useful Useful x 1
  3. @xTimPugz is correct check if the e.getHand() == EquipmentSlot.Hand
    or something like that.
     
  4. Thanks for the tips. I tried the suggestion and this is a simple echo result of the following code:
    Code (Text):
        @EventHandler
    public void onBlockClick(PlayerInteractEvent e){
        if(!(e.getAction().equals(Action.RIGHT_CLICK_BLOCK) ||
                e.getAction().equals(Action.LEFT_CLICK_BLOCK))) return;
        e.getPlayer().sendMessage(e.getAction().toString());
        e.getPlayer().sendMessage(e.getHand().name());
    }
    Result: http://prntscr.com/f90pxx

    I guess you guys were correct. I'll simply have to make sure only the main hand event triggers I guess. Kinda stupid if you ask me, but hey, that'll solve my issue. Thanks! :D