Package ch.njol.skript.lang
Class Section
java.lang.Object
ch.njol.skript.lang.TriggerItem
ch.njol.skript.lang.TriggerSection
ch.njol.skript.lang.Section
- All Implemented Interfaces:
Debuggable,SyntaxElement,RuntimeErrorProducer,SyntaxRuntimeErrorProducer
- Direct Known Subclasses:
EffectSection,ExpressionSection,LoopSection
public abstract class Section
extends TriggerSection
implements SyntaxElement, SyntaxRuntimeErrorProducer
A section that can decide what it does with its contents, as code isn't parsed by default.
In most cases though, a section should load its code through one of the following loading methods:
Every section must override the
In the walk method, it is recommended that you return
In most cases though, a section should load its code through one of the following loading methods:
loadCode(SectionNode), loadCode(SectionNode, String, Class[]), loadOptionalCode(SectionNode)
Every section must override the
TriggerSection.walk(Event) method. In this method, you can determine whether * the section should run. If you have stored a Trigger from loadCode(SectionNode, String, Class[]), you
should not run it with this event passed in this walk method.
In the walk method, it is recommended that you return
TriggerSection.walk(Event, boolean).
This method is very useful, as it will handle most of the things you need to do.
The boolean parameter for the method determines whether the section should run.
If it is true, Skript will attempt to run the section's code if it has been loaded. If the section's code hasn't been loaded, Skript will behave as if false was passed.
If it is false, Skript will just move onto the next syntax element after this section.
So, if you are using a normal section and your code should run immediately, you should just return the result of this method with true for the parameter.
However, in cases where you have loaded your code into a trigger using loadCode(SectionNode, String, Class[]), it does not matter
if true or false is passed, as the section's code was never actually loaded into the current trigger. Please note that this will result in
all code after the section to run. If you wish to delay the entire execution, you should return null and Skript will not continue on.
You should generally make sure that code after the section will run at some point though.
Also note, that if you aren't returning the result of TriggerSection.walk(Event, boolean),
you should probably call TriggerItem.debug(Event, boolean). The boolean parameter should be false in most cases.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classData stored in theParserInstanceto keep track of the current section being parsed. -
Field Summary
Fields inherited from class ch.njol.skript.lang.TriggerSection
first, lastFields inherited from class ch.njol.skript.lang.TriggerItem
parent -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetNode()Returns the sourceNodefor any errors the implementing class emits.@NotNull Stringbooleaninit(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) This method should not be overridden unless you know what you are doing!abstract booleaninit(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult, SectionNode sectionNode, List<TriggerItem> triggerItems) protected voidloadCode(SectionNode sectionNode) Loads the code in the givenSectionNode, appropriately modifyingParserInstance.getCurrentSections().protected final TriggerloadCode(SectionNode sectionNode, String name, @Nullable Runnable beforeLoading, @Nullable Runnable afterLoading, Class<? extends org.bukkit.event.Event>... events) Loads the code in the givenSectionNode, appropriately modifyingParserInstance.getCurrentSections().protected final TriggerloadCode(SectionNode sectionNode, String name, @Nullable Runnable afterLoading, Class<? extends org.bukkit.event.Event>... events) Deprecated, for removal: This API element is subject to removal in a future version.protected final TriggerloadCode(SectionNode sectionNode, String name, Class<? extends org.bukkit.event.Event>... events) Loads the code in the givenSectionNode, appropriately modifyingParserInstance.getCurrentSections().protected voidloadOptionalCode(SectionNode sectionNode) Loads the code usingloadCode(SectionNode).static @Nullable Sectionparse(String expr, @Nullable String defaultError, SectionNode sectionNode, List<TriggerItem> triggerItems) booleanpreInit()Called immediately after the constructor.Methods inherited from class ch.njol.skript.lang.TriggerSection
run, setNext, setParent, setTriggerItems, triggerExecutionIntent, walk, walkMethods inherited from class ch.njol.skript.lang.TriggerItem
debug, executionIntent, getActualNext, getIndentation, getNext, getParent, getTrigger, toString, walkMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ch.njol.skript.lang.Debuggable
toStringMethods inherited from interface org.skriptlang.skript.log.runtime.RuntimeErrorProducer
error, error, getRuntimeErrorManager, warning, warningMethods inherited from interface ch.njol.skript.lang.SyntaxElement
getParserMethods inherited from interface org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer
getErrorSource
-
Constructor Details
-
Section
public Section()
-
-
Method Details
-
preInit
public boolean preInit()Description copied from interface:SyntaxElementCalled immediately after the constructor. This should be used to do any work that need to be done prior to downstream initialization. This is not intended to be used by syntaxes directly, but by parent classes to do work prior to the initialization of the child classes.- Specified by:
preInitin interfaceSyntaxElement- Returns:
- Whether this expression was pre-initialised successfully. An error should be printed prior to returning false to specify the cause.
-
init
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) This method should not be overridden unless you know what you are doing!- Specified by:
initin interfaceSyntaxElement- Parameters:
expressions- all %expr%s included in the matching pattern in the order they appear in the pattern. If an optional value was left out, it will still be included in this list holding the default value of the desired type, which usually depends on the event.matchedPattern- The index of the pattern which matchedisDelayed- Whether this expression is used after a delay or not (i.e. if the event has already passed when this expression will be called)parseResult- Additional information about the match.- Returns:
- Whether this expression was initialised successfully. An error should be printed prior to returning false to specify the cause.
- See Also:
-
init
public abstract boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult, SectionNode sectionNode, List<TriggerItem> triggerItems) -
loadCode
Loads the code in the givenSectionNode, appropriately modifyingParserInstance.getCurrentSections().
This method itself does not modifyParserInstance.getHasDelayBefore()(although the loaded code may change it), the calling code must deal with this. -
loadCode
@SafeVarargs protected final Trigger loadCode(SectionNode sectionNode, String name, Class<? extends org.bukkit.event.Event>... events) Loads the code in the givenSectionNode, appropriately modifyingParserInstance.getCurrentSections().
This method differs fromloadCode(SectionNode)in that it is meant for code that will be executed in a different event.- Parameters:
sectionNode- The section node to load.name- The name of the event(s) being used.events- The event(s) during the section's execution.- Returns:
- A trigger containing the loaded section. This should be stored and used to run the section one or more times.
-
loadCode
@SafeVarargs @Deprecated(since="2.12", forRemoval=true) protected final Trigger loadCode(SectionNode sectionNode, String name, @Nullable @Nullable Runnable afterLoading, Class<? extends org.bukkit.event.Event>... events) Deprecated, for removal: This API element is subject to removal in a future version. -
loadCode
@SafeVarargs protected final Trigger loadCode(SectionNode sectionNode, String name, @Nullable @Nullable Runnable beforeLoading, @Nullable @Nullable Runnable afterLoading, Class<? extends org.bukkit.event.Event>... events) Loads the code in the givenSectionNode, appropriately modifyingParserInstance.getCurrentSections().
This method differs fromloadCode(SectionNode)in that it is meant for code that will be executed at another time and potentially with different context. The section's contents are parsed with the understanding that they have no relation to the section itself, along with any other code that may come before and after the section. TheParserInstanceis modified to reflect that understanding.- Parameters:
sectionNode- The section node to load.name- The name of the event(s) being used.beforeLoading- A Runnable to execute before the SectionNode has been loaded. This occurs after theParserInstancecontext switch.afterLoading- A Runnable to execute after the SectionNode has been loaded. This occurs beforeParserInstancestates are reset (context switches back).events- The event(s) during the section's execution.- Returns:
- A trigger containing the loaded section. This should be stored and used to run the section one or more times.
-
loadOptionalCode
Loads the code usingloadCode(SectionNode).
This method also adjustsParserInstance.getHasDelayBefore()to expect the code to be called zero or more times. This is done by settinghasDelayBeforetoKleenean.UNKNOWNif the loaded section has a possible or definite delay in it. -
parse
@Nullable public static @Nullable Section parse(String expr, @Nullable @Nullable String defaultError, SectionNode sectionNode, List<TriggerItem> triggerItems) -
getNode
Description copied from interface:SyntaxRuntimeErrorProducerReturns the sourceNodefor any errors the implementing class emits.
Used for accessing the line contents viaNode.getKey()and the line number viaNode.getLine().
A standard implementation is to store the Node duringSyntaxElement.init(Expression[], int, Kleenean, SkriptParser.ParseResult)viaParserInstance.getNode().- Specified by:
getNodein interfaceSyntaxRuntimeErrorProducer- Returns:
- The source that produced a runtime error.
-
getSyntaxTypeName
- Specified by:
getSyntaxTypeNamein interfaceSyntaxElement- Returns:
- A string naming the type of syntax this is. e.g. "expression", "section".
-
loadCode(SectionNode, String, Runnable, Runnable, Class[])