Package dev.aurelium.slate.builder
Class MenuBuilder
java.lang.Object
dev.aurelium.slate.builder.MenuBuilder
Class used to define functionality for a menu. This is used in conjunction with the menu file
and individual
ItemBuilder, TemplateBuilder, and ComponentBuilder instances to
render a menu shown to a player.-
Method Summary
Modifier and TypeMethodDescriptionbuild()static MenuBuilderbuilder()Creates a new menu builder instance.<T> MenuBuildercomponent(String name, @Nullable Class<T> contextType, Consumer<ComponentBuilder<T>> template) Add a component to the menu.<T> MenuBuildercomponent(String name, Class<T> contextType, ComponentBuilder<T> builder) Add a component to the menu that accepts aComponentBuilderinstance you must create yourself.component(String name, Consumer<ComponentBuilder<?>> template) Add a component without a context type to the menu.defaultOptions(Map<String, Object> defaultOptions) Sets default options for the menu, matching values in the options section of a menu file.fillItem(ItemModifier modifier) Defines a fill item or modifies an existing fill item in the menu.item(String name, ItemBuilder builder) Add an item to the menu that accepts aItemBuilderinstance you must create yourself.item(String name, Consumer<ItemBuilder> item) Add an item to the menuonOpen(MenuListener listener) Defines a consumer to run when the menu is opened for a player.onUpdate(MenuListener listener) Defines a consumer to run every tick a menu is open for a player.pages(PageProvider provider) Sets the page provider for the menu.properties(PropertyProvider provider) Defines default properties for this menu.replace(String from, ItemReplacer replacer) Replaces any placeholder on the page that matches the "from" string.replaceTitle(String from, ItemReplacer replacer) Replaces a placeholder in the menu title with a value.replaceTitleAny(ItemReplacer replacer) Replaces any placeholder in the menu title with a value.<T> MenuBuildertemplate(String name, Class<T> contextType, TemplateBuilder<T> builder) Add a template item to the menu that accepts aTemplateBuilderinstance you must create yourself.<T> MenuBuildertemplate(String name, Class<T> contextType, Consumer<TemplateBuilder<T>> template) Add a template item to the menu.
-
Method Details
-
builder
Creates a new menu builder instance.- Returns:
- the menu builder
-
item
Add an item to the menu- Parameters:
name- the name of the itemitem- a consumer containing a newItemBuilder, best used as a lambda- Returns:
- the menu builder
-
item
Add an item to the menu that accepts aItemBuilderinstance you must create yourself. It is usually easier to useitem(String, Consumer), which provides a builder for you.- Parameters:
name- the name of the itembuilder- the item builder- Returns:
- the menu builder
-
template
public <T> MenuBuilder template(String name, Class<T> contextType, Consumer<TemplateBuilder<T>> template) Add a template item to the menu. A template item is an item that can be repeated multiple times with different contexts. Each instance of a template is linked to a context and can have a separate appearance. This must match a template defined in the templates section of the menu file.- Type Parameters:
T- the type of the context object- Parameters:
name- the name of the template, as defined in the menu filecontextType- the type of the context object that will be passed to the templatetemplate- a consumer containing a newTemplateBuilder, best used as a lambda- Returns:
- the menu builder
-
template
Add a template item to the menu that accepts aTemplateBuilderinstance you must create yourself. It is usually easier to usetemplate(String, Class, Consumer), which provides a builder for you.- Type Parameters:
T- the type of the context object- Parameters:
name- the name of the template, as defined in the menu filecontextType- the type of the context object that will be passed to the templatebuilder- the template builder- Returns:
- the menu builder
-
component
public <T> MenuBuilder component(String name, @Nullable @Nullable Class<T> contextType, Consumer<ComponentBuilder<T>> template) Add a component to the menu. A component is a reusable piece of item lore (list of lore lines) that can be inserted into items and templates. Components can be shown and hidden based on a condition in code. This must match a component defined in the components section of the menu file.- Type Parameters:
T- the type of the context object- Parameters:
name- the name of the component, as defined in the menu filecontextType- the type of the context object that will be passed to the component, can be null if no context is neededtemplate- a consumer containing a newComponentBuilder, best used as a lambda- Returns:
- the menu builder
-
component
Add a component without a context type to the menu. Components created this way cannot access the context object of templates, so they should be only used in items.- Parameters:
name- the name of the component, as defined in the menu filetemplate- a consumer containing a newComponentBuilder, best used as a lambda- Returns:
- the menu builder
-
component
Add a component to the menu that accepts aComponentBuilderinstance you must create yourself. It is usually easier to usecomponent(String, Class, Consumer), which provides a builder for you.- Type Parameters:
T- the type of the context object- Parameters:
name- the name of the component, as defined in the menu filecontextType- the type of the context object that will be passed to the component, can be null if no context is neededbuilder- the component builder- Returns:
- the menu builder
-
replace
Replaces any placeholder on the page that matches the "from" string. This can be in the title, items, templates, and components.- Parameters:
from- the text of the placeholder without curly bracesreplacer- the replacer function, best used as a lambda- Returns:
- the menu builder
-
replaceTitle
Replaces a placeholder in the menu title with a value.- Parameters:
from- the text of the placeholder without curly bracesreplacer- the replacer function, best used as a lambda- Returns:
- the menu builder
-
replaceTitleAny
Replaces any placeholder in the menu title with a value. TheItemReplacerpassed will be called for every placeholder detected in the title. The name of the placeholder being checked can be accessing usingPlaceholderInfo.placeholder().- Parameters:
replacer- the replacer function, best used as a lambda- Returns:
- the menu builder
-
pages
Sets the page provider for the menu. The page provider computes the number of pages needed for the menu using aMenuInfocontext object.- Parameters:
provider- the page provider- Returns:
- the menu builder
-
properties
Defines default properties for this menu. These properties are used when the menu is opened through click actions defined in other menu files.- Parameters:
provider- thePropertyProvider, a function that takes aMenuInfocontext object and returns aMap<String, Object>of properties- Returns:
- the menu builder
-
fillItem
Defines a fill item or modifies an existing fill item in the menu. The fill item is used to fill up empty slots in the menu with a repeating item. In most cases, the fill item can be fully defined with the fill section of the menu file. This should only be used if you need to modify the fill item in code.- Parameters:
modifier- the item modifier, a function that takes aItemInfocontext object and returns theItemStackthat will be used as the fill item. The existing fill item defined from the menu file can be accessed usingItemInfo.item().- Returns:
- the menu builder
-
onOpen
Defines a consumer to run when the menu is opened for a player.- Parameters:
listener- the menu listener, a consumer that takes aMenuInfocontext object- Returns:
- the menu builder
-
onUpdate
Defines a consumer to run every tick a menu is open for a player.- Parameters:
listener- the menu listener, a consumer that takes aMenuInfocontext object- Returns:
- the menu builder
-
defaultOptions
Sets default options for the menu, matching values in the options section of a menu file. These options allow Slate to update user menu files automatically with new configurable options you add later.- Parameters:
defaultOptions- a map of default options- Returns:
- the menu builder
-
build
-