Class Script

java.lang.Object
org.skriptlang.skript.lang.script.Script
All Implemented Interfaces:
AnyNamed, AnyProvider, Validated

public final class Script extends Object implements Validated, AnyNamed
Scripts are the primary container of all code. Every script is made up of one or more Structures, 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.
  • Constructor Details

    • Script

      @Internal public Script(Config config, List<Structure> structures)
      Creates a new Script to be used across the API. Only one Script should be created per Config. A loaded Script may be obtained through ScriptLoader.
      Parameters:
      config - The Config containing the contents of this Script.
      structures - The list of Structures contained in this Script.
  • Method Details

    • getConfig

      public Config getConfig()
      Returns:
      The Config representing the structure of this Script.
    • getStructures

      public @Unmodifiable List<Structure> getStructures()
      Returns:
      An unmodifiable list of all Structures within this Script.
    • suppressWarning

      public void suppressWarning(ScriptWarning warning)
      Parameters:
      warning - Suppresses the provided warning for this Script.
    • allowWarning

      public void allowWarning(ScriptWarning warning)
      Parameters:
      warning - Allows the provided warning for this Script.
    • suppressesWarning

      public boolean suppressesWarning(ScriptWarning warning)
      Parameters:
      warning - The warning to check.
      Returns:
      Whether this Script suppresses the provided warning.
    • addData

      @Experimental public void addData(ScriptData data)
      This API is experimental and subject to change. Adds new ScriptData to this Script's data map.
      Parameters:
      data - The data to add.
    • removeData

      @Experimental public void removeData(Class<? extends ScriptData> dataType)
      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

      @Experimental @Nullable public <Type extends ScriptData> Type getData(Class<Type> dataType)
      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

      public String name()
      Specified by:
      name in interface AnyNamed
      Returns:
      This thing's name
    • nameAndPath

      public String 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

      public EventRegistry<Script.Event> 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 interface Validated
    • 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 from ScriptLoader.
      Specified by:
      valid in interface Validated
      Returns:
      Whether this script object is a valid reflection of a script