Package ch.njol.skript
Class ScriptLoader
java.lang.Object
ch.njol.skript.ScriptLoader
The main class for loading, unloading and reloading scripts.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceUsed for listening to events involving a ScriptLoader.static classA class for keeping track of the general content of a script: The amount of files The amount of structuresstatic interfaceCalled when aScriptis created and preloaded in theScriptLoader.static interfaceCalled when aScriptis loaded in theScriptLoader.static interfacestatic interfaceCalled when aScriptis unloaded in theScriptLoader. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidDeprecated.static @Nullable StringDeprecated.Deprecated.static List<ch.njol.skript.sections.SecLoop> Deprecated.static @Nullable ConfigDeprecated.static List<TriggerSection> Deprecated.static FileFilterstatic KleeneanDeprecated.static FileFilterstatic @Nullable ScriptSearches through the loaded scripts to find the script loaded from the provided file.getScripts(File directory) Searches through the loaded scripts to find all scripts loaded from the files contained within the provided directory.static booleanisAsync()Checks if scripts are loaded in separate thread.static booleanisCurrentEvent(@Nullable Class<? extends Event> event) Deprecated.static booleanisCurrentEvent(Class<? extends Event>... events) Deprecated.static booleanChecks if scripts are loaded in multiple threads instead of one thread.static intDeprecated.UsegetLoadedScripts().size().static intDeprecated.UsegetLoadedScripts()andScript.getStructures().size().static ArrayList<TriggerItem> loadItems(SectionNode node) Loads a section by converting it toTriggerItems.static ScriptLoader.ScriptInfoloadScripts(Config... configs) Deprecated.Callers should not be using configs.loadScripts(File file, OpenCloseable openCloseable) Loads the Script present at the file usingloadScripts(List, OpenCloseable), sending info/error messages when done.static ScriptLoader.ScriptInfoloadScripts(List<Config> configs) Deprecated.Callers should not be using configs.static ScriptLoader.ScriptInfoloadScripts(List<Config> configs, List<LogEntry> logOut) Deprecated.Callers should not be using configs.loadScripts(Set<File> files, OpenCloseable openCloseable) Loads the Scripts present at the files usingloadScripts(List, OpenCloseable), sending info/error messages when done.static ConfigloadStructure(Config config) Deprecated.This method has no functionality, it just returns its input.static ScriptLoader.ScriptInforeloadScript(File script) Deprecated.reloadScript(File scriptFile, OpenCloseable openCloseable) Deprecated.reloadScript(Script script, OpenCloseable openCloseable) Reloads a single Script.static ScriptLoader.ScriptInforeloadScripts(File folder) Deprecated.reloadScripts(File folder, OpenCloseable openCloseable) reloadScripts(Set<Script> scripts, OpenCloseable openCloseable) Reloads all provided Scripts.static StringreplaceOptions(String string) Replaces options in a string.static voidsetAsyncLoaderSize(int size) Sets the amount of async loaders, by updatingasyncLoaderSizeandloaderThreads.static voidsetCurrentEvent(String name, @Nullable Class<? extends Event>... events) Deprecated.static voidsetCurrentLoops(List<ch.njol.skript.sections.SecLoop> currentLoops) Deprecated.Never use this method, it has no effect.static voidsetCurrentScript(@Nullable Config currentScript) Deprecated.Addons should no longer be modifying this.static voidsetCurrentSections(List<TriggerSection> currentSections) Deprecated.static voidsetHasDelayBefore(Kleenean hasDelayBefore) Deprecated.static ScriptLoader.ScriptInfounloadScript(File scriptFile) Deprecated.UseunloadScript(Script).static ScriptLoader.ScriptInfounloadScript(Script script) Unloads the provided script.static ScriptLoader.ScriptInfounloadScripts(Set<Script> scripts) Unloads all scripts present in the provided collection.
-
Field Details
-
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
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
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
Sets the amount of async loaders, by updatingasyncLoaderSizeandloaderThreads.
Ifsize <= 0, async and parallel loading are disabled.
Ifsize == 1, async loading is enabled but parallel loading is disabled.
Ifsize >= 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 usingloadScripts(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- AnOpenCloseablethat will be called before and after each individual script load (seemakeFuture(Supplier, OpenCloseable)).
-
loadScripts
public static CompletableFuture<ScriptLoader.ScriptInfo> loadScripts(Set<File> files, OpenCloseable openCloseable) Loads the Scripts present at the files usingloadScripts(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- AnOpenCloseablethat will be called before and after each individual script load (seemakeFuture(Supplier, OpenCloseable)).
-
unloadScripts
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
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- AnOpenCloseablethat will be called before and after each individual Script load (seemakeFuture(Supplier, OpenCloseable)).- Returns:
- Info on the loaded Scripts.
-
replaceOptions
Replaces options in a string. Options are obtained from aScript'sStructOptions.OptionsData. Example:script.getData(OptionsData.class) -
loadItems
Loads a section by converting it toTriggerItems. -
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
- 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
- Returns:
- A FileFilter defining the naming conditions of a loaded script.
-
getDisabledScriptsFilter
- Returns:
- A FileFilter defining the naming conditions of a disabled script.
-
eventRegistry
- Returns:
- An EventRegistry for the ScriptLoader's events.
-
unloadScript
Deprecated.UseunloadScript(Script).Unloads the provided script.- Parameters:
scriptFile- The file representing the script to unload.- Returns:
- Statistics for the unloaded script.
-
reloadScript
@Deprecated public static CompletableFuture<ScriptLoader.ScriptInfo> reloadScript(File scriptFile, OpenCloseable openCloseable) Deprecated.Reloads a single script.- Parameters:
scriptFile- The file representing the script to reload.- Returns:
- Future of statistics of the newly loaded script.
-
reloadScripts
@Deprecated public static CompletableFuture<ScriptLoader.ScriptInfo> reloadScripts(File folder, OpenCloseable openCloseable) Deprecated.Reloads all scripts in the given folder and its subfolders.- Parameters:
folder- A folder.- Returns:
- Future of statistics of newly loaded scripts.
-
loadedScripts
Deprecated.UsegetLoadedScripts().size(). -
loadedTriggers
Deprecated.UsegetLoadedScripts()andScript.getStructures().size(). Please note that a Structure may have multiple triggers, and this is only an estimate. -
loadScripts
Deprecated.Callers should not be using configs. UseloadScripts(Set, OpenCloseable). -
loadScripts
@Deprecated public static ScriptLoader.ScriptInfo loadScripts(List<Config> configs, List<LogEntry> logOut) Deprecated.Callers should not be using configs. UseloadScripts(Set, OpenCloseable).- See Also:
-
loadScripts
Deprecated.Callers should not be using configs. UseloadScripts(Set, OpenCloseable). -
reloadScript
Deprecated. -
reloadScripts
Deprecated. -
getHasDelayBefore
Deprecated. -
setHasDelayBefore
Deprecated. -
getCurrentScript
Deprecated. -
setCurrentScript
Deprecated.Addons should no longer be modifying this. -
getCurrentSections
Deprecated. -
setCurrentSections
Deprecated. -
getCurrentLoops
Deprecated. -
setCurrentLoops
Deprecated.Never use this method, it has no effect. -
getCurrentEventName
Deprecated. -
setCurrentEvent
@SafeVarargs @Deprecated public static void setCurrentEvent(String name, @Nullable @Nullable Class<? extends Event>... events) Deprecated. -
deleteCurrentEvent
Deprecated. -
isCurrentEvent
Deprecated. -
isCurrentEvent
Deprecated. -
getCurrentEvents
Deprecated. -
loadStructure
Deprecated.This method has no functionality, it just returns its input.
-
ParserInstance.deleteCurrentEvent().