diff --git a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java index 7a99c659d5d..8e73bf83d56 100644 --- a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java +++ b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java @@ -53,7 +53,7 @@ * the first one needs to be a non-negated one and a negated one. */ public abstract class PropertyCondition extends Condition implements Checker { - + /** * See {@link PropertyCondition} for more info */ @@ -74,100 +74,112 @@ public enum PropertyType { * Indicates that the condition is in a form of something has/have something, * also possibly in the negated form */ - HAVE + HAVE, + + /** + * Indicates that the condition is in a form of something will/be something, + * also possibly in the negated form + */ + WILL } - - @SuppressWarnings("null") + private Expression expr; - + /** - * @param c the class to register + * @param condition the class to register * @param property the property name, for example fly in players can fly * @param type must be plural, for example players in players can fly */ - public static void register(final Class c, final String property, final String type) { - register(c, PropertyType.BE, property, type); + public static void register(Class condition, String property, String type) { + register(condition, PropertyType.BE, property, type); } - + /** - * @param c the class to register + * @param condition the class to register * @param propertyType the property type, see {@link PropertyType} * @param property the property name, for example fly in players can fly * @param type must be plural, for example players in players can fly */ - public static void register(final Class c, final PropertyType propertyType, final String property, final String type) { - if (type.contains("%")) { + public static void register(Class condition, PropertyType propertyType, String property, String type) { + if (type.contains("%")) throw new SkriptAPIException("The type argument must not contain any '%'s"); - } + switch (propertyType) { case BE: - Skript.registerCondition(c, + Skript.registerCondition(condition, "%" + type + "% (is|are) " + property, "%" + type + "% (isn't|is not|aren't|are not) " + property); break; case CAN: - Skript.registerCondition(c, + Skript.registerCondition(condition, "%" + type + "% can " + property, "%" + type + "% (can't|cannot|can not) " + property); break; case HAVE: - Skript.registerCondition(c, + Skript.registerCondition(condition, "%" + type + "% (has|have) " + property, "%" + type + "% (doesn't|does not|do not|don't) have " + property); break; + case WILL: + Skript.registerCondition(condition, + "%" + type + "% will " + property, + "%" + type + "% (will (not|neither)|won't) " + property); + break; default: assert false; } } - - @SuppressWarnings({"unchecked", "null"}) + @Override - public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { + @SuppressWarnings("unchecked") + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { expr = (Expression) exprs[0]; setNegated(matchedPattern == 1); return true; } - + @Override - public final boolean check(final Event e) { - return expr.check(e, this, isNegated()); + public final boolean check(Event event) { + return expr.check(event, this, isNegated()); } - + @Override public abstract boolean check(T t); - + protected abstract String getPropertyName(); - + protected PropertyType getPropertyType() { return PropertyType.BE; } - + /** * Sets the expression this condition checks a property of. No reference to the expression should be kept. * - * @param expr + * @param expr The expression property of this property condition. */ - protected final void setExpr(final Expression expr) { + protected final void setExpr(Expression expr) { this.expr = expr; } - + @Override - public String toString(final @Nullable Event e, final boolean debug) { - return toString(this, getPropertyType(), e, debug, expr, getPropertyName()); + public String toString(@Nullable Event event, boolean debug) { + return toString(this, getPropertyType(), event, debug, expr, getPropertyName()); } - - public static String toString(Condition condition, PropertyType propertyType, @Nullable Event e, + + public static String toString(Condition condition, PropertyType propertyType, @Nullable Event event, boolean debug, Expression expr, String property) { switch (propertyType) { case BE: - return expr.toString(e, debug) + (expr.isSingle() ? " is " : " are ") + (condition.isNegated() ? "not " : "") + property; + return expr.toString(event, debug) + (expr.isSingle() ? " is " : " are ") + (condition.isNegated() ? "not " : "") + property; case CAN: - return expr.toString(e, debug) + (condition.isNegated() ? " can't " : " can ") + property; + return expr.toString(event, debug) + (condition.isNegated() ? " can't " : " can ") + property; case HAVE: if (expr.isSingle()) - return expr.toString(e, debug) + (condition.isNegated() ? " doesn't have " : " has ") + property; + return expr.toString(event, debug) + (condition.isNegated() ? " doesn't have " : " has ") + property; else - return expr.toString(e, debug) + (condition.isNegated() ? " don't have " : " have ") + property; + return expr.toString(event, debug) + (condition.isNegated() ? " don't have " : " have ") + property; + case WILL: + return expr.toString(event, debug) + (condition.isNegated() ? " won't " : " will ") + "be " + property; default: assert false; throw new AssertionError();