Hello there,
What i want to do:
Mark a Position with a Wooden Axe.
Problem:
I don’t get the Event on first hit. I need to do a long Left Click to get the Event.
Code:
@Listener
public void onInteractBlockEventPrimaryMainHand(InteractBlockEvent.Primary.MainHand event, @First Player player) {
Member member = memberManager.getMemberByPlayer(player);
member.getSelection().handleInteractBlockEvent(event, player, true);
}
public void handleInteractBlockEvent(InteractBlockEvent event, Player player, Boolean primary) {
BlockSnapshot targetBlock = event.getTargetBlock();
if (targetBlock.getState().getType().equals(BlockTypes.AIR) ) {
return;
}
if (!player.hasPermission("kingdoms.zones.selection") ) {
return; // silently
}
ItemStack itemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!itemStack.getType().equals(ItemTypes.WOODEN_AXE) ) {
return;
}
Optional<Location<World>> optionalWorldLocation = targetBlock.getLocation();
if (!optionalWorldLocation.isPresent()) {
return;
}
Location location = optionalWorldLocation.get();
String corner;
if (primary) {
corner = "1";
setLocation1(location);
} else {
corner = "2";
setLocation2(location);
}
player.sendMessage(Text.of(TextColors.RED, "Point ", corner, ": X : ", location.getBlockX(), " Y : ", location.getBlockY(), " Z : ", location.getBlockZ()));
}
Is there a better Event for that? Or how could i fix the Problem of the Long Press needed on the Left Hand.
The Event works Perfect for the Secondary (Right) click.
Thanks for your Help.