Пример #1
0
  private void doCommand(ScriptEntry scriptEntry, String mapName) {
    TreeMap<Integer, ArrayList<String>> commandMap =
        (TreeMap<Integer, ArrayList<String>>) scriptEntry.getObject(mapName);

    if (commandMap == null || commandMap.size() == 0) return;

    List<ScriptEntry> entries = new ArrayList<ScriptEntry>();

    for (Map.Entry<Integer, ArrayList<String>> pairs : commandMap.entrySet()) {
      ArrayList<String> commandArray = pairs.getValue();
      String command = commandArray.get(0);
      commandArray.remove(0);
      String[] arguments = commandArray.toArray(new String[commandArray.size()]);

      try {
        ScriptEntry entry =
            new ScriptEntry(
                    command,
                    arguments,
                    (scriptEntry.getScript() == null
                        ? null
                        : scriptEntry.getScript().getContainer()))
                .setPlayer(scriptEntry.getPlayer())
                .setNPC(scriptEntry.getNPC())
                .setInstant(true)
                .addObject("reqId", scriptEntry.getObject("reqId"));

        entries.add(entry);

      } catch (ScriptEntryCreationException e) {
        dB.echoError("There has been a problem running the Command. Check syntax.");
        dB.echoError(e);
      }
    }

    // Put tracked objects into new script entries.
    for (String tracked_object : scriptEntry.tracked_objects) {
      ScriptBuilder.addObjectToEntries(
          entries, tracked_object, scriptEntry.getObject(tracked_object));
    }

    scriptEntry.getResidingQueue().injectEntries(entries, 0);
  }
Пример #2
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);
  }