Class DynamicFunctionReference<Result>

java.lang.Object
ch.njol.skript.lang.function.DynamicFunctionReference<Result>
Type Parameters:
Result - The return type of this function, if known.
All Implemented Interfaces:
AnyNamed, AnyProvider, Contract, Executable<org.bukkit.event.Event,Result[]>, Validated

public class DynamicFunctionReference<Result> extends Object implements Contract, Executable<org.bukkit.event.Event,Result[]>, Validated, AnyNamed
A partial reference to a Skript function. This reference knows some of its information in advance (such as the function's name) but will not be resolved until it receives inputs for the first time.
  • Constructor Details

    • DynamicFunctionReference

      public DynamicFunctionReference(Function<? extends Result> function)
    • DynamicFunctionReference

      public DynamicFunctionReference(@NotNull @NotNull String name)
    • DynamicFunctionReference

      public DynamicFunctionReference(@NotNull @NotNull String name, @Nullable @Nullable Script source)
  • Method Details

    • source

      @Nullable public @Nullable Script source()
    • name

      @NotNull public @NotNull String name()
      Specified by:
      name in interface AnyNamed
      Returns:
      This thing's name
    • isSingle

      public boolean isSingle(Expression<?>... arguments)
      Specified by:
      isSingle in interface Contract
      Returns:
      Whether, given these parameters, this will return a single value
      See Also:
    • getReturnType

      @Nullable public @Nullable Class<?> getReturnType(Expression<?>... arguments)
      Specified by:
      getReturnType in interface Contract
      Returns:
      What this will return, given these parameters
      See Also:
    • execute

      public Result @Nullable [] execute(org.bukkit.event.Event event, Object... arguments)
      Specified by:
      execute in interface Executable<org.bukkit.event.Event,Result[]>
    • invalidate

      public void invalidate()
      Description copied from interface: Validated
      Mark a thing as no longer safe to use. This should (typically) not be used by external modifiers, but implementations may differ.
      Implementations that do not want to expose an invalidator hook may throw an UnsupportedOperationException, which is protected by the internal contract.
      Specified by:
      invalidate in interface Validated
    • valid

      public boolean valid()
      Description copied from interface: Validated
      Implementations ought to specify what 'valid' means locally (e.g. should a new copy be obtained?) when overriding this method.
      Specified by:
      valid in interface Validated
      Returns:
      Whether this is still valid
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • validate

      @Nullable public @Nullable Expression<?> validate(Expression<?>[] parameters)
      Validates whether dynamic inputs are appropriate for the resolved function. If the inputs are acceptable, this will collect them into an expression list (the output of which can be passed directly to the task).
      Parameters:
      parameters - The input types to check
      Returns:
      A combined expression list, if these inputs are appropriate for the function
    • validate

      @Nullable public @Nullable Expression<?> validate(DynamicFunctionReference.Input input)
    • parseFunction

      @Nullable public static @Nullable DynamicFunctionReference<?> parseFunction(String name)
      Attempts to parse a function reference from the format it would be stringified in. The name can include the source script name for the case of parsing local functions.
      Parameters:
      name - The function name, possibly including its script name
      Returns:
      A reference, if one is available
    • resolveFunction

      @Nullable public static @Nullable DynamicFunctionReference<?> resolveFunction(String name, @Nullable @Nullable Script script)
      Used to resolve a function from its name.
      Parameters:
      name - The function name
      script - Potentially, the script it is from, if one is known
      Returns:
      A function reference, if one is available.