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

public class BuildContext extends Object
BuildContext 是构建 Widget 树时的上下文信息。

它包含构建过程中需要访问的信息,如:

  • 当前玩家
  • GUI 配置(行数、标题等)
  • 父 Widget 的继承属性
  • 自定义的上下文数据

使用示例:


 @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)
      创建根 BuildContext。
      Parameters:
      player - 玩家
      guiId - GUI ID
      rows - 行数
      Returns:
      新的 BuildContext
    • child

      @NotNull public @NotNull BuildContext child(@NotNull @NotNull Element parentElement)
      为此 Context 创建一个子 Context。 用于传递父 Widget 的属性给子 Widget。
      Returns:
      子 BuildContext
    • getPlayer

      @NotNull public @NotNull org.bukkit.entity.Player getPlayer()
      获取当前玩家。
      Returns:
      玩家
    • getGuiId

      @NotNull public @NotNull String getGuiId()
      获取 GUI ID。
      Returns:
      GUI ID
    • getRows

      public int getRows()
      获取 GUI 行数。
      Returns:
      行数
    • getSize

      public int getSize()
      获取 GUI 槽位总数。
      Returns:
      槽位总数
    • getParentElement

      @Nullable public @Nullable Element getParentElement()
      获取父 Element。
      Returns:
      父 Element,如果是根则返回 null
    • getInheritedProperty

      @Nullable public @Nullable Object getInheritedProperty(@NotNull @NotNull String key)
      获取继承的属性值。
      Parameters:
      key - 属性名
      Returns:
      属性值,不存在则返回 null
    • hasInheritedProperty

      public boolean hasInheritedProperty(@NotNull @NotNull String key)
      检查是否有指定的继承属性。
      Parameters:
      key - 属性名
      Returns:
      如果存在则返回 true
    • toBuilder

      @NotNull public @NotNull BuildContext.Builder toBuilder()
      创建一个新的 Builder,复制当前 Context 的配置。