How do I find what player interacted with InteractBlockEvent?

There is no method for determining it in sponge API 3.0.0. I’m trying to detect when a player is clicking a sign. I can get the BlockSnapshot, which is okay but not as good as just the location, but I dont have a reference to the player. What can I do?

Wait, I just remembered there’s a page in the doc about Event Causes. Seems like it may answer my question

Mark as solved if it answered your question.

Also, for future reference of people trying to find the solution to this as well, please include how with a code sample, it helps others not having to search and re-post the same question :wink:

1 Like

For future reference:

@Listener
public void onEvent(InteractBlockEvent event) {
  Optional<Player> player = event.getCause().first(Player.class);
}

Or if you’re only wanting to handle player interactions:

@Listener
public void onEvent(InteractBlockEvent event, @First Player player) {
    //do something with the player
}
3 Likes

How does mark solved?