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
- Direct Known Subclasses:
EffectSection
,LoopSection
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
-
Field Summary
Fields inherited from class ch.njol.skript.lang.TriggerSection
first, last
Fields inherited from class ch.njol.skript.lang.TriggerItem
parent
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
init
(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) This method should not be overridden unless you know what you are doing!abstract boolean
init
(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult, SectionNode sectionNode, List<TriggerItem> triggerItems) protected void
loadCode
(SectionNode sectionNode) Loads the code in the givenSectionNode
, appropriately modifyingParserInstance.getCurrentSections()
.protected final Trigger
loadCode
(SectionNode sectionNode, String name, @Nullable Runnable afterLoading, Class<? extends org.bukkit.event.Event>... events) Loads the code in the givenSectionNode
, appropriately modifyingParserInstance.getCurrentSections()
.protected final Trigger
loadCode
(SectionNode sectionNode, String name, Class<? extends org.bukkit.event.Event>... events) Loads the code in the givenSectionNode
, appropriately modifyingParserInstance.getCurrentSections()
.protected void
loadOptionalCode
(SectionNode sectionNode) Loads the code usingloadCode(SectionNode)
.static @Nullable Section
parse
(String expr, @Nullable String defaultError, SectionNode sectionNode, List<TriggerItem> triggerItems) Methods inherited from class ch.njol.skript.lang.TriggerSection
run, setNext, setParent, setTriggerItems, walk, walk
Methods inherited from class ch.njol.skript.lang.TriggerItem
debug, getIndentation, getNext, getParent, getTrigger, toString, walk
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.njol.skript.lang.Debuggable
toString
Methods inherited from interface ch.njol.skript.lang.SyntaxElement
getParser
-
Constructor Details
-
Section
public Section()
-
-
Method Details
-
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:
init
in 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 protected final Trigger loadCode(SectionNode sectionNode, String name, @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. TheParserInstance
is modified to reflect that understanding.- Parameters:
sectionNode
- The section node to load.name
- The name of the event(s) being used.afterLoading
- A Runnable to execute after the SectionNode has been loaded. This occurs beforeParserInstance
states are reset.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 settinghasDelayBefore
toKleenean.UNKNOWN
if 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)
-