Package ch.njol.skript.lang.parser
Class ParserInstance
java.lang.Object
ch.njol.skript.lang.parser.ParserInstance
- All Implemented Interfaces:
Experimented
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A Backup represents a ParserInstance at a certain point in time.static class
An abstract class for addons that want to add data bound to a ParserInstance. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addExperiment
(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).void
void
Deprecated.A snapshot of the experiments this script is currently known to be using.static ParserInstance
get()
@Nullable String
Class<? extends org.bukkit.event.Event> @Nullable []
Deprecated.UseScript.getData(Class)
instead.<T extends TriggerSection>
TgetCurrentSection
(Class<T> sectionClass) <T extends TriggerSection>
@NotNull List<T> getCurrentSections
(Class<T> sectionClass) @Nullable SkriptEvent
Deprecated.@Nullable Structure
<T extends ParserInstance.Data>
TYou probably shouldn't use this method.@Nullable Node
getNode()
boolean
hasExperiment
(String featureName) boolean
hasExperiment
(Experiment experiment) boolean
isActive()
boolean
isCurrentEvent
(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 boolean
isCurrentEvent
(Class<? extends org.bukkit.event.Event>... events) Same asisCurrentEvent(Class)
, but allows for plural argument input.boolean
isCurrentSection
(Class<? extends TriggerSection> sectionClass) final boolean
isCurrentSection
(Class<? extends TriggerSection>... sectionClasses) boolean
isCurrentStructure
(Class<? extends Structure> structureClass) final boolean
isCurrentStructure
(Class<? extends Structure>... structureClasses) static boolean
isRegistered
(Class<? extends ParserInstance.Data> dataClass) static <T extends ParserInstance.Data>
voidregisterData
(Class<T> dataClass, Function<ParserInstance, T> dataFunction) Registers a data class to allParserInstance
s.void
removeExperiment
(Experiment experiment) Marks this as no longer using an experimental feature (e.g.void
reset()
Resets this ParserInstance to its default state.void
restoreBackup
(ParserInstance.Backup backup) Restores a backup onto this ParserInstance.void
Internal method for updating a ParserInstance'sisActive()
status! You probably don't need to use this method!final void
setCurrentEvent
(String name, @Nullable Class<? extends org.bukkit.event.Event>... events) void
setCurrentEventName
(@Nullable String currentEventName) void
setCurrentEvents
(Class<? extends org.bukkit.event.Event> @Nullable [] currentEvents) void
setCurrentScript
(@Nullable Config currentScript) Deprecated.Addons should no longer be modifying this.void
setCurrentSections
(List<TriggerSection> currentSections) Updates the list of sections currently being handled by this ParserInstance.void
setCurrentSkriptEvent
(@Nullable SkriptEvent currentSkriptEvent) Deprecated.void
setCurrentStructure
(@Nullable Structure structure) Updates the Structure currently being handled by this ParserInstance.void
setHasDelayBefore
(Kleenean hasDelayBefore) This method should be called to indicate that the trigger will (possibly) be delayed from this point on.void
Internal method for updating a ParserInstance'sisActive()
status! You probably don't need to use this method!void
setIndentation
(String indentation) void
-
Constructor Details
-
ParserInstance
public ParserInstance()
-
-
Method Details
-
get
- Returns:
- The
ParserInstance
for 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
null
ifisCurrentSection(Class)
returnsfalse
. - See Also:
-
getCurrentSections
@NotNull public <T extends TriggerSection> @NotNull List<T> getCurrentSections(Class<T> sectionClass) - Returns:
- a
List
of current sections that are an instance of the given class. Modifications to the returned list are not saved. - See Also:
-
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
Kleenean
provided 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
HandlerList
containing 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
-
hasExperiment
- Specified by:
hasExperiment
in interfaceExperimented
- Parameters:
featureName
- The name of the experimental feature to test.- Returns:
- Whether this has a feature with the given name.
-
hasExperiment
- Specified by:
hasExperiment
in 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
-
registerData
public static <T extends ParserInstance.Data> void registerData(Class<T> dataClass, Function<ParserInstance, T> dataFunction) Registers a data class to allParserInstance
s.- 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 (afterfalse
has 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.UseScript.getData(Class)
instead. TheStructOptions.OptionsData
class should be obtained. Example:script.getData(OptionsData.class)
-
getCurrentSkriptEvent
Deprecated. -
setCurrentSkriptEvent
Deprecated. -
deleteCurrentSkriptEvent
Deprecated.UsesetCurrentStructure(Structure)
with 'null'. -
setCurrentScript
Deprecated.Addons should no longer be modifying this.
-
setCurrentStructure(Structure)
with 'null'.