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
Modifier and TypeClassDescriptionstatic class
A class for keeping track of the general content of a script: The amount of files The amount of structures -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Deprecated.static @Nullable String
Deprecated.static @Nullable Class<? extends org.bukkit.event.Event>[]
Deprecated.static List
<ch.njol.skript.sections.SecLoop> Deprecated.static @Nullable Config
Deprecated.static List
<TriggerSection> Deprecated.static FileFilter
static Kleenean
Deprecated.static FileFilter
static @Nullable Script
Searches 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 boolean
isAsync()
Checks if scripts are loaded in separate thread.static boolean
isCurrentEvent
(@Nullable Class<? extends org.bukkit.event.Event> event) Deprecated.static boolean
isCurrentEvent
(Class<? extends org.bukkit.event.Event>... events) Deprecated.static boolean
Checks if scripts are loaded in multiple threads instead of one thread.static int
Deprecated.UsegetLoadedScripts()
.size().static int
Deprecated.UsegetLoadedScripts()
andScript.getStructures()
.size().static ArrayList
<TriggerItem> loadItems
(SectionNode node) Loads a section by converting it toTriggerItem
s.static ScriptLoader.ScriptInfo
loadScripts
(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.ScriptInfo
loadScripts
(List<Config> configs) Deprecated.Callers should not be using configs.static ScriptLoader.ScriptInfo
loadScripts
(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 Config
loadStructure
(Config config) Deprecated.This method has no functionality, it just returns its input.static ScriptLoader.ScriptInfo
reloadScript
(File script) Deprecated.reloadScript
(File scriptFile, OpenCloseable openCloseable) Deprecated.reloadScript
(Script script, OpenCloseable openCloseable) Reloads a single Script.static ScriptLoader.ScriptInfo
reloadScripts
(File folder) Deprecated.reloadScripts
(File folder, OpenCloseable openCloseable) reloadScripts
(Set<Script> scripts, OpenCloseable openCloseable) Reloads all provided Scripts.static String
replaceOptions
(String string) Replaces options in a string.static void
setAsyncLoaderSize
(int size) Sets the amount of async loaders, by updatingasyncLoaderSize
andloaderThreads
.static void
setCurrentEvent
(String name, @Nullable Class<? extends org.bukkit.event.Event>... events) Deprecated.static void
setCurrentLoops
(List<ch.njol.skript.sections.SecLoop> currentLoops) Deprecated.Never use this method, it has no effect.static void
setCurrentScript
(@Nullable Config currentScript) Deprecated.Addons should no longer be modifying this.static void
setCurrentSections
(List<TriggerSection> currentSections) Deprecated.static void
setHasDelayBefore
(Kleenean hasDelayBefore) Deprecated.static ScriptLoader.ScriptInfo
unloadScript
(File scriptFile) Deprecated.UseunloadScript(Script)
.static ScriptLoader.ScriptInfo
unloadScript
(Script script) Unloads the provided script.static ScriptLoader.ScriptInfo
unloadScripts
(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 updatingasyncLoaderSize
andloaderThreads
.
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
- AnOpenCloseable
that 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
- AnOpenCloseable
that 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
- AnOpenCloseable
that 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 toTriggerItem
s. -
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.
-
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 org.bukkit.event.Event>... events) Deprecated. -
deleteCurrentEvent
Deprecated. -
isCurrentEvent
@Deprecated public static boolean isCurrentEvent(@Nullable @Nullable Class<? extends org.bukkit.event.Event> event) Deprecated. -
isCurrentEvent
@SafeVarargs @Deprecated public static boolean isCurrentEvent(Class<? extends org.bukkit.event.Event>... events) Deprecated. -
getCurrentEvents
@Nullable @Deprecated public static @Nullable Class<? extends org.bukkit.event.Event>[] getCurrentEvents()Deprecated. -
loadStructure
Deprecated.This method has no functionality, it just returns its input.
-
ParserInstance.deleteCurrentEvent()
.