if (Skript.debug())
indentation += " ";
final ArrayList<TriggerItem> items = new ArrayList<TriggerItem>();
Kleenean hadDelayBeforeLastIf = Kleenean.FALSE;
for (final Node n : node) {
SkriptLogger.setNode(n);
if (n instanceof SimpleNode) {
final SimpleNode e = (SimpleNode) n;
final String s = replaceOptions("" + e.getKey());
if (!SkriptParser.validateLine(s))
continue;
final Statement stmt = Statement.parse(s, "Can't understand this condition/effect: " + s);
if (stmt == null)
continue;
if (Skript.debug() || n.debug())
Skript.debug(indentation + stmt.toString(null, true));
items.add(stmt);
if (stmt instanceof Delay)
hasDelayBefore = Kleenean.TRUE;
} else if (n instanceof SectionNode) {
String name = replaceOptions("" + n.getKey());
if (!SkriptParser.validateLine(name))
continue;
if (StringUtils.startsWithIgnoreCase(name, "loop ")) {
final String l = "" + name.substring("loop ".length());
final RetainingLogHandler h = SkriptLogger.startRetainingLog();
Expression<?> loopedExpr;
try {
loopedExpr = new SkriptParser(l).parseExpression(Object.class);
if (loopedExpr != null)
loopedExpr = loopedExpr.getConvertedExpression(Object.class);
if (loopedExpr == null) {
h.printErrors("Can't understand this loop: '" + name + "'");
continue;
}
h.printLog();
} finally {
h.stop();
}
if (loopedExpr.isSingle()) {
Skript.error("Can't loop " + loopedExpr + " because it's only a single value");
continue;
}
if (Skript.debug() || n.debug())
Skript.debug(indentation + "loop " + loopedExpr.toString(null, true) + ":");
final Kleenean hadDelayBefore = hasDelayBefore;
items.add(new Loop(loopedExpr, (SectionNode) n));
if (hadDelayBefore != Kleenean.TRUE && hasDelayBefore != Kleenean.FALSE)
hasDelayBefore = Kleenean.UNKNOWN;
} else if (StringUtils.startsWithIgnoreCase(name, "while ")) {
final String l = "" + name.substring("while ".length());
final Condition c = Condition.parse(l, "Can't understand this condition: " + l);
if (c == null)
continue;
if (Skript.debug() || n.debug())
Skript.debug(indentation + "while " + c.toString(null, true) + ":");
final Kleenean hadDelayBefore = hasDelayBefore;
items.add(new While(c, (SectionNode) n));
if (hadDelayBefore != Kleenean.TRUE && hasDelayBefore != Kleenean.FALSE)
hasDelayBefore = Kleenean.UNKNOWN;
} else if (name.equalsIgnoreCase("else")) {
if (items.size() == 0 || !(items.get(items.size() - 1) instanceof Conditional) || ((Conditional) items.get(items.size() - 1)).hasElseClause()) {
Skript.error("'else' has to be placed just after an 'if' or 'else if' section");
continue;
}
if (Skript.debug() || n.debug())
Skript.debug(indentation + "else:");
final Kleenean hadDelayAfterLastIf = hasDelayBefore;
hasDelayBefore = hadDelayBeforeLastIf;
((Conditional) items.get(items.size() - 1)).loadElseClause((SectionNode) n);
hasDelayBefore = hadDelayBeforeLastIf.or(hadDelayAfterLastIf.and(hasDelayBefore));
} else if (StringUtils.startsWithIgnoreCase(name, "else if ")) {
if (items.size() == 0 || !(items.get(items.size() - 1) instanceof Conditional) || ((Conditional) items.get(items.size() - 1)).hasElseClause()) {
Skript.error("'else if' has to be placed just after another 'if' or 'else if' section");
continue;
}
name = "" + name.substring("else if ".length());
final Condition cond = Condition.parse(name, "can't understand this condition: '" + name + "'");
if (cond == null)
continue;
if (Skript.debug() || n.debug())
Skript.debug(indentation + "else if " + cond.toString(null, true));
final Kleenean hadDelayAfterLastIf = hasDelayBefore;
hasDelayBefore = hadDelayBeforeLastIf;
((Conditional) items.get(items.size() - 1)).loadElseIf(cond, (SectionNode) n);
hasDelayBefore = hadDelayBeforeLastIf.or(hadDelayAfterLastIf.and(hasDelayBefore.and(Kleenean.UNKNOWN)));
} else {
if (StringUtils.startsWithIgnoreCase(name, "if "))
name = "" + name.substring(3);
final Condition cond = Condition.parse(name, "can't understand this condition: '" + name + "'");
if (cond == null)
continue;
if (Skript.debug() || n.debug())
Skript.debug(indentation + cond.toString(null, true) + ":");
final Kleenean hadDelayBefore = hasDelayBefore;
hadDelayBeforeLastIf = hadDelayBefore;
items.add(new Conditional(cond, (SectionNode) n));
hasDelayBefore = hadDelayBefore.or(hasDelayBefore.and(Kleenean.UNKNOWN));
}
}
}
for (int i = 0; i < items.size() - 1; i++)