Class ItemComponentBuilderImpl
java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.internal.component.ItemComponentBuilderImpl
- All Implemented Interfaces:
ItemComponentBuilder
@Internal
public final class ItemComponentBuilderImpl
extends Object
implements ItemComponentBuilder
Mutable collector behind
ItemComponentBuilder; gathers a component declaration
and materializes it into an immutable ComponentInstance bound to fixed slots.-
Constructor Summary
Constructors -
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 ComponentInstancematerialize(@org.jetbrains.annotations.NotNull int[] slots) Freezes the collected declaration into a component bound to the given slots.@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 asItemComponentBuilder.openOnClick(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.
-
Constructor Details
-
ItemComponentBuilderImpl
public ItemComponentBuilderImpl()
-
-
Method Details
-
item
@NotNull public @NotNull ItemComponentBuilder item(@NotNull @NotNull org.bukkit.inventory.ItemStack item) Description copied from interface:ItemComponentBuilderSets a static item for this component.- Specified by:
itemin interfaceItemComponentBuilder- Parameters:
item- the item to display- Returns:
- this builder
-
item
@NotNull public @NotNull ItemComponentBuilder item(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> renderer) Description copied from interface:ItemComponentBuilderSets 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.- Specified by:
itemin interfaceItemComponentBuilder- Parameters:
renderer- the per-render item factory- Returns:
- this builder
-
displayIf
@NotNull public @NotNull ItemComponentBuilder displayIf(@NotNull @NotNull Predicate<ViewContext> condition) Description copied from interface:ItemComponentBuilderShows this component only while the condition holds; a hidden component's slots are cleared and it receives no clicks.- Specified by:
displayIfin interfaceItemComponentBuilder- Parameters:
condition- evaluated on every re-render of this component- Returns:
- this builder
-
updateOnStateChange
@NotNull public @NotNull ItemComponentBuilder updateOnStateChange(@NotNull @NotNull StateToken... tokens) Description copied from interface:ItemComponentBuilderRe-renders this component whenever one of the given tokens changes, at most once per flush. Dependencies are explicit — there is no automatic read tracking.- Specified by:
updateOnStateChangein interfaceItemComponentBuilder- Parameters:
tokens- the state tokens to watch- Returns:
- this builder
-
onClick
@NotNull public @NotNull ItemComponentBuilder onClick(@NotNull @NotNull Consumer<SlotClickContext> handler) Description copied from interface:ItemComponentBuilderSets the untyped click handler; it runs only when no per-ClickTypehandler matched the click.- Specified by:
onClickin interfaceItemComponentBuilder- Parameters:
handler- the fallback click handler- Returns:
- this builder
-
onClick
@NotNull public @NotNull ItemComponentBuilder onClick(@NotNull @NotNull org.bukkit.event.inventory.ClickType type, @NotNull @NotNull Consumer<SlotClickContext> handler) Description copied from interface:ItemComponentBuilderSets the handler for one specific click type; it takes precedence over the untyped handler.- Specified by:
onClickin interfaceItemComponentBuilder- Parameters:
type- the click type to matchhandler- the click handler- Returns:
- this builder
-
cancelOnClick
Description copied from interface:ItemComponentBuilderOverrides the config-level click cancellation for this component's slots; handlers may still overturn the decision viaSlotClickContext.setCancelled(boolean).- Specified by:
cancelOnClickin interfaceItemComponentBuilder- Parameters:
cancel- whether clicks on this component are pre-cancelled- Returns:
- this builder
-
closeOnClick
Description copied from interface:ItemComponentBuilderCloses the view after a click on this component; deferred to the end of the tick.- Specified by:
closeOnClickin interfaceItemComponentBuilder- Returns:
- this builder
-
openOnClick
@NotNull public @NotNull ItemComponentBuilder openOnClick(@NotNull @NotNull Class<? extends View> target) Description copied from interface:ItemComponentBuilderNavigates to another registered view after a click on this component; deferred to the end of the tick.- Specified by:
openOnClickin interfaceItemComponentBuilder- Parameters:
target- the registered view class to open- Returns:
- this builder
-
openOnClick
@NotNull public @NotNull ItemComponentBuilder openOnClick(@NotNull @NotNull Class<? extends View> target, @NotNull @NotNull ViewArguments arguments) Description copied from interface:ItemComponentBuilderSame asItemComponentBuilder.openOnClick(Class), passing arguments to the target view.- Specified by:
openOnClickin interfaceItemComponentBuilder- Parameters:
target- the registered view class to openarguments- the arguments handed to the target's contexts- Returns:
- this builder
-
materialize
@NotNull public @NotNull ComponentInstance materialize(@NotNull @org.jetbrains.annotations.NotNull int[] slots) Freezes the collected declaration into a component bound to the given slots.- Parameters:
slots- the container slots this component paints, in paint order- Returns:
- the immutable materialized component
-