Class SkriptEvent

java.lang.Object
io.github.syst3ms.skriptparser.lang.event.SkriptEvent
All Implemented Interfaces:
SyntaxElement
Direct Known Subclasses:
EvtAtTime, EvtPeriodical, EvtScriptLoad, EvtWhen, Structure

public abstract class SkriptEvent extends Object implements SyntaxElement
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 Details

    • SkriptEvent

      public SkriptEvent()
  • Method Details

    • getTriggers

      public List<Trigger> getTriggers()
    • addTrigger

      public void addTrigger(String scriptName, Trigger trigger)
    • clearTrigger

      public void clearTrigger(String scriptName)
    • check

      public abstract boolean check(TriggerContext ctx)
      Whether this event should trigger, given the TriggerContext
      Parameters:
      ctx - the TriggerContext to check
      Returns:
      whether the event should trigger
    • loadSection

      public List<Statement> loadSection(FileSection section, ParserState parserState, SkriptLogger logger)
    • init

      public boolean init(Expression<?>[] expressions, int matchedPattern, ParseContext parseContext)
      Description copied from interface: SyntaxElement
      Initializes this SyntaxElement before being used. This method is always called before all the others in an extending class, the only exception being CodeSection.loadSection(FileSection, ParserState, SkriptLogger).
      Specified by:
      init in interface SyntaxElement
      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 be null.
      matchedPattern - the index of the pattern that was successfully matched. It corresponds to the order of the syntaxes in registration
      parseContext - an object containing additional information about the parsing of this syntax element, like regex matches and parse marks
      Returns:
      true if the syntax element was initialized successfully, false otherwise.
      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, triggers with a higher loading priority number will be loaded first.

      Returns:
      the loading priority number. 0 by default
    • getAllowedSyntaxes

      public Set<Class<? extends SyntaxElement>> 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 null if you don't want to allow any
      See Also:
    • isRestrictingExpressions

      public boolean isRestrictingExpressions()
      Whether the syntax restrictions outlined in getAllowedSyntaxes() 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.