diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/listener/ItemEventListener.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/listener/ItemEventListener.java index 225c4187b..9c1d62e4c 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/listener/ItemEventListener.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/listener/ItemEventListener.java @@ -73,11 +73,6 @@ public class ItemEventListener implements Listener { Object blockState = BlockStateUtils.blockDataToBlockState(blockData); ImmutableBlockState immutableBlockState = null; int stateId = BlockStateUtils.blockStateToId(blockState); - Item itemInHand = serverPlayer.getItemInHand(hand); - - Optional> optionalCustomItem = itemInHand == null ? Optional.empty() : itemInHand.getCustomItem(); - boolean hasItem = itemInHand != null; - boolean hasCustomItem = optionalCustomItem.isPresent(); // 处理自定义方块 if (!BlockStateUtils.isVanillaBlock(stateId)) { @@ -98,6 +93,7 @@ public class ItemEventListener implements Listener { event.setCancelled(true); return; } + // run custom functions CustomBlock customBlock = immutableBlockState.owner().value(); PlayerBlockActionContext context = PlayerBlockActionContext.of(serverPlayer, new BukkitBlockInWorld(block), ContextHolder.builder() @@ -112,6 +108,11 @@ public class ItemEventListener implements Listener { else customBlock.execute(context, EventTrigger.LEFT_CLICK); } + Item itemInHand = serverPlayer.getItemInHand(hand); + Optional> optionalCustomItem = itemInHand == null ? Optional.empty() : itemInHand.getCustomItem(); + boolean hasItem = itemInHand != null; + boolean hasCustomItem = optionalCustomItem.isPresent(); + // interact block with items if (hasItem && action == Action.RIGHT_CLICK_BLOCK) { Location interactionPoint = Objects.requireNonNull(event.getInteractionPoint(), "interaction point should not be null");