9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-04 15:41:38 +00:00

Update ItemEventListener.java

This commit is contained in:
halogly
2025-07-18 14:47:32 +08:00
parent 774a9a9207
commit 8a970fa2f3

View File

@@ -77,18 +77,17 @@ public class ItemEventListener implements Listener {
if (ItemUtils.isEmpty(itemInHand)) return; if (ItemUtils.isEmpty(itemInHand)) return;
Optional<CustomItem<ItemStack>> optionalCustomItem = itemInHand.getCustomItem(); Optional<CustomItem<ItemStack>> optionalCustomItem = itemInHand.getCustomItem();
if (optionalCustomItem.isEmpty()) return; if (optionalCustomItem.isEmpty()) return;
if (InteractUtils.isEntityInteractable(player, entity, itemInHand)) return;
if (!InteractUtils.isEntityInteractable(player, entity, itemInHand)) { Cancellable cancellable = Cancellable.of(event::isCancelled, event::setCancelled);
Cancellable cancellable = Cancellable.of(event::isCancelled, event::setCancelled); PlayerOptionalContext context = PlayerOptionalContext.of(serverPlayer, ContextHolder.builder()
PlayerOptionalContext context = PlayerOptionalContext.of(serverPlayer, ContextHolder.builder() .withOptionalParameter(DirectContextParameters.ITEM_IN_HAND, itemInHand)
.withOptionalParameter(DirectContextParameters.ITEM_IN_HAND, itemInHand) .withParameter(DirectContextParameters.EVENT, cancellable)
.withParameter(DirectContextParameters.EVENT, cancellable) .withParameter(DirectContextParameters.POSITION, LocationUtils.toWorldPosition(event.getRightClicked().getLocation()))
.withParameter(DirectContextParameters.POSITION, LocationUtils.toWorldPosition(event.getRightClicked().getLocation())) .withParameter(DirectContextParameters.HAND, hand)
.withParameter(DirectContextParameters.HAND, hand) );
); CustomItem<ItemStack> customItem = optionalCustomItem.get();
CustomItem<ItemStack> customItem = optionalCustomItem.get(); customItem.execute(context, EventTrigger.RIGHT_CLICK);
customItem.execute(context, EventTrigger.RIGHT_CLICK);
}
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)