Hello, i create a plugin for test. and i want to get the entity whose i interact with…
i want to do an action with the entity, but i want to get it before to do another actions
(sorry for my english, i’m french)
I guess this is what your looking for. But I think this event is missing something tho. Like getClickedEntity() ?
thx, but, how can i do for get the entity? i getClickEntity is doesn’t work…
i have to get cause? or another thing?
Oh yeah indeed. The cause should be the player that clicked.
Maybe try:
@Listener
public void onRightClickEntity(InteractEntityEvent.Secondary event){
System.out.println(event.getTargetEntity());
System.out.println(event.getCause().any(Player.class));
}
That should return something like:
EntityCow@4848
True
The entity that was clicked is event.getTargetEntity()
. To get the player who clicked it, use this code:
if (event.getCause().any(Player.class)) {
Player whoClicked = event.getCause().last(Player.class).get();
} else {
// something other than a player clicked the entity
}
1 Like