Package ch.njol.skript.lang.parser
Class ParserInstance
java.lang.Object
ch.njol.skript.lang.parser.ParserInstance
- All Implemented Interfaces:
Experimented
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA Backup represents a ParserInstance at a certain point in time.static classAn abstract class for addons that want to add data bound to a ParserInstance.static interfaceCalled when aScriptis made active or inactive in aParserInstance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExperiment(Experiment experiment) Marks this as using an experimental feature.backup()Creates a backup of this ParserInstance, which represents its current state (excluding any Logging API).voidvoidDeprecated, for removal: This API element is subject to removal in a future version.A snapshot of the experiments this script is currently known to be using.static ParserInstanceget()@Nullable StringClass<? extends org.bukkit.event.Event> @Nullable []Deprecated, for removal: This API element is subject to removal in a future version.UseScript.getData(Class)instead.<T extends TriggerSection>
TgetCurrentSection(Class<T> sectionClass) <T extends TriggerSection>
@NotNull List<T> getCurrentSections(Class<T> sectionClass) @Nullable SkriptEventDeprecated, for removal: This API element is subject to removal in a future version.UsegetCurrentStructure()instead.@Nullable Structure<T extends ParserInstance.Data>
TGet theExperimentSetof the currentScriptYou probably shouldn't use this method.@Nullable NodegetNode()Gets the current parsing stack.getSections(int levels) Returns a list of sections up to the specified number of levels from the current section.getSections(int levels, Class<? extends TriggerSection> type) Returns a list of sections to the specified number of levels from the current section.getSectionsUntil(TriggerSection section) Returns the sections from the current section (inclusive) until the specified section (exclusive).booleanhasExperiment(String featureName) booleanhasExperiment(Experiment experiment) booleanisActive()booleanisCurrentEvent(Class<? extends org.bukkit.event.Event> event) This method checks whether at least one of the current event classes is covered by the argument event class (i.e.final booleanisCurrentEvent(Class<? extends org.bukkit.event.Event>... events) Same asisCurrentEvent(Class), but allows for plural argument input.booleanisCurrentSection(Class<? extends TriggerSection> sectionClass) final booleanisCurrentSection(Class<? extends TriggerSection>... sectionClasses) booleanisCurrentStructure(Class<? extends Structure> structureClass) final booleanisCurrentStructure(Class<? extends Structure>... structureClasses) static booleanisRegistered(Class<? extends ParserInstance.Data> dataClass) static <T extends ParserInstance.Data>
voidregisterData(Class<T> dataClass, Function<ParserInstance, T> dataFunction) Registers a data class to allParserInstances.voidremoveExperiment(Experiment experiment) Marks this as no longer using an experimental feature (e.g.voidreset()Resets this ParserInstance to its default state.voidrestoreBackup(ParserInstance.Backup backup) Restores a backup onto this ParserInstance.voidInternal method for updating a ParserInstance'sisActive()status! You probably don't need to use this method!final voidsetCurrentEvent(String name, @Nullable Class<? extends org.bukkit.event.Event>... events) voidsetCurrentEventName(@Nullable String currentEventName) voidsetCurrentEvents(Class<? extends org.bukkit.event.Event> @Nullable [] currentEvents) voidsetCurrentScript(@Nullable Config currentScript) Deprecated, for removal: This API element is subject to removal in a future version.Addons should no longer be modifying this.voidsetCurrentSections(List<TriggerSection> currentSections) Updates the list of sections currently being handled by this ParserInstance.voidsetCurrentSkriptEvent(@Nullable SkriptEvent currentSkriptEvent) Deprecated, for removal: This API element is subject to removal in a future version.UsesetCurrentStructure(Structure)instead.voidsetCurrentStructure(@Nullable Structure structure) Updates the Structure currently being handled by this ParserInstance.voidsetHasDelayBefore(Kleenean hasDelayBefore) This method should be called to indicate that the trigger will (possibly) be delayed from this point on.voidInternal method for updating a ParserInstance'sisActive()status! You probably don't need to use this method!voidsetIndentation(String indentation) void
-
Constructor Details
-
ParserInstance
public ParserInstance()
-
-
Method Details
-
get
- Returns:
- The
ParserInstancefor this thread.
-
setInactive
@Internal public void setInactive()Internal method for updating a ParserInstance'sisActive()status! You probably don't need to use this method! -
setActive
Internal method for updating a ParserInstance'sisActive()status! You probably don't need to use this method! -
isActive
public boolean isActive()- Returns:
- Whether this ParserInstance is currently active.
An active ParserInstance may be loading, parsing, or unloading scripts.
Please note that some methods may be unavailable if this method returns
false. You should consult the documentation of the method you are calling.
-
reset
public void reset()Resets this ParserInstance to its default state. The only data retained isgetCurrentScript()and any Logging API. -
getCurrentScript
- Returns:
- The Script currently being handled by this ParserInstance.
- Throws:
SkriptAPIException- If this ParserInstance is notisActive().
-
setCurrentStructure
Updates the Structure currently being handled by this ParserInstance.- Parameters:
structure- The new Structure to be handled.
-
getCurrentStructure
- Returns:
- The Structure currently being handled by this ParserInstance.
-
isCurrentStructure
- Returns:
- Whether
getCurrentStructure()is an instance of the given Structure class.
-
isCurrentStructure
@SafeVarargs public final boolean isCurrentStructure(Class<? extends Structure>... structureClasses) - Returns:
- Whether
getCurrentStructure()is an instance of one of the given Structure classes.
-
setCurrentEventName
-
getCurrentEventName
-
setCurrentEvents
- Parameters:
currentEvents- The events that may be present during execution. An instance of the events present in the provided array MUST be used to execute any loaded items.
-
setCurrentEvent
@SafeVarargs public final void setCurrentEvent(String name, @Nullable @Nullable Class<? extends org.bukkit.event.Event>... events) -
deleteCurrentEvent
public void deleteCurrentEvent() -
getCurrentEvents
-
isCurrentEvent
This method checks whether at least one of the current event classes is covered by the argument event class (i.e. equal to the class or a subclass of it).
Using this method in an event-specific syntax element requires a runtime check, for example
if (!(e instanceof BlockBreakEvent)) return null;
This check is required because there can be more than 1 event class at parse-time, but this method only checks if one of them matches the argument class.
See alsoisCurrentEvent(Class[])for checking with multiple argument classes -
isCurrentEvent
Same asisCurrentEvent(Class), but allows for plural argument input.
This means that this method will return whether any of the current event classes is covered by any of the argument classes.
Using this method in an event-specific syntax elementrequires a runtime check, you can useCollectionUtils.isAnyInstanceOf(Object, Class[])for this, for example:
if (!CollectionUtils.isAnyInstanceOf(e, BlockBreakEvent.class, BlockPlaceEvent.class)) return null;- See Also:
-
setCurrentSections
Updates the list of sections currently being handled by this ParserInstance.- Parameters:
currentSections- A new list of sections to handle.
-
getCurrentSections
- Returns:
- A list of all sections this ParserInstance is currently within.
-
getCurrentSection
- Returns:
- The outermost section which is an instance of the given class.
Returns
nullifisCurrentSection(Class)returnsfalse. - See Also:
-
getCurrentSections
@NotNull public <T extends TriggerSection> @NotNull List<T> getCurrentSections(Class<T> sectionClass) - Returns:
- a
Listof current sections that are an instance of the given class. Modifications to the returned list are not saved. - See Also:
-
getSectionsUntil
Returns the sections from the current section (inclusive) until the specified section (exclusive).If we have the following sections:
And we callSection1 └ Section2 └ Section3(we are here)getSectionsUntil(Section1), the result will be[Section2, Section3].- Parameters:
section- The section to stop at. (exclusive)- Returns:
- A list of sections from the current section (inclusive) until the specified section (exclusive).
-
getSections
Returns a list of sections up to the specified number of levels from the current section.If we have the following sections:
And we callSection1 └ Section2 └ Section3(we are here)getSections(2), the result will be[Section2, Section3].- Parameters:
levels- The number of levels to retrieve from the current section upwards. Must be greater than 0.- Returns:
- A list of sections up to the specified number of levels.
- Throws:
IllegalArgumentException- if the levels is less than 1.
-
getSections
Returns a list of sections to the specified number of levels from the current section. Only counting sections of the specified type.If we have the following sections:
And we callSection1 └ LoopSection2 └ Section3 └ LoopSection4(we are here)getSections(2, LoopSection.class), the result will be[LoopSection2, Section3, LoopSection4].- Parameters:
levels- The number of levels to retrieve from the current section upwards. Must be greater than 0.type- The class type of the sections to count.- Returns:
- A list of sections of the specified type up to the specified number of levels.
- Throws:
IllegalArgumentException- if the levels is less than 1.
-
isCurrentSection
- Returns:
- Whether
getCurrentSections()contains a section instance of the given class (or subclass).
-
isCurrentSection
@SafeVarargs public final boolean isCurrentSection(Class<? extends TriggerSection>... sectionClasses) - Returns:
- Whether
getCurrentSections()contains a section instance of one of the given classes (or subclasses).
-
setHasDelayBefore
This method should be called to indicate that the trigger will (possibly) be delayed from this point on.- See Also:
-
getHasDelayBefore
- Returns:
- whether this trigger has had delays before.
Any syntax elements that modify event-values, should use this
(or the
Kleeneanprovided to inSyntaxElement.init(Expression[], int, Kleenean, SkriptParser.ParseResult)) to make sure the event can't be modified when it has passed.
-
getHandlers
You probably shouldn't use this method.- Returns:
- The
HandlerListcontaining all active log handlers.
-
setNode
- Parameters:
node- The node to mark as being handled. This is mainly used for logging. Null means to mark it as no node currently being handled (that the ParserInstance is aware of).
-
getNode
- Returns:
- The node currently marked as being handled. This is mainly used for logging. Null indicates no node is currently being handled (that the ParserInstance is aware of).
-
setIndentation
-
getIndentation
-
getParsingStack
Gets the current parsing stack.Although the stack can be modified, doing so is not recommended.
-
hasExperiment
- Specified by:
hasExperimentin interfaceExperimented- Parameters:
featureName- The name of the experimental feature to test.- Returns:
- Whether this has a feature with the given name.
-
hasExperiment
- Specified by:
hasExperimentin interfaceExperimented- Parameters:
experiment- The experimental feature to test.- Returns:
- Whether this uses the given feature.
-
addExperiment
Marks this as using an experimental feature.- Parameters:
experiment- The feature to register.
-
removeExperiment
Marks this as no longer using an experimental feature (e.g. during de-registration or reload).- Parameters:
experiment- The feature to unregister.
-
experimentSnapshot
A snapshot of the experiments this script is currently known to be using. This is safe to retain during runtime (e.g. to defer a check) but will not see changes, such as if a script subsequently 'uses' another experiment.- Returns:
- A snapshot of the current experiment flags in use,
or an empty experiment set if not
isActive().
-
getExperimentSet
Get theExperimentSetof the currentScript- Returns:
- Experiment set of
getCurrentScript(), or an empty experiment set if notisActive().
-
getHintManager
- Returns:
- The local variable type hint manager for the active parsing process.
-
registerData
public static <T extends ParserInstance.Data> void registerData(Class<T> dataClass, Function<ParserInstance, T> dataFunction) Registers a data class to allParserInstances.- Parameters:
dataClass- the data class to register.dataFunction- an instance creator for the data class.
-
isRegistered
-
getData
- Returns:
- the data object for the given class from this
ParserInstance, or null (afterfalsehas been asserted) if the given data class isn't registered.
-
backup
Creates a backup of this ParserInstance, which represents its current state (excluding any Logging API).- Returns:
- A backup of this ParserInstance.
- See Also:
-
restoreBackup
Restores a backup onto this ParserInstance. That is, this entire ParserInstance, except any Logging API, will be overridden.- Parameters:
backup- The backup to apply.- See Also:
-
getCurrentOptions
Deprecated, for removal: This API element is subject to removal in a future version.UseScript.getData(Class)instead. TheStructOptions.OptionsDataclass should be obtained. Example:script.getData(OptionsData.class) -
getCurrentSkriptEvent
@Deprecated(since="2.7.0", forRemoval=true) @Nullable public @Nullable SkriptEvent getCurrentSkriptEvent()Deprecated, for removal: This API element is subject to removal in a future version.UsegetCurrentStructure()instead. -
setCurrentSkriptEvent
@Deprecated(since="2.7.0", forRemoval=true) public void setCurrentSkriptEvent(@Nullable @Nullable SkriptEvent currentSkriptEvent) Deprecated, for removal: This API element is subject to removal in a future version.UsesetCurrentStructure(Structure)instead. -
deleteCurrentSkriptEvent
Deprecated, for removal: This API element is subject to removal in a future version.UsesetCurrentStructure(Structure)with 'null' instead. -
setCurrentScript
@Deprecated(since="2.7.0", forRemoval=true) public void setCurrentScript(@Nullable @Nullable Config currentScript) Deprecated, for removal: This API element is subject to removal in a future version.Addons should no longer be modifying this.
-
setCurrentStructure(Structure)with 'null' instead.