Solved PlayerInteractEvent sent twice

Discussion in 'Spigot Plugin Development' started by RekTek249, Feb 22, 2020.

Thread Status:
Not open for further replies.
  1. Hi, I'm somewhat new to the spigot API, so I might have missed something. I want something to happen when the player right clicks in a specific condition. For now, let's forget about the item in hand. Here's what I got:
    Code (Java):
    Action a = event.getAction();
    Player p = event.getPlayer();
    if(a != Action.RIGHT_CLICK_AIR && a != Action.RIGHT_CLICK_BLOCK) return;
    if(event.getHand() != EquipmentSlot.HAND) return;
    p.sendMessage("Player right clicked!");
    There's a bit more to it than that, but they're unrelated checks. In-game, when I right click, (currently doesn't work on air for some reason) it gets fired twice. I'm only registering it once (tested with constructor logging). Am I missing something?
  2. Could be the way you are comparing actions. Try using !a.equals(RIGHT_CLICK_AIR) instead of a != RIGHT_CLICK_AIR. Same for you other action
  3. Maybe because the player interacts with both hands?
  4. SteelPhoenix


    Doesn't matter and for comparing enum values one should stick to == as it's (slightly) more efficient and is null safe.
  5. Tried it just in case, but doesn't change anything. I doubt there's any difference between == and equals() when comparing enums.
  6. Already have a check for that
    Code (Java):
    event.getHand() != EquipmentSlot.HAND
  7. Apparently making a check for Action.PHYSICAL was needed.
    • Winner Winner x 1
Thread Status:
Not open for further replies.