Example #1
0
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    // Parse Arguments
    for (Argument arg : aH.interpret(scriptEntry.getArguments())) {

      if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values()))
        scriptEntry.addObject("action", Action.valueOf(arg.getValue().toUpperCase()));
      else if (!scriptEntry.hasObject("range")
          && arg.matchesPrimitive(aH.PrimitiveType.Double)
          && arg.matchesPrefix("range, r")) scriptEntry.addObject("range", arg.asElement());
      else if (!scriptEntry.hasObject("id") && arg.matchesPrefix("id, i"))
        scriptEntry.addObject("id", arg.asElement());
      else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class))
        scriptEntry.addObject("location", arg.asType(dLocation.class));
      else arg.reportUnhandled();
    }

    // Check required arguments
    if (!scriptEntry.hasNPC())
      throw new InvalidArgumentsException("NPC linked was missing or invalid.");

    if (!scriptEntry.hasObject("action"))
      throw new InvalidArgumentsException(
          "Must specify an 'Anchor Action'. Valid: " + Action.values());
  }
Example #2
0
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

      if (arg.matches("passive, passively")) scriptEntry.addObject("passively", new Element(true));
      else if (!scriptEntry.hasObject("outcome"))
        scriptEntry.addObject("outcome", new Element(arg.raw_value));
      else arg.reportUnhandled();
    }

    // Set defaults
    scriptEntry.defaultObject("passively", new Element(false));
    scriptEntry.defaultObject("outcome", new Element(false));
  }
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    dItem item = null;
    Action action = Action.PLACE;
    Duration duration = null;
    dLocation location = null;

    // Make sure NPC is available
    for (String arg : scriptEntry.getArguments()) {

      if (aH.matchesDuration(arg)) duration = aH.getDurationFrom(arg);
      else if (aH.matchesArg("REMOVE", arg)) action = Action.REMOVE;
      else if (aH.matchesLocation(arg)) location = aH.getLocationFrom(arg);
      else if (aH.getItemFrom(arg) != null) item = aH.getItemFrom(arg);
      else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
    }

    // Check required args
    if (item == null) throw new InvalidArgumentsException("Must specify an item to display.");

    if (location == null) throw new InvalidArgumentsException(Messages.DEBUG_SET_LOCATION);

    // Add objects to ScriptEntry for execution
    scriptEntry
        .addObject("item", item)
        .addObject("action", action)
        .addObject("duration", duration)
        .addObject("location", location);
  }
Example #4
0
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
      if (!scriptEntry.hasObject("type")
          && arg.matchesPrefix("type")
          && arg.matchesEnum(Type.values())) scriptEntry.addObject("type", arg.asElement());
      else if (!scriptEntry.hasObject("file") && arg.matchesPrefix("file"))
        scriptEntry.addObject("file", arg.asElement());
      else if (!scriptEntry.hasObject("message")) scriptEntry.addObject("message", arg.asElement());
      else arg.reportUnhandled();
    }

    if (!scriptEntry.hasObject("message"))
      throw new InvalidArgumentsException("Must specify a message.");

    if (!scriptEntry.hasObject("file")) throw new InvalidArgumentsException("Must specify a file.");

    if (!scriptEntry.hasObject("type")) scriptEntry.addObject("type", new Element("INFO"));
  }
Example #5
0
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    // Parse Arguments
    for (String arg : scriptEntry.getArguments()) {
      if (aH.matchesState(arg))
        scriptEntry.addObject("state", Action.valueOf(aH.getStringFrom(arg).toUpperCase()));
      else if (aH.matchesArg("NPC, PLAYER", arg))
        scriptEntry.addObject("target", Target.valueOf(aH.getStringFrom(arg).toUpperCase()));
      else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg);
    }

    if (scriptEntry.getObject("state") == null)
      throw new InvalidArgumentsException("Must specify a state action!");

    if (scriptEntry.getObject("target") == null)
      throw new InvalidArgumentsException("Must specify a target!");

    if ((scriptEntry.getObject("target") == Target.NPC && scriptEntry.getNPC() == null)
        || (scriptEntry.getObject("target") == Target.PLAYER && scriptEntry.getPlayer() == null))
      throw new InvalidArgumentsException("NPC not found!");
  }
Example #6
0
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    // Define necessary fields
    Script script = scriptEntry.getScript();
    Duration duration = null;
    OfflinePlayer player = null;
    Type type = Type.PLAYER;

    // Set player in scriptEntry to the target
    if (scriptEntry.getPlayer() != null) player = scriptEntry.getPlayer();
    else if (scriptEntry.getOfflinePlayer() != null) player = scriptEntry.getOfflinePlayer();

    // Parse Arguments
    for (String arg : scriptEntry.getArguments()) {

      if (aH.matchesDuration(arg) || aH.matchesInteger(arg)) duration = aH.getDurationFrom(arg);

      // Default is PLAYER, but having both to choose from seems to be most straightforward
      else if (aH.matchesArg("GLOBAL, PLAYER", arg)) type = Type.valueOf(arg.toUpperCase());

      // Must be an actual script! If the script doesn't exist, matchesScript(...)
      // will echo an error.
      else if (aH.matchesScript(arg)) script = aH.getScriptFrom(arg);
      else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
    }

    // Check to make sure required arguments have been filled
    if (type == Type.PLAYER && player == null)
      throw new InvalidArgumentsException(Messages.ERROR_NO_PLAYER);
    if (script == null) throw new InvalidArgumentsException(Messages.ERROR_NO_SCRIPT);

    // Store necessary items in the scriptEntry
    scriptEntry.addObject("script", script);
    scriptEntry.addObject("duration", duration);
    scriptEntry.addObject("type", type);
    // Store the player only when necessary
    if (type == Type.PLAYER) scriptEntry.addObject("player", player);
  }
Example #7
0
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    // Comparables check the logic
    List<Comparable> comparables = new ArrayList<Comparable>();
    // Insert new comparable into the list
    comparables.add(new Comparable());

    // Indicate that comparables are building
    boolean buildingComparables = true;

    // What to do depending on the logic of the comparables
    // is stored in two tree maps
    TreeMap<Integer, ArrayList<String>> thenOutcome = new TreeMap<Integer, ArrayList<String>>();
    TreeMap<Integer, ArrayList<String>> elseOutcome = new TreeMap<Integer, ArrayList<String>>();

    // Keep tracking of whether we're inside the Else part of the statement or not
    boolean insideElse = false;

    // Keep track of this to avoid Denizen overlooking comparedTo when an operator is used
    // with a value that matches the name of a command. (Good find dimensionZ!)
    boolean usedOperator = false;

    // Track whether we are adding a new command or not
    boolean newCommand = false;

    // Track whether we are inside nested brackets whose contents
    // should be added as arguments to our current If, not as commands
    int bracketsEntered = 0;

    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
      if (buildingComparables) {

        // Set logic to NEGATIVE
        if (arg.startsWith("!")) {
          comparables.get(comparables.size() - 1).setNegativeLogic();
          if (arg.getValue().length() == 1) continue;
          if (arg.startsWith("!=")) arg.replaceValue("==");
          else arg.replaceValue(arg.getValue().substring(1));
        }

        // Replace symbol-operators/bridges with ENUM value for matching
        if (arg.getValue().equals("==")) arg.replaceValue("EQUALS");
        else if (arg.getValue().equals(">=")) arg.replaceValue("OR_MORE");
        else if (arg.getValue().equals("<=")) arg.replaceValue("OR_LESS");
        else if (arg.getValue().equals("<")) arg.replaceValue("LESS");
        else if (arg.getValue().equals(">")) arg.replaceValue("MORE");
        else if (arg.getValue().equals("||")) arg.replaceValue("OR");
        else if (arg.getValue().equals("&&")) arg.replaceValue("AND");

        // Set bridge
        if (arg.matchesEnum(Comparable.Bridge.values())) {
          // new Comparable to add to the list
          comparables.add(new Comparable());
          comparables.get(comparables.size() - 1).bridge =
              Comparable.Bridge.valueOf(arg.getValue().toUpperCase());
        }

        // Set operator (Optional, default is EQUALS)
        else if (arg.matchesEnum(Comparable.Operator.values())) {
          comparables.get(comparables.size() - 1).operator =
              Comparable.Operator.valueOf(arg.getValue().toUpperCase());
          usedOperator = true;
        }

        // Set comparable
        else if (comparables.get(comparables.size() - 1).comparable == null) {
          // If using MATCHES operator, keep as string.
          comparables.get(comparables.size() - 1).setComparable(arg.getValue());
        } else if (!usedOperator && arg.matches("{")) {
          buildingComparables = false;
        }

        // Check if filling comparables are done by checking the command registry for valid
        // commands.
        // If using an operator though, skip on to compared-to!
        else if (!usedOperator
            && denizen.getCommandRegistry().get(arg.getValue().replace("^", "")) != null) {
          buildingComparables = false;
        }

        // Set compared-to
        else {
          comparables.get(comparables.size() - 1).setComparedto(arg.getValue());
          usedOperator = false;
        }
      }

      if (!buildingComparables) {

        // Read "-" as meaning we are moving to a new command, unless we
        // are inside nested brackets (i.e. bracketsEntered of at least 2)
        // in which case we just treat what follows as arguments
        if (arg.matches("-") && bracketsEntered < 2) {
          newCommand = true;
        } else if (!insideElse) {

          // Move to else commands if we read an "else" and we're not
          // currently going through nested arguments
          if (arg.matches("else") && bracketsEntered == 0) {
            insideElse = true;
          }

          // If we find a bracket, and we're already inside
          // nested brackets, add the bracket to the current
          // command's arguments
          else if (arg.matches("{")) {
            bracketsEntered++;

            if (bracketsEntered > 1) {
              thenOutcome.get(thenOutcome.lastKey()).add(arg.raw_value);
            }
          } else if (arg.matches("}")) {
            bracketsEntered--;

            if (bracketsEntered > 0) {
              thenOutcome.get(thenOutcome.lastKey()).add(arg.raw_value);
            }
          }

          // Add new outcome command if the last argument was a non-nested "-"
          // or if there are no outcome commands yet
          else if (newCommand || thenOutcome.size() == 0) {
            thenOutcome.put(thenOutcome.size(), new ArrayList<String>());
            thenOutcome.get(thenOutcome.lastKey()).add(arg.raw_value);
            newCommand = false;
          }

          // Add new outcome argument
          else {
            thenOutcome.get(thenOutcome.lastKey()).add(arg.raw_value);
          }
        } else if (insideElse) {

          // If we find a bracket, and we're already inside
          // nested brackets, add the bracket to the current
          // command's arguments
          if (arg.matches("{")) {
            bracketsEntered++;

            if (bracketsEntered > 1) {
              elseOutcome.get(elseOutcome.lastKey()).add(arg.raw_value);
            }
          } else if (arg.matches("}")) {
            bracketsEntered--;

            if (bracketsEntered > 0) {
              elseOutcome.get(elseOutcome.lastKey()).add(arg.raw_value);
            }
          }

          // Add new else command if the last argument was a non-nested "-"
          // or if it was "else" and we have no else commands yet
          else if (newCommand || elseOutcome.size() == 0) {
            newCommand = false;

            // Important!
            //
            // If we find an "else if", act like we entered a set of
            // brackets, so we treat the if's commands as arguments
            // and don't add them to our current else commands
            if (arg.matches("if") && elseOutcome.size() == 0) {
              bracketsEntered++;
            }

            // Add the new else command
            elseOutcome.put(elseOutcome.size(), new ArrayList<String>());
            elseOutcome.get(elseOutcome.lastKey()).add(arg.raw_value);
          }

          // Add new else argument
          else {
            elseOutcome.get(elseOutcome.lastKey()).add(arg.raw_value);
          }
        }
      }
    }

    // Stash objects required to execute() into the ScriptEntry
    scriptEntry
        .addObject("comparables", comparables)
        .addObject("then-outcome", thenOutcome)
        .addObject("else-outcome", elseOutcome);
  }