Package ch.njol.skript.lang.function
Class FunctionRegistry
java.lang.Object
ch.njol.skript.lang.function.FunctionRegistry
A registry for functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Unmodifiable @NotNull Collection
<Function<?>> elements()
@NotNull ch.njol.skript.lang.function.FunctionRegistry.Retrieval
<Function<?>> getFunction
(@Nullable String namespace, @NotNull String name, @NotNull Class<?>... args) Gets a function from a script.static FunctionRegistry
Gets the global function registry.ch.njol.skript.lang.function.FunctionRegistry.Retrieval
<Signature<?>> getSignature
(@Nullable String namespace, @NotNull String name, @NotNull Class<?>... args) Gets the signature for a function with the given name and arguments.getSignatures
(@Nullable String namespace, @NotNull String name) Gets every signature with the namename
.void
Registers a function.void
Registers a signature.void
Removes a function's signature from the registry.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
FunctionRegistry
public FunctionRegistry()
-
-
Method Details
-
getRegistry
Gets the global function registry.- Returns:
- The global function registry.
-
elements
-
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
. Ifnamespace
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
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
. Ifnamespace
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. Ifnamespace
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. Ifnamespace
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 namename
. This includes global functions and, ifnamespace
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
Removes a function's signature from the registry.- Parameters:
signature
- The signature to remove.
-