java.lang.Object
com.ultikits.ultitools.abstracts.gui.declarative.core.BuildContext

public class BuildContext extends Object
BuildContext carries the contextual information available while building a Widget tree.

It holds the information the build process needs to access, such as:

  • the current player
  • GUI configuration (row count, title, etc.)
  • properties inherited from the parent Widget
  • custom context data

Usage example:


 @Override
 public Widget build(BuildContext context) {
     Player player = context.getPlayer();
     int rows = context.getRows();

     return Container.builder()
         .title("Welcome, " + player.getName())
         .rows(rows)
         .child(buildContent(context))
         .build();
 }
 
Since:
6.2.0
Version:
1.0.0
Author:
UltiTools Team
  • Field Details

    • player

      @NotNull private final @NotNull org.bukkit.entity.Player player
    • guiId

      @NotNull private final @NotNull String guiId
    • rows

      private final int rows
    • parentElement

      @Nullable private final @Nullable Element parentElement
    • inheritedProperties

      @NotNull private final @NotNull Map<String,Object> inheritedProperties
  • Constructor Details

  • Method Details

    • root

      @NotNull public static @NotNull BuildContext root(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String guiId, int rows)
      Creates the root BuildContext.
      Parameters:
      player - the player
      guiId - the GUI ID
      rows - the row count
      Returns:
      a new BuildContext
    • child

      @NotNull public @NotNull BuildContext child(@NotNull @NotNull Element parentElement)
      Creates a child Context for this Context. Used to pass a parent Widget's properties down to a child Widget.
      Returns:
      the child BuildContext
    • getPlayer

      @NotNull public @NotNull org.bukkit.entity.Player getPlayer()
      Gets the current player.
      Returns:
      the player
    • getGuiId

      @NotNull public @NotNull String getGuiId()
      Gets the GUI ID.
      Returns:
      the GUI ID
    • getRows

      public int getRows()
      Gets the GUI row count.
      Returns:
      the row count
    • getSize

      public int getSize()
      Gets the total number of GUI slots.
      Returns:
      the total slot count
    • getParentElement

      @Nullable public @Nullable Element getParentElement()
      Gets the parent Element.
      Returns:
      the parent Element, or null at the root
    • getInheritedProperty

      @Nullable public @Nullable Object getInheritedProperty(@NotNull @NotNull String key)
      Gets an inherited property value.
      Parameters:
      key - the property name
      Returns:
      the property value, or null if it does not exist
    • hasInheritedProperty

      public boolean hasInheritedProperty(@NotNull @NotNull String key)
      Checks whether the given inherited property exists.
      Parameters:
      key - the property name
      Returns:
      true if it exists
    • toBuilder

      @NotNull public @NotNull BuildContext.Builder toBuilder()
      Creates a new Builder that copies this Context's configuration.