For all types of interaction, there’s InteractEvent
. If you want all block interactions, see InteractBlockEvent
and for entities, InteractEntityEvent
.
Because these events are not player specific, you have to see what caused the event to fire in the first place.
If you’re only interested in player-caused events, do something like this:
@Listener
public void onInteractBlock(InteractBlockEvent event) {
Optional<Player> optPlayer = event.getCause().first(Player.class);
if (!optPlayer.isPresent()) {
return; // Don't care about non-player caused events
}
Player player = optPlayer.get();
// Do something here
}