package com.btk5h.skriptmirror.skript.custom;

import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.TriggerItem;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;

public class EffContinue extends Effect {
  static {
    Skript.registerEffect(EffContinue.class, "continue");
  }

  @Override
  protected void execute(Event e) {
    throw new UnsupportedOperationException();
  }

  @Override
  protected TriggerItem walk(Event e) {
    if (e instanceof CustomEffect.EffectEvent) {
      if (((CustomEffect.EffectEvent) e).isSync()) {
        Skript.warning("Synchronous events should not be continued. " +
            "Call 'delay effect' to delay the effect's execution.");
      } else {
        TriggerItem.walk(((CustomEffect.EffectEvent) e).getNext(),
            ((CustomEffect.EffectEvent) e).getDirectEvent());
      }
    } else if (e instanceof CustomCondition.ConditionEvent) {
      ((CustomCondition.ConditionEvent) e).markContinue();
    }
    return null;
  }

  @Override
  public String toString(Event e, boolean debug) {
    return "continue";
  }

  @SuppressWarnings("unchecked")
  @Override
  public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed,
                      SkriptParser.ParseResult parseResult) {
    if (!ScriptLoader.isCurrentEvent(CustomEffect.EffectEvent.class, CustomCondition.ConditionEvent.class)) {
      Skript.error("Return may only be used in custom effects and conditions.", ErrorQuality.SEMANTIC_ERROR);
      return false;
    }

    return true;
  }
}

@@ -137,134 +137,9 @@
 ang.
-Effect;%0Aimport ch.njol.skript.lang.Expression;%0Aimport ch.njol.skript.lang.SkriptParser;%0Aimport ch.njol.skript.lang.TriggerItem
+*
 ;%0Aim
@@ -349,15 +349,124 @@
 inue
-%22);%0A  %7D
+ %5B(if%7Cwhen) (%25-boolean%25%7C%3C.+%3E)%5D%22);%0A  %7D%0A%0A  private Expression%3CBoolean%3E condition;%0A  private Condition skriptCondition;
 %0A%0A  
@@ -611,24 +611,185 @@
 (Event e) %7B%0A
+    if (skriptCondition != null && !skriptCondition.check(e)%0A        %7C%7C condition != null && condition.getSingle(e) != Boolean.TRUE) %7B%0A      return null;%0A    %7D%0A%0A
     if (e in
@@ -1294,24 +1294,25 @@
 ue();%0A    %7D%0A
+%0A
     return n
@@ -1843,32 +1843,319 @@
 n false;%0A    %7D%0A%0A
+    condition = (Expression%3CBoolean%3E) exprs%5B0%5D;%0A%0A    if (parseResult.regexes.size() %3E 0) %7B%0A      String group = parseResult.regexes.get(0).group();%0A      skriptCondition = Condition.parse(group, %22Can't understand this condition: %22 + group);%0A%0A      return skriptCondition != null;%0A    %7D%0A%0A
     return true;

Add conditional continue to conditions and effects (fixes #45)