Class ScriptLoader

java.lang.Object
ch.njol.skript.ScriptLoader

public class ScriptLoader extends Object
The main class for loading, unloading and reloading scripts.
  • Field Details

    • DISABLED_SCRIPT_PREFIX

      public static final String DISABLED_SCRIPT_PREFIX
      See Also:
    • DISABLED_SCRIPT_PREFIX_LENGTH

      public static final int DISABLED_SCRIPT_PREFIX_LENGTH
  • Constructor Details

    • ScriptLoader

      public ScriptLoader()
  • Method Details

    • getScript

      @Nullable public static @Nullable Script getScript(File file)
      Searches through the loaded scripts to find the script loaded from the provided file.
      Parameters:
      file - The file containing the script to find. Must not be a directory.
      Returns:
      The script loaded from the provided file, or null if no script was found.
    • getScripts

      public static Set<Script> getScripts(File directory)
      Searches through the loaded scripts to find all scripts loaded from the files contained within the provided directory.
      Parameters:
      directory - The directory containing scripts to find.
      Returns:
      The scripts loaded from the files of the provided directory. Empty if no scripts were found.
    • isAsync

      public static boolean isAsync()
      Checks if scripts are loaded in separate thread. If true, following behavior should be expected:
      • Scripts are still unloaded and enabled in server thread
      • When reloading a script, old version is unloaded after it has been parsed, immediately before it has been loaded
      • When reloading all scripts, scripts that were removed are disabled after everything has been reloaded
      • Script infos returned by most methods are inaccurate
      Returns:
      If main thread is not blocked when loading.
    • isParallel

      public static boolean isParallel()
      Checks if scripts are loaded in multiple threads instead of one thread. If true, isAsync() will also be true.
      Returns:
      if parallel loading is enabled.
    • setAsyncLoaderSize

      public static void setAsyncLoaderSize(int size) throws IllegalStateException
      Sets the amount of async loaders, by updating asyncLoaderSize and loaderThreads.
      If size <= 0, async and parallel loading are disabled.
      If size == 1, async loading is enabled but parallel loading is disabled.
      If size >= 2, async and parallel loading are enabled.
      Parameters:
      size - the amount of async loaders to use.
      Throws:
      IllegalStateException
    • loadScripts

      public static CompletableFuture<ScriptLoader.ScriptInfo> loadScripts(File file, OpenCloseable openCloseable)
      Loads the Script present at the file using loadScripts(List, OpenCloseable), sending info/error messages when done.
      Parameters:
      file - The file to load. If this is a directory, all scripts within the directory and any subdirectories will be loaded.
      openCloseable - An OpenCloseable that will be called before and after each individual script load (see makeFuture(Supplier, OpenCloseable)).
    • loadScripts

      public static CompletableFuture<ScriptLoader.ScriptInfo> loadScripts(Set<File> files, OpenCloseable openCloseable)
      Loads the Scripts present at the files using loadScripts(List, OpenCloseable), sending info/error messages when done.
      Parameters:
      files - The files to load. If any file is a directory, all scripts within the directory and any subdirectories will be loaded.
      openCloseable - An OpenCloseable that will be called before and after each individual script load (see makeFuture(Supplier, OpenCloseable)).
    • unloadScripts

      public static ScriptLoader.ScriptInfo unloadScripts(Set<Script> scripts)
      Unloads all scripts present in the provided collection.
      Parameters:
      scripts - The scripts to unload.
      Returns:
      Combined statistics for the unloaded scripts. This data is calculated by using ScriptLoader.ScriptInfo.add(ScriptInfo).
    • unloadScript

      public static ScriptLoader.ScriptInfo unloadScript(Script script)
      Unloads the provided script.
      Parameters:
      script - The script to unload.
      Returns:
      Statistics for the unloaded script.
    • reloadScript

      public static CompletableFuture<ScriptLoader.ScriptInfo> reloadScript(Script script, OpenCloseable openCloseable)
      Reloads a single Script.
      Parameters:
      script - The Script to reload.
      Returns:
      Info on the loaded Script.
    • reloadScripts

      public static CompletableFuture<ScriptLoader.ScriptInfo> reloadScripts(Set<Script> scripts, OpenCloseable openCloseable)
      Reloads all provided Scripts.
      Parameters:
      scripts - The Scripts to reload.
      openCloseable - An OpenCloseable that will be called before and after each individual Script load (see makeFuture(Supplier, OpenCloseable)).
      Returns:
      Info on the loaded Scripts.
    • replaceOptions

      public static String replaceOptions(String string)
      Replaces options in a string. Options are obtained from a Script's StructOptions.OptionsData. Example: script.getData(OptionsData.class)
    • loadItems

      public static ArrayList<TriggerItem> loadItems(SectionNode node)
      Loads a section by converting it to TriggerItems.
    • createDummyScript

      @Internal public static Script createDummyScript(String name, @Nullable @Nullable File file)
      Creates a Script object for a file (or resource) that may (or may not) exist. This is used for providing handles for disabled scripts.
      This does not load (or parse or open or do anything to) the given file.
      Returns:
      An unlinked, empty script object with an empty backing config
    • getLoadedScripts

      public static Set<Script> getLoadedScripts()
      Returns:
      An unmodifiable set containing a snapshot of the currently loaded scripts. Any changes to loaded scripts will not be reflected in the returned set.
    • getDisabledScripts

      public static Set<File> getDisabledScripts()
      Returns:
      An unmodifiable set containing a snapshot of the currently disabled scripts. Any changes to disabled scripts will not be reflected in the returned set.
    • getLoadedScriptsFilter

      public static FileFilter getLoadedScriptsFilter()
      Returns:
      A FileFilter defining the naming conditions of a loaded script.
    • getDisabledScriptsFilter

      public static FileFilter getDisabledScriptsFilter()
      Returns:
      A FileFilter defining the naming conditions of a disabled script.
    • eventRegistry

      public static EventRegistry<ScriptLoader.LoaderEvent> eventRegistry()
      Returns:
      An EventRegistry for the ScriptLoader's events.
    • getScriptFromName

      @Nullable public static @Nullable File getScriptFromName(String script)
      Gets a script's file from its name, if one exists.
      Parameters:
      script - The script name/path
      Returns:
      The script file, if one is found