Class Functions

java.lang.Object
ch.njol.skript.lang.function.Functions

public abstract class Functions extends Object
Static methods to work with functions.
  • Field Details

  • Method Details

    • registerFunction

      public static JavaFunction<?> registerFunction(JavaFunction<?> function)
      Registers a function written in Java.
      Returns:
      The passed function
    • loadFunction

      @Nullable public static @Nullable Function<?> loadFunction(Script script, SectionNode node, Signature<?> signature)
      Loads a script function from given node.
      Parameters:
      script - The script the function is declared in
      node - Section node.
      signature - The signature of the function. Use parseSignature(String, String, String, String, boolean) to get a new signature instance and registerSignature(Signature) to register the signature
      Returns:
      Script function, or null if something went wrong.
    • parseSignature

      @Nullable public static @Nullable Signature<?> parseSignature(String script, String name, String args, @Nullable @Nullable String returnType, boolean local)
      Parses the signature from the given arguments.
      Parameters:
      script - Script file name (might be used for some checks).
      name - The name of the function.
      args - The parameters of the function. See Parameter.parse(String)
      returnType - The return type of the function
      local - If the signature of function is local.
      Returns:
      Parsed signature or null if something went wrong.
      See Also:
    • registerSignature

      @Nullable public static @Nullable Signature<?> registerSignature(Signature<?> signature)
      Registers the signature.
      Parameters:
      signature - The signature to register.
      Returns:
      Signature of function, or null if something went wrong.
      See Also:
    • getFunction

      @Deprecated @Nullable public static @Nullable Function<?> getFunction(String name)
      Deprecated.
      in favour of getGlobalFunction(String) for proper name.
      Gets a function, if it exists. Note that even if function exists in scripts, it might not have been parsed yet. If you want to check for existence, then use getGlobalSignature(String).
      Parameters:
      name - Name of function.
      Returns:
      Function, or null if it does not exist.
    • getGlobalFunction

      @Nullable public static @Nullable Function<?> getGlobalFunction(String name)
      Gets a function, if it exists. Note that even if function exists in scripts, it might not have been parsed yet. If you want to check for existence, then use getGlobalSignature(String).
      Parameters:
      name - Name of function.
      Returns:
      Function, or null if it does not exist.
    • getLocalFunction

      @Nullable public static @Nullable Function<?> getLocalFunction(String name, String script)
      Gets a function, if it exists. Note that even if function exists in scripts, it might not have been parsed yet. If you want to check for existence, then use getLocalSignature(String, String).
      Parameters:
      name - Name of function.
      script - The script where the function is declared in. Used to get local functions.
      Returns:
      Function, or null if it does not exist.
    • getFunction

      @Nullable public static @Nullable Function<?> getFunction(String name, @Nullable @Nullable String script)
      Gets a local function, if it doesn't exist it'll fall back to a global function, if it exists. Note that even if function exists in scripts, it might not have been parsed yet. If you want to check for existence, then use getSignature(String, String).
      Parameters:
      name - Name of function.
      script - The script where the function is declared in. Used to get local functions.
      Returns:
      Function, or null if it does not exist.
    • getSignature

      @Deprecated @Nullable public static @Nullable Signature<?> getSignature(String name)
      Deprecated.
      in favour of getGlobalSignature(String) for proper name.
      Gets a signature of function with given name.
      Parameters:
      name - Name of function.
      Returns:
      Signature, or null if function does not exist.
    • getGlobalSignature

      @Nullable public static @Nullable Signature<?> getGlobalSignature(String name)
      Gets a signature of function with given name.
      Parameters:
      name - Name of function.
      Returns:
      Signature, or null if function does not exist.
    • getLocalSignature

      @Nullable public static @Nullable Signature<?> getLocalSignature(String name, String script)
      Gets a signature of function with given name.
      Parameters:
      name - Name of function.
      script - The script where the function is declared in. Used to get local functions.
      Returns:
      Signature, or null if function does not exist.
    • getSignature

      @Nullable public static @Nullable Signature<?> getSignature(String name, @Nullable @Nullable String script)
      Gets a signature of local function with the given name, if no signature was found, it will fall back to a global function.
      Parameters:
      name - Name of function.
      script - The script where the function is declared in. Used to get local functions.
      Returns:
      Signature, or null if function does not exist.
    • getScriptNamespace

      @Nullable public static @Nullable Namespace getScriptNamespace(String script)
    • clearFunctions

      @Deprecated public static int clearFunctions(String script)
      Deprecated.
      Remember to call validateFunctions() after calling this
      Returns:
      How many functions were removed
    • unregisterFunction

      public static void unregisterFunction(Signature<?> signature)
    • validateFunctions

      public static void validateFunctions()
    • clearFunctions

      @Deprecated public static void clearFunctions()
      Deprecated.
      Clears all function calls and removes script functions.
    • getJavaFunctions

      public static Collection<JavaFunction<?>> getJavaFunctions()
    • enableFunctionEvents

      public static void enableFunctionEvents(SkriptAddon addon)
      Normally, function calls do not cause actual Bukkit events to be called. If an addon requires such functionality, it should call this method. After doing so, the events will be called. Calling this method many times will not cause any additional changes.

      Note that calling events is not free; performance might vary once you have enabled that.

      Parameters:
      addon - Addon instance.