Class SectionConfiguration

java.lang.Object
io.github.syst3ms.skriptparser.lang.entries.SectionConfiguration

public class SectionConfiguration extends Object
The SectionConfiguration class can be used to create simple and efficient data sections that only allow specific keys and values. Skript's command structure is the perfect example:

command /hello:
    permission: plugin.hello
    permission message: "You don't have the permission to do that!"
    cooldown: 1 minute
    trigger:
        broadcast "Hello!"

This example portrays the many features this class has.
  • Keys can be omitted if they are optional.
  • Whole sections can be added as value.
  • Some keys only allow specific types.
  • Method Details

    • loadConfiguration

      public boolean loadConfiguration(@Nullable @Nullable CodeSection parent, FileSection section, ParserState parserState, SkriptLogger logger)
      Load the data of this SectionConfiguration into to the data map using a FileSection instance. This method should be called only once and will throw an error if attempting to load the configuration multiple times. The default use-case would be to load the configuration inside CodeSection's load method.
      Parameters:
      parent - the parent section
      section - the file section
      parserState - the parse state
      logger - the logger
      Returns:
      whether the section was loaded successfully or errors occurred
    • getParent

      @Nullable public @Nullable CodeSection getParent()
    • getData

      public Map<String,Object> getData()
      Returns:
      a modifiable map containing the loaded data
    • getEntries

      public List<EntryLoader> getEntries()
    • getValue

      public Object getValue(String key)
    • getValue

      public <T> Optional<T> getValue(String key, Class<T> cls)
      Tries to retrieve a value from its key and cast it to the correct class. This can only be used when you register your option as a literal, otherwise, the option will likely be parsed as a String and throw an exception. Options that allow literal lists are saved as an array. Returns an empty Optional if the key is not present. This is only possible for optional keys.
      Type Parameters:
      T - the type of the value
      Parameters:
      key - the key
      cls - the class to cast to
      Returns:
      the value cast to the given class, or an empty Optional if the key was not specified
    • getString

      public Optional<String> getString(String key)
      Parameters:
      key - the key
      Returns:
      the option value, or an empty Optional if the key was not specified
    • getStringList

      public Optional<String[]> getStringList(String key)
      Parameters:
      key - the key
      Returns:
      the list values, or an empty Optional if the key was not specified
    • getSection

      public Optional<CodeSection> getSection(String key)
      Parameters:
      key - the key
      Returns:
      the enclosed code section, or an empty Optional if the key was not specified