Package ch.njol.skript.lang
Class Condition
java.lang.Object
ch.njol.skript.lang.TriggerItem
ch.njol.skript.lang.Statement
ch.njol.skript.lang.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:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.skriptlang.skript.lang.condition.Conditional
Conditional.Operator -
Field Summary
Fields inherited from class ch.njol.skript.lang.TriggerItem
parent -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleancheck(org.bukkit.event.Event event) Checks whether this condition is satisfied with the given event.evaluate(org.bukkit.event.Event event) Evaluates this object as `true`, `false`, or `unknown`.getNode()Returns the sourceNodefor any errors the implementing class emits.@NotNull Stringfinal booleanstatic @Nullable ConditionParse a raw string input as a condition.booleanpreInit()Called immediately after the constructor.final booleanrun(org.bukkit.event.Event event) Executes this item.protected final voidsetNegated(boolean invert) Sets the negation state of this condition.simplify()Simplifies this object.Methods inherited from class ch.njol.skript.lang.TriggerItem
debug, executionIntent, getActualNext, getIndentation, getNext, getParent, getTrigger, setNext, setParent, toString, walk, walkMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.skriptlang.skript.lang.condition.Conditional
evaluate, evaluateAnd, evaluateAnd, evaluateAnd, evaluateAnd, evaluateNot, evaluateNot, evaluateOr, evaluateOr, evaluateOr, evaluateOrMethods inherited from interface ch.njol.skript.lang.Debuggable
toString, toStringMethods inherited from interface org.skriptlang.skript.log.runtime.RuntimeErrorProducer
error, error, getRuntimeErrorManager, warning, warningMethods inherited from interface ch.njol.skript.lang.SyntaxElement
getParser, initMethods inherited from interface org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer
getErrorSource
-
Constructor Details
-
Condition
protected Condition()
-
-
Method Details
-
preInit
public boolean preInit()Description copied from interface:SyntaxElementCalled 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:
preInitin interfaceSyntaxElement- 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 useSimpleExpression.check(Event, Predicate)- Parameters:
event- the event to check- Returns:
trueif the condition is satisfied,falseotherwise or if the condition doesn't apply to this event.
-
evaluate
Description copied from interface:ConditionalEvaluates this object as `true`, `false`, or `unknown`. This value may change between subsequent callings.- Specified by:
evaluatein interfaceConditional<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:TriggerItemExecutes this item.- Specified by:
runin classTriggerItem- 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 ofExpression.check(Event, Predicate, boolean). -
isNegated
public final boolean isNegated()- Returns:
- whether this condition is negated or not.
-
getNode
Description copied from interface:SyntaxRuntimeErrorProducerReturns the sourceNodefor any errors the implementing class emits.
Used for accessing the line contents viaNode.getKey()and the line number viaNode.getLine().
A standard implementation is to store the Node duringSyntaxElement.init(Expression[], int, Kleenean, SkriptParser.ParseResult)viaParserInstance.getNode().- Specified by:
getNodein interfaceSyntaxRuntimeErrorProducer- Returns:
- The source that produced a runtime error.
-
getSyntaxTypeName
- Specified by:
getSyntaxTypeNamein interfaceSyntaxElement- Returns:
- A string naming the type of syntax this is. e.g. "expression", "section".
-
simplify
Description copied from interface:SimplifiableSimplifies 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 ofDebuggable.toString(Event, boolean). An addition indicating that the value was simplified can be added in the debug string. SeeSimplifiedLiteralfor 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 updateExpression.getSource()to point to the expression prior to simplification. This makes maintaining the above contracts easier.- Specified by:
simplifyin interfaceSimplifiable<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.
-