Get InteractionEvent block location?

The InteractionEvent#InteractionPoint is giving me where on the block I click when trying to place a block.
When breaking one, it gives me the location of the block.
Is there any way to always get the location of the block you interacted with, instead of where on the block?


I wish.
I’m on API 6 and don’t see that.
I figured I can do .get(“HitTarget”, BlockSnapshot.class) on the cause.

Uh, it’s right in the docs. TargetBlockEvent#getTargetBlock, and InteractBlockEvent extends this.

I can only get it out of the Cause.

InteractEvent is not what you’re looking for; it’s InteractBlockEvent. InteractEvent is just a common superclass for every single type of interaction.

I’m only using it temporarily to protect islands in my plugin until I finish every event listener.

But what are you trying to listen for? If you’re listening for block interaction, then you would use InteractBlockEvent. InteractEvent is pretty meaningless on its own. And InteractBlockEvent is the one with getTargetBlock.

It’s just me temporarily cutting corners. It just listens for every interact event. Then it checks if it’s a block interaction event by looking in the cause for HitTarget. If that isn’t present then it uses the InteractionPoint.
Then the plugin checks if that location is an island and if they have permission to interact…and so on.

Pretty soon I’ll change it to listen for every event from block interactions to opening a mule’s inventory, all toggle-able from the config file, but for now I’m just giving quick, and simple protection to islands.

Or, you could check if it’s a block interaction event by checking instanceof InteractBlockEvent. And then cast it to InteractBlockEvent and call getTargetBlock.

It’s like saying Object foo = "hello world", and then wondering why foo.split(" ") won’t compile.

You’re right. There’s plenty of ways to do it, but this way already works, so I can’t change it until I do the new system.