Interface ItemComponentBuilder
- All Known Implementing Classes:
ItemComponentBuilderImpl
@NonExtendable
public interface ItemComponentBuilder
Fluent declaration of one item component, returned by
RenderContext.slot(...)/layoutSlot(...). Declaration order is paint
order; all callbacks run on the main thread, engine-invoked. A component must declare an
item source via item(...) — one without fails at first render with
ViewConfigurationException.-
Method Summary
Modifier and TypeMethodDescription@NotNull ItemComponentBuildercancelOnClick(boolean cancel) Overrides the config-level click cancellation for this component's slots; handlers may still overturn the decision viaSlotClickContext.setCancelled(boolean).@NotNull ItemComponentBuilderCloses the view after a click on this component; deferred to the end of the tick.@NotNull ItemComponentBuilderdisplayIf(@NotNull Predicate<ViewContext> condition) Shows this component only while the condition holds; a hidden component's slots are cleared and it receives no clicks.@NotNull ItemComponentBuilderitem(@NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> renderer) Sets a dynamic item renderer, re-evaluated on every re-render of this component.@NotNull ItemComponentBuilderitem(@NotNull org.bukkit.inventory.ItemStack item) Sets a static item for this component.@NotNull ItemComponentBuilderonClick(@NotNull Consumer<SlotClickContext> handler) Sets the untyped click handler; it runs only when no per-ClickTypehandler matched the click.@NotNull ItemComponentBuilderonClick(@NotNull org.bukkit.event.inventory.ClickType type, @NotNull Consumer<SlotClickContext> handler) Sets the handler for one specific click type; it takes precedence over the untyped handler.@NotNull ItemComponentBuilderopenOnClick(@NotNull Class<? extends View> target) Navigates to another registered view after a click on this component; deferred to the end of the tick.@NotNull ItemComponentBuilderopenOnClick(@NotNull Class<? extends View> target, @NotNull ViewArguments arguments) Same asopenOnClick(Class), passing arguments to the target view.@NotNull ItemComponentBuilderupdateOnStateChange(@NotNull StateToken... tokens) Re-renders this component whenever one of the given tokens changes, at most once per flush.
-
Method Details
-
item
Sets a static item for this component.- Parameters:
item- the item to display- Returns:
- this builder
-
item
@NotNull @NotNull ItemComponentBuilder item(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> renderer) Sets a dynamic item renderer, re-evaluated on every re-render of this component. Renderer failures keep the previous slot content and are logged rate-limited.- Parameters:
renderer- the per-render item factory- Returns:
- this builder
-
displayIf
@NotNull @NotNull ItemComponentBuilder displayIf(@NotNull @NotNull Predicate<ViewContext> condition) Shows this component only while the condition holds; a hidden component's slots are cleared and it receives no clicks.- Parameters:
condition- evaluated on every re-render of this component- Returns:
- this builder
-
updateOnStateChange
Re-renders this component whenever one of the given tokens changes, at most once per flush. Dependencies are explicit — there is no automatic read tracking.- Parameters:
tokens- the state tokens to watch- Returns:
- this builder
-
onClick
@NotNull @NotNull ItemComponentBuilder onClick(@NotNull @NotNull Consumer<SlotClickContext> handler) Sets the untyped click handler; it runs only when no per-ClickTypehandler matched the click.- Parameters:
handler- the fallback click handler- Returns:
- this builder
-
onClick
@NotNull @NotNull ItemComponentBuilder onClick(@NotNull @NotNull org.bukkit.event.inventory.ClickType type, @NotNull @NotNull Consumer<SlotClickContext> handler) Sets the handler for one specific click type; it takes precedence over the untyped handler.- Parameters:
type- the click type to matchhandler- the click handler- Returns:
- this builder
-
cancelOnClick
Overrides the config-level click cancellation for this component's slots; handlers may still overturn the decision viaSlotClickContext.setCancelled(boolean).- Parameters:
cancel- whether clicks on this component are pre-cancelled- Returns:
- this builder
-
closeOnClick
Closes the view after a click on this component; deferred to the end of the tick.- Returns:
- this builder
-
openOnClick
Navigates to another registered view after a click on this component; deferred to the end of the tick.- Parameters:
target- the registered view class to open- Returns:
- this builder
-
openOnClick
@NotNull @NotNull ItemComponentBuilder openOnClick(@NotNull @NotNull Class<? extends View> target, @NotNull @NotNull ViewArguments arguments) Same asopenOnClick(Class), passing arguments to the target view.- Parameters:
target- the registered view class to openarguments- the arguments handed to the target's contexts- Returns:
- this builder
-