Class BuildContext
java.lang.Object
com.ultikits.ultitools.abstracts.gui.declarative.core.BuildContext
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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull BuildContextCreates a child Context for this Context.@NotNull StringgetGuiId()Gets the GUI ID.@Nullable ObjectgetInheritedProperty(@NotNull String key) Gets an inherited property value.@Nullable ElementGets the parent Element.@NotNull org.bukkit.entity.PlayerGets the current player.intgetRows()Gets the GUI row count.intgetSize()Gets the total number of GUI slots.booleanhasInheritedProperty(@NotNull String key) Checks whether the given inherited property exists.static @NotNull BuildContextCreates the root BuildContext.@NotNull BuildContext.BuilderCreates a new Builder that copies this Context's configuration.
-
Field Details
-
player
@NotNull private final @NotNull org.bukkit.entity.Player player -
guiId
-
rows
private final int rows -
parentElement
-
inheritedProperties
-
-
Constructor Details
-
BuildContext
-
-
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 playerguiId- the GUI IDrows- the row count- Returns:
- a new BuildContext
-
child
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
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
Gets the parent Element.- Returns:
- the parent Element, or null at the root
-
getInheritedProperty
Gets an inherited property value.- Parameters:
key- the property name- Returns:
- the property value, or null if it does not exist
-
hasInheritedProperty
Checks whether the given inherited property exists.- Parameters:
key- the property name- Returns:
- true if it exists
-
toBuilder
Creates a new Builder that copies this Context's configuration.
-