Class Script
java.lang.Object
org.skriptlang.skript.lang.script.Script
- All Implemented Interfaces:
AnyNamed
,AnyProvider
,Validated
Scripts are the primary container of all code.
Every script is made up of one or more
Structure
s, which contain user-defined instructions and information.
Every script also has its own internal information, such as
custom data, suppressed warnings, and associated event handlers.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Used for listening to events involving a Script. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addData
(ScriptData data) This API is experimental and subject to change. Adds new ScriptData to this Script's data map.void
allowWarning
(ScriptWarning warning) void
This API is experimental and subject to change. Clears the data stored for this script.<Value extends ScriptData>
ValueThis API is experimental and subject to change. A method that always obtains ScriptData matching the specified data type.<Type extends ScriptData>
TypeThis API is experimental and subject to change. A method to obtain ScriptData matching the specified data type.void
Marks this script reference as invalid.name()
This is added to support the legacy script name syntax.void
removeData
(Class<? extends ScriptData> dataType) This API is experimental and subject to change. Removes the ScriptData matching the specified data type.boolean
suppressesWarning
(ScriptWarning warning) void
suppressWarning
(ScriptWarning warning) boolean
valid()
This is a reference to a script (having been loaded); if the script is reloaded, disabled, moved or changed in some way then this object will no longer be a valid reference to it.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.njol.skript.lang.util.common.AnyNamed
setName, supportsNameChange
-
Constructor Details
-
Script
Creates a new Script to be used across the API. Only one Script should be created per Config. A loaded Script may be obtained throughScriptLoader
.- Parameters:
config
- The Config containing the contents of this Script.structures
- The list of Structures contained in this Script.
-
-
Method Details
-
getConfig
- Returns:
- The Config representing the structure of this Script.
-
getStructures
- Returns:
- An unmodifiable list of all Structures within this Script.
-
suppressWarning
- Parameters:
warning
- Suppresses the provided warning for this Script.
-
allowWarning
- Parameters:
warning
- Allows the provided warning for this Script.
-
suppressesWarning
- Parameters:
warning
- The warning to check.- Returns:
- Whether this Script suppresses the provided warning.
-
addData
This API is experimental and subject to change. Adds new ScriptData to this Script's data map.- Parameters:
data
- The data to add.
-
removeData
This API is experimental and subject to change. Removes the ScriptData matching the specified data type.- Parameters:
dataType
- The type of the data to remove.
-
clearData
@Experimental public void clearData()This API is experimental and subject to change. Clears the data stored for this script. -
getData
This API is experimental and subject to change. A method to obtain ScriptData matching the specified data type.- Parameters:
dataType
- The class representing the ScriptData to obtain.- Returns:
- ScriptData found matching the provided class, or null if no data is present.
-
getData
@Experimental public <Value extends ScriptData> Value getData(Class<? extends Value> dataType, Supplier<Value> mapper) This API is experimental and subject to change. A method that always obtains ScriptData matching the specified data type. By using the mapping supplier, it will also add ScriptData of the provided type if it is not already present.- Parameters:
dataType
- The class representing the ScriptData to obtain.mapper
- A supplier to create ScriptData of the provided type if such ScriptData is not already present.- Returns:
- Existing ScriptData found matching the provided class, or new data provided by the mapping function.
-
name
-
nameAndPath
This is added to support the legacy script name syntax. Script names used to be printed including their directory but excluding their file extension.- Returns:
- The script's name, including its path from the script directory, e.g. `games/murder mystery`
-
eventRegistry
- Returns:
- An EventRegistry for this Script's events.
-
invalidate
public void invalidate()Marks this script reference as invalid. Typically invoked during unloading (when its data is discarded).- Specified by:
invalidate
in interfaceValidated
-
valid
public boolean valid()This is a reference to a script (having been loaded); if the script is reloaded, disabled, moved or changed in some way then this object will no longer be a valid reference to it.
If a script reference is not valid, it is not safe to assume that the data in this object is an accurate reflection of the program (e.g. the data could have cleared during unloading, the user might have edited the file and reloaded it, etc.) and it is recommended to obtain a new reference to the script fromScriptLoader
.
-