ch.njol.skript.lang.Condition Java Examples
The following examples show how to use
ch.njol.skript.lang.Condition.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PropertyCondition.java From Skript with GNU General Public License v3.0 | 6 votes |
/** * @param c the class to register * @param propertyType the property type, see {@link PropertyType} * @param property the property name, for example <i>fly</i> in <i>players can fly</i> * @param type must be plural, for example <i>players</i> in <i>players can fly</i> */ public static void register(final Class<? extends Condition> c, final PropertyType propertyType, final String property, final String type) { if (type.contains("%")) { throw new SkriptAPIException("The type argument must not contain any '%'s"); } switch (propertyType) { case BE: Skript.registerCondition(c, "%" + type + "% (is|are) " + property, "%" + type + "% (isn't|is not|aren't|are not) " + property); break; case CAN: Skript.registerCondition(c, "%" + type + "% can " + property, "%" + type + "% (can't|cannot|can not) " + property); break; case HAVE: Skript.registerCondition(c, "%" + type + "% (has|have) " + property, "%" + type + "% (doesn't|does not|do not|don't) have " + property); break; default: assert false; } }
Example #2
Source File: PropertyCondition.java From Skript with GNU General Public License v3.0 | 6 votes |
public static String toString(Condition condition, PropertyType propertyType, @Nullable Event e, boolean debug, Expression<?> expr, String property) { switch (propertyType) { case BE: return expr.toString(e, debug) + (expr.isSingle() ? " is " : " are ") + (condition.isNegated() ? "not " : "") + property; case CAN: return expr.toString(e, debug) + (condition.isNegated() ? " can't " : " can ") + property; case HAVE: if (expr.isSingle()) return expr.toString(e, debug) + (condition.isNegated() ? " doesn't have " : " has ") + property; else return expr.toString(e, debug) + (condition.isNegated() ? " don't have " : " have ") + property; default: assert false; throw new AssertionError(); } }
Example #3
Source File: ExprFilter.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { try { parsing = this; objects = LiteralUtils.defendExpression(exprs[0]); rawCond = parseResult.regexes.get(0).group(); condition = Condition.parse(rawCond, "Can't understand this condition: " + rawCond); } finally { parsing = null; } return condition != null && LiteralUtils.canInitSafely(objects); }
Example #4
Source File: ExprTernary.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { ifTrue = LiteralUtils.defendExpression(exprs[0]); ifFalse = LiteralUtils.defendExpression(exprs[1]); if (ifFalse instanceof ExprTernary<?> || ifTrue instanceof ExprTernary<?>) { Skript.error("Ternary operators may not be nested!"); return false; } String cond = parseResult.regexes.get(0).group(); condition = Condition.parse(cond, "Can't understand this condition: " + cond); return condition != null && LiteralUtils.canInitSafely(ifTrue, ifFalse); }
Example #5
Source File: Skript.java From Skript with GNU General Public License v3.0 | 5 votes |
/** * registers a {@link Condition}. * * @param condition The condition's class * @param patterns Skript patterns to match this condition */ public static <E extends Condition> void registerCondition(final Class<E> condition, final String... patterns) throws IllegalArgumentException { checkAcceptRegistrations(); String originClassPath = Thread.currentThread().getStackTrace()[2].getClassName(); final SyntaxElementInfo<E> info = new SyntaxElementInfo<>(patterns, condition, originClassPath); conditions.add(info); statements.add(info); }
Example #6
Source File: EffAssert.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"null", "unchecked"}) @Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { String cond = parseResult.regexes.get(0).group(); condition = Condition.parse(cond, "Can't understand this condition: " + cond); errorMsg = (Expression<String>) exprs[0]; return condition != null; }
Example #7
Source File: EvtTestCase.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"null", "unchecked"}) @Override public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { name = (Expression<String>) args[0]; if (!parseResult.regexes.isEmpty()) { // Do not parse or run unless condition is met String cond = parseResult.regexes.get(0).group(); condition = Condition.parse(cond, "Can't understand this condition: " + cond); } return true; }
Example #8
Source File: EffDoIf.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { String eff = parseResult.regexes.get(0).group(); String cond = parseResult.regexes.get(1).group(); effect = Effect.parse(eff, "Can't understand this effect: " + eff); if (effect instanceof EffDoIf) { Skript.error("Do if effects may not be nested!"); return false; } condition = Condition.parse(cond, "Can't understand this condition: " + cond); return effect != null && condition != null; }
Example #9
Source File: Skript.java From Skript with GNU General Public License v3.0 | 4 votes |
public static Collection<SyntaxElementInfo<? extends Condition>> getConditions() { return conditions; }
Example #10
Source File: PropertyCondition.java From Skript with GNU General Public License v3.0 | 2 votes |
/** * @param c the class to register * @param property the property name, for example <i>fly</i> in <i>players can fly</i> * @param type must be plural, for example <i>players</i> in <i>players can fly</i> */ public static void register(final Class<? extends Condition> c, final String property, final String type) { register(c, PropertyType.BE, property, type); }