Class FunctionRegistry

java.lang.Object
ch.njol.skript.lang.function.FunctionRegistry
All Implemented Interfaces:
Iterable<Function<?>>, Registry<Function<?>>

@Internal public final class FunctionRegistry extends Object implements Registry<Function<?>>
A registry for functions.
  • Constructor Details

    • FunctionRegistry

      public FunctionRegistry()
  • Method Details

    • getRegistry

      public static FunctionRegistry getRegistry()
      Gets the global function registry.
      Returns:
      The global function registry.
    • elements

      @NotNull public @Unmodifiable @NotNull Collection<Function<?>> elements()
      Specified by:
      elements in interface Registry<Function<?>>
      Returns:
      A collection of all elements in this registry.
    • register

      public void register(@Nullable @Nullable String namespace, @NotNull @NotNull Signature<?> signature)
      Registers a signature.

      Attempting to register a local signature in the global namespace, or a global signature in a local namespace, will throw an IllegalArgumentException. If namespace is null, will register this signature globally, only if the signature is global.

      Parameters:
      namespace - The namespace to register the signature in. Usually represents the path of the script this signature is registered in.
      signature - The signature to register.
      Throws:
      SkriptAPIException - if a signature with the same name and parameters is already registered in this namespace.
      IllegalArgumentException - if the signature is global and namespace is not null, or if the signature is local and namespace is null.
    • register

      public void register(@Nullable @Nullable String namespace, @NotNull @NotNull Function<?> function)
      Registers a function.

      Attempting to register a local function in the global namespace, or a global function in a local namespace, will throw an IllegalArgumentException. If namespace is null, will register this function globally, only if the function is global.

      Parameters:
      namespace - The namespace to register the function in. Usually represents the path of the script this function is registered in.
      function - The function to register.
      Throws:
      SkriptAPIException - if the function name is invalid or if a function with the same name and parameters is already registered in this namespace.
      IllegalArgumentException - if the function is global and namespace is not null, or if the function is local and namespace is null.
    • getFunction

      @NotNull public @NotNull ch.njol.skript.lang.function.FunctionRegistry.Retrieval<Function<?>> getFunction(@Nullable @Nullable String namespace, @NotNull @NotNull String name, @NotNull @NotNull Class<?>... args)
      Gets a function from a script. If no local function is found, checks for global functions. If namespace is null, only global functions will be checked.
      Parameters:
      namespace - The namespace to get the function from. Usually represents the path of the script this function is registered in.
      name - The name of the function.
      args - The types of the arguments of the function.
      Returns:
      Information related to the attempt to get the specified function, stored in a FunctionRegistry.Retrieval object.
    • getSignature

      public ch.njol.skript.lang.function.FunctionRegistry.Retrieval<Signature<?>> getSignature(@Nullable @Nullable String namespace, @NotNull @NotNull String name, @NotNull @NotNull Class<?>... args)
      Gets the signature for a function with the given name and arguments. If no local function is found, checks for global functions. If namespace is null, only global signatures will be checked.
      Parameters:
      namespace - The namespace to get the function from. Usually represents the path of the script this function is registered in.
      name - The name of the function.
      args - The types of the arguments of the function.
      Returns:
      The signature for the function with the given name and argument types, or null if no such function exists.
    • getSignatures

      @NotNull public @Unmodifiable @NotNull Set<Signature<?>> getSignatures(@Nullable @Nullable String namespace, @NotNull @NotNull String name)
      Gets every signature with the name name. This includes global functions and, if namespace is not null, functions under that namespace (if valid).
      Parameters:
      namespace - The additional namespace to obtain signatures from. Usually represents the path of the script this function is registered in.
      name - The name of the signature(s) to obtain.
      Returns:
      A list of all signatures named name.
    • remove

      public void remove(@NotNull @NotNull Signature<?> signature)
      Removes a function's signature from the registry.
      Parameters:
      signature - The signature to remove.