Hello I am just starting on the development of sponge plugins.
I am trying to do something on right clicking an entity, though I can’t figure out how to differ left from right clicking.
My code:
@Listener
public void onRightClick(InteractEntityEvent event) {
if (event.getCause().last(Player.class) != null) {
Player player = event.getCause().last(Player.class).get();
if (isSneaking(player)) {
player.sendMessage(Text.of("Works"));
}
}
}
private boolean isSneaking(Player player) {
return player.get(Keys.IS_SNEAKING).orElse(false);
}
But if I punch an entity it still counts as an interaction, is there anyway to check if the interaction is made with right click only?
Cheers.