Interface MenuBackgroundCondition

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface MenuBackgroundCondition
A condition an add-on adds to the when of menu background rules in guis.yml.

Server owners write it under the add-on's namespace, namespace:name (see nameOf(Plugin, String)), anywhere a built-in condition such as permission may stand. For a condition registered as myranks:rank:

 - when: { myranks:rank: gold }                 argument "gold"
 - when: { myranks:rank: [gold, "!trial"] }     every one must hold; "!" means "not"
 - when: { myranks:rank: true }                 argument "" (false asks for the opposite)
 - when: "myranks:rank(gold) and page > 1"      argument "gold"; several are all tested
 - when: "not myranks:rank"                     argument ""
 

The argument is what the owner wrote, trimmed; what it means is up to the add-on. A condition that throws counts as false and is reported in the console once.

Since:
1.15.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final class 
    Holds the name pattern, which an interface cannot keep as a private constant.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull String
    nameOf(@NotNull org.bukkit.plugin.Plugin owner, @NotNull String name)
    The name server owners write for a condition or value a plugin registers: the plugin's name in lowercase, with every character outside a-z, 0-9, _ and - replaced by _, then a colon and the name.
    boolean
    test(@NotNull MenuConditionContext context, @NotNull String argument)
    Tests the condition for one viewer's menu.
  • Method Details

    • test

      boolean test(@NotNull @NotNull MenuConditionContext context, @NotNull @NotNull String argument)
      Tests the condition for one viewer's menu. Runs on the main thread.
      Parameters:
      context - the viewer, their menu and the moment
      argument - what the owner wrote after the condition's name, empty when nothing
      Returns:
      whether the condition holds
    • nameOf

      @NotNull static @NotNull String nameOf(@NotNull @NotNull org.bukkit.plugin.Plugin owner, @NotNull @NotNull String name)
      The name server owners write for a condition or value a plugin registers: the plugin's name in lowercase, with every character outside a-z, 0-9, _ and - replaced by _, then a colon and the name.
      Parameters:
      owner - the registering plugin
      name - the condition's name within the plugin, using a-z, 0-9, _ and -; case is ignored
      Returns:
      the name as written in guis.yml, such as myranks:rank
      Throws:
      IllegalArgumentException - when the name uses other characters