Class RestrictedExpression<T>

java.lang.Object
io.github.syst3ms.skriptparser.lang.base.RestrictedExpression<T>
Type Parameters:
T - the return type
All Implemented Interfaces:
Expression<T>, SyntaxElement

public abstract class RestrictedExpression<T> extends Object implements Expression<T>
An expression that can only be used in select CodeSections. It is possible to make a RestrictedExpression "strict" ; that is, it would be invalid to use it when not directly enclosed in one of its required sections. It is possible to specify the error message that should be shown if the restrictions aren't followed. This class shouldn't be used for expressions that should only work with specific TriggerContexts. For this purpose, use ParseContext.getParserState() in conjuction with ParserState.getCurrentContexts().
See Also:
  • Constructor Details

    • RestrictedExpression

      public RestrictedExpression()
  • Method Details

    • 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:
    • initialize

      protected abstract boolean initialize(Expression<?>[] expressions, CodeSection requiredSection, int matchedPattern, ParseContext parseContext)
    • getSpecificErrorMessage

      protected abstract String getSpecificErrorMessage()
      The error message that should be displayed if this expression is used outside of one of its required sections
      Returns:
      the error message that should be displayed if this expression is used outside of one of its required sections
    • getRequiredSections

      protected abstract List<Class<? extends CodeSection>> getRequiredSections()
      Returns a list of the classes of all the sections inside of which this expression can be used
      Returns:
      a list of the classes of all the sections inside of which this expression can be used
    • isStrict

      protected abstract boolean isStrict()
      True if the directly enclosing section must be a required one (a member of getRequiredSections()), false otherwise.
      Returns:
      whether the directly enclosing section must be a required one or not