Solved PlayerInteractEvent fires twice?

Discussion in 'Plugin Development' started by SirLollington, Jun 28, 2017.

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

    SirLollington

    I'm having an issue where an event handler for the PlayerInteractEvent fires twice on a single interaction.

    Here's my code:
    [​IMG]

    Here's what happens when I right click a block once:
    [​IMG]

    I've checked all things I thought of that could be causing the issue (Accidentally calling onBlockUse from somewhere else, registering events twice, creating 2 objects of the event handler class) and none of these are the case.

    I'm using CraftBukkit version git-Bukkit-753a8e7 (MC: 1.12) on my test/development server.

    Is there some oversight on my end or is this a bug?

    I'm using this event to send a message to the player clicking the block, and it's kind of jarring to have two identical messages pop up when I only right clicked once.
     
  2. Online

    timtower Administrator Administrator Moderator

    @SirLollington It does run twice.
    Once for the main hand.
    Once for the offhand.
    There is a getHand() method I believe.
     
    SirLollington likes this.
  3. Offline

    SirLollington

    Yup, there is. I was under the impression that it would only fire once and I'd get the item in hand/offhand myself.
    Anyways, I added an additional check for the hand, and now I only get one message. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page