Ejemplo n.º 1
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    // Grab comparables from the ScriptEntry
    List<Comparable> comparables = (List<Comparable>) scriptEntry.getObject("comparables");

    int counter = 1;

    // Evaluate comparables
    for (Comparable com : comparables) {
      com.determineOutcome();

      // Show outcome of Comparable
      dB.echoDebug(
          scriptEntry,
          ChatColor.YELLOW + "Comparable " + counter + ": " + ChatColor.WHITE + com.toString());
      counter++;
    }

    // Compare outcomes

    int ormet = 0;
    for (Comparable comparable : comparables) {
      if (comparable.bridge == Comparable.Bridge.OR) if (comparable.outcome) ormet++;
    }

    int andcount = 0;
    int andmet = 0;
    for (Comparable comparable : comparables) {
      if (comparable.bridge == Comparable.Bridge.AND) {
        if (comparable.outcome) andmet++;
        andcount++;
      }
    }

    boolean do_then;

    if (comparables.size() > 1) {
      do_then = (ormet > 0) || (andcount == andmet && comparables.get(0).outcome == true);
    } else do_then = comparables.get(0).outcome;

    // Determine outcome -- then, or else?
    if (do_then) {
      // dB.log("then: " + scriptEntry.getObject("then-outcome").toString());
      doCommand(scriptEntry, "then-outcome");
    } else {
      // dB.log("else: " + scriptEntry.getObject("else-outcome").toString());
      doCommand(scriptEntry, "else-outcome");
    }
  }