Class Condition

All Implemented Interfaces:
Debuggable, Simplifiable<Condition>, SyntaxElement, Conditional<org.bukkit.event.Event>, RuntimeErrorProducer, SyntaxRuntimeErrorProducer
Direct Known Subclasses:
CondBrewingConsume, CondFishingLure, CondIsPressingKey, CondIsTagged, PropCondContains, PropertyBaseCondition, ch.njol.skript.conditions.base.PropertyCondition, SimplifiedCondition

public abstract class Condition extends Statement implements Conditional<org.bukkit.event.Event>, SyntaxRuntimeErrorProducer, Simplifiable<Condition>
A condition which must be fulfilled for the trigger to continue. If the condition is in a section the behaviour depends on the section.
See Also:
  • Constructor Details

    • Condition

      protected Condition()
  • Method Details

    • preInit

      public boolean preInit()
      Description copied from interface: SyntaxElement
      Called 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:
      preInit in interface SyntaxElement
      Returns:
      Whether this expression was pre-initialised successfully. An error should be printed prior to returning false to specify the cause.
    • check

      public abstract boolean check(org.bukkit.event.Event event)
      Checks whether this condition is satisfied with the given event. This should not alter the event or the world in any way, as conditions are only checked until one returns false. All subsequent conditions of the same trigger will then be omitted.

      You might want to use SimpleExpression.check(Event, Predicate)
      Parameters:
      event - the event to check
      Returns:
      true if the condition is satisfied, false otherwise or if the condition doesn't apply to this event.
    • evaluate

      public Kleenean evaluate(org.bukkit.event.Event event)
      Description copied from interface: Conditional
      Evaluates this object as `true`, `false`, or `unknown`. This value may change between subsequent callings.
      Specified by:
      evaluate in interface Conditional<org.bukkit.event.Event>
      Parameters:
      event - The context with which to evaluate this object.
      Returns:
      The evaluation of this object.
    • run

      public final boolean run(org.bukkit.event.Event event)
      Description copied from class: TriggerItem
      Executes this item.
      Specified by:
      run in class TriggerItem
      Parameters:
      event - The event to run this item with
      Returns:
      True if the next item should be run, or false for the item following this item's parent.
    • setNegated

      protected final void setNegated(boolean invert)
      Sets the negation state of this condition. This will change the behaviour of Expression.check(Event, Predicate, boolean).
    • isNegated

      public final boolean isNegated()
      Returns:
      whether this condition is negated or not.
    • getNode

      public Node getNode()
      Description copied from interface: SyntaxRuntimeErrorProducer
      Returns the source Node for any errors the implementing class emits.
      Used for accessing the line contents via Node.getKey() and the line number via Node.getLine().
      A standard implementation is to store the Node during SyntaxElement.init(Expression[], int, Kleenean, SkriptParser.ParseResult) via ParserInstance.getNode().
      Specified by:
      getNode in interface SyntaxRuntimeErrorProducer
      Returns:
      The source that produced a runtime error.
    • getSyntaxTypeName

      @NotNull public @NotNull String getSyntaxTypeName()
      Specified by:
      getSyntaxTypeName in interface SyntaxElement
      Returns:
      A string naming the type of syntax this is. e.g. "expression", "section".
    • simplify

      public Condition simplify()
      Description copied from interface: Simplifiable
      Simplifies this object. This should be called immediately after init() returns true. If simplification is not possible, the object is returned as is.
      References to the original object should be replaced with the simplified object.
      Any returned object should attempt to maintain the original value of Debuggable.toString(Event, boolean). An addition indicating that the value was simplified can be added in the debug string. See SimplifiedLiteral for an example.
      Simplification should never invalidate contracts. For example, any simplified expression should take care to return the same or a more specific type than the original expression, never a more generic type. Likewise, be sure to maintain the behavior of change() and acceptsChange(). Failure to do so can result in unexpected behavior and tricky bugs.
      Finally, simplified results should update Expression.getSource() to point to the expression prior to simplification. This makes maintaining the above contracts easier.
      Specified by:
      simplify in interface Simplifiable<Condition>
      Returns:
      the simplified object.
      See Also:
    • parse

      @Nullable public static @Nullable Condition parse(String input, @Nullable @Nullable String defaultError)
      Parse a raw string input as a condition.
      Parameters:
      input - The string input to parse as a condition.
      defaultError - The error if the condition fails.
      Returns:
      Condition if parsed correctly, otherwise null.