Class SkriptEvent
java.lang.Object
io.github.syst3ms.skriptparser.lang.event.SkriptEvent
- All Implemented Interfaces:
SyntaxElement
- Direct Known Subclasses:
EvtAtTime, EvtPeriodical, EvtScriptLoad, EvtWhen, Structure
The entry point for all code in Skript. Once an event triggers, all of the code inside it may be run.
Skript-parser's event system is composed of three interacting parts : Trigger, SkriptEvent and TriggerContext.
This is directly parallel to Skript's event system, with Bukkit's own Event class replacing TriggerContext.
Let's explain how this system works using a simple analogy : skript-parser is like a giant kitchen :
- The goal is to prepare food (write code).
- There are many different types of food to prepare (
TriggerContexts). - There are different means of actually preparing the food (different
SkriptEvents), each one being specific to one or more types of food - Finally, in order to make the recipe come together, one needs the physical, tangible tools to achieve that (
Triggers)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTrigger(String scriptName, Trigger trigger) abstract booleancheck(TriggerContext ctx) Whether this event should trigger, given theTriggerContextvoidclearTrigger(String scriptName) Set<Class<? extends SyntaxElement>> A list of the classes of every syntax that is allowed to be used inside of this SkriptEvent.intFor virtually all programming and scripting languages, the need exists to have functions in order to not repeat code too often.booleaninit(Expression<?>[] expressions, int matchedPattern, ParseContext parseContext) Initializes this SyntaxElement before being used.booleanWhether the syntax restrictions outlined ingetAllowedSyntaxes()should also apply to expressions.loadSection(FileSection section, ParserState parserState, SkriptLogger logger) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SyntaxElement
toString
-
Constructor Details
-
SkriptEvent
public SkriptEvent()
-
-
Method Details
-
getTriggers
-
addTrigger
-
clearTrigger
-
check
Whether this event should trigger, given theTriggerContext- Parameters:
ctx- the TriggerContext to check- Returns:
- whether the event should trigger
-
loadSection
public List<Statement> loadSection(FileSection section, ParserState parserState, SkriptLogger logger) -
init
Description copied from interface:SyntaxElementInitializes this SyntaxElement before being used. This method is always called before all the others in an extending class, the only exception beingCodeSection.loadSection(FileSection, ParserState, SkriptLogger).- Specified by:
initin interfaceSyntaxElement- Parameters:
expressions- an array of expressions representing all the expressions that are being passed to this syntax element. As opposed to Skript, elements of this array can't benull.matchedPattern- the index of the pattern that was successfully matched. It corresponds to the order of the syntaxes in registrationparseContext- an object containing additional information about the parsing of this syntax element, like regex matches and parse marks- Returns:
trueif the syntax element was initialized successfully,falseotherwise.- See Also:
-
getLoadingPriority
public int getLoadingPriority()For virtually all programming and scripting languages, the need exists to have functions in order to not repeat code too often. Skript is no exception, however, by default, every trigger is loaded in the order it appears in the file, This is undesirable if we don't want the restriction of having to declare functions before using them. This is especially counter-productive if we're dealing with multiple scripts.To solve this problem,
triggerswith a higher loading priority number will be loaded first.- Returns:
- the loading priority number. 0 by default
-
getAllowedSyntaxes
A list of the classes of every syntax that is allowed to be used inside of this SkriptEvent. The default behavior is to return an empty list, which equates to no restrictions. If overridden, this allows the creation of specialized, DSL-like sections in which only select statements and other sections (and potentially, but not necessarily, expressions).- Returns:
- a list of the classes of each syntax allowed inside this SkriptEvent
or
nullif you don't want to allow any - See Also:
-
isRestrictingExpressions
public boolean isRestrictingExpressions()Whether the syntax restrictions outlined ingetAllowedSyntaxes()should also apply to expressions. This is usually undesirable, so it is false by default.This should return true if and only if
getAllowedSyntaxes()contains an Expression class.- Returns:
- whether the use of expressions is also restricted by
getAllowedSyntaxes(). False by default.
-