1.15.2 BlockBreakEvent called twice

Discussion in 'Spigot Plugin Development' started by AtomicZombies, Apr 4, 2020.

  1. I'm making a lucky blocks plugin and I've found that whenever I break a lucky block, I the BlockBreakEvent is called twice, neither of them are cancelled.

    A number of events, like the PlayerInteractEvent are called twice, once for the main hand and once for the offhand (Which, to me seems pretty dumb, they should be separated into multiple events that extend the PlayerInteractEvent). In this event's case, the solution is easy:
    Code (Java):
    if(event.getHand() == EquipmentSlot.OFF_HAND) return;
    I assume this is the issue because breaking a block is similar to interacting with a block.

    But the BlockBreakEvent doesn't have a method to get the hand, most likely since only the mainhand can break blocks.

    I've tried using cooldowns, but that caused other issues.
  2. Did you register it twice, perhaps? I sometimes need both BlockBreakEvent and BlockPlaceEvent and since my listeners are named to represent the even they listen to, I sometimes copy/paste the registering part, but forget to replace Break with Place ^^
  3. No, I didn't register the event twice. I think I've done enough debugging to rule out stupid mistakes, but there is still that chance.
  4. Is there anything new on this topic? After upgrading from 1.16.1 to 1.16.2 I encountered the same problem
  5. Maybe you can try that?
    Code (Text):
    if(event.getPlayer().getInventory().getItemInOffHand().getType() == null || event.getPlayer().getInventory().getItemInOffHand().getType() == Material.AIR) return;
  6. Well, it turned out that I had accidentally deleted the @Singleton notation from the class during the upgrade... So there were several instances of the listeners, which were registered :)

    But thanks anyway