Class MenuBuilder

java.lang.Object
dev.aurelium.slate.builder.MenuBuilder

public class MenuBuilder extends Object
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 Details

    • builder

      public static MenuBuilder builder()
      Creates a new menu builder instance.
      Returns:
      the menu builder
    • item

      public MenuBuilder item(String name, Consumer<ItemBuilder> item)
      Add an item to the menu
      Parameters:
      name - the name of the item
      item - a consumer containing a new ItemBuilder, best used as a lambda
      Returns:
      the menu builder
    • item

      public MenuBuilder item(String name, ItemBuilder builder)
      Add an item to the menu that accepts a ItemBuilder instance you must create yourself. It is usually easier to use item(String, Consumer), which provides a builder for you.
      Parameters:
      name - the name of the item
      builder - 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 file
      contextType - the type of the context object that will be passed to the template
      template - a consumer containing a new TemplateBuilder, best used as a lambda
      Returns:
      the menu builder
    • template

      public <T> MenuBuilder template(String name, Class<T> contextType, TemplateBuilder<T> builder)
      Add a template item to the menu that accepts a TemplateBuilder instance you must create yourself. It is usually easier to use template(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 file
      contextType - the type of the context object that will be passed to the template
      builder - 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 file
      contextType - the type of the context object that will be passed to the component, can be null if no context is needed
      template - a consumer containing a new ComponentBuilder, best used as a lambda
      Returns:
      the menu builder
    • component

      public MenuBuilder component(String name, Consumer<ComponentBuilder<?>> template)
      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 file
      template - a consumer containing a new ComponentBuilder, best used as a lambda
      Returns:
      the menu builder
    • component

      public <T> MenuBuilder component(String name, Class<T> contextType, ComponentBuilder<T> builder)
      Add a component to the menu that accepts a ComponentBuilder instance you must create yourself. It is usually easier to use component(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 file
      contextType - the type of the context object that will be passed to the component, can be null if no context is needed
      builder - the component builder
      Returns:
      the menu builder
    • replace

      public MenuBuilder replace(String from, ItemReplacer replacer)
      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 braces
      replacer - the replacer function, best used as a lambda
      Returns:
      the menu builder
    • replaceTitle

      public MenuBuilder replaceTitle(String from, ItemReplacer replacer)
      Replaces a placeholder in the menu title with a value.
      Parameters:
      from - the text of the placeholder without curly braces
      replacer - the replacer function, best used as a lambda
      Returns:
      the menu builder
    • replaceTitleAny

      public MenuBuilder replaceTitleAny(ItemReplacer replacer)
      Replaces any placeholder in the menu title with a value. The ItemReplacer passed will be called for every placeholder detected in the title. The name of the placeholder being checked can be accessing using PlaceholderInfo.placeholder().
      Parameters:
      replacer - the replacer function, best used as a lambda
      Returns:
      the menu builder
    • pages

      public MenuBuilder pages(PageProvider provider)
      Sets the page provider for the menu. The page provider computes the number of pages needed for the menu using a MenuInfo context object.
      Parameters:
      provider - the page provider
      Returns:
      the menu builder
    • properties

      public MenuBuilder properties(PropertyProvider provider)
      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 - the PropertyProvider, a function that takes a MenuInfo context object and returns a Map<String, Object> of properties
      Returns:
      the menu builder
    • fillItem

      public MenuBuilder fillItem(ItemModifier modifier)
      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 a ItemInfo context object and returns the ItemStack that will be used as the fill item. The existing fill item defined from the menu file can be accessed using ItemInfo.item().
      Returns:
      the menu builder
    • onOpen

      public MenuBuilder onOpen(MenuListener listener)
      Defines a consumer to run when the menu is opened for a player.
      Parameters:
      listener - the menu listener, a consumer that takes a MenuInfo context object
      Returns:
      the menu builder
    • onUpdate

      public MenuBuilder onUpdate(MenuListener listener)
      Defines a consumer to run every tick a menu is open for a player.
      Parameters:
      listener - the menu listener, a consumer that takes a MenuInfo context object
      Returns:
      the menu builder
    • defaultOptions

      public MenuBuilder defaultOptions(Map<String,Object> 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

      public BuiltMenu build()