public void undo() {
   if (!mCommandStack.empty()) {
     AbstractCommand c = pop();
     c.undo();
     validateCells();
   }
 }
 public void restoreState(Bundle inState) {
   int stackSize = inState.getInt("cmdStack.size");
   for (int i = 0; i < stackSize; i++) {
     Bundle commandState = inState.getBundle("cmdStack." + i);
     AbstractCommand command = AbstractCommand.newInstance(commandState.getString("commandClass"));
     command.restoreState(commandState);
     push(command);
   }
 }
  @Override
  public boolean sysAccess(CommandSender sender, String[] args) {

    AbstractCommand cmd = commands.getCommand(args[0]);

    if (cmd == null) return false;

    return cmd.sysAccess(sender, args);
  }
 public void saveState(Bundle outState) {
   outState.putInt("cmdStack.size", mCommandStack.size());
   for (int i = 0; i < mCommandStack.size(); i++) {
     AbstractCommand command = mCommandStack.get(i);
     Bundle commandState = new Bundle();
     commandState.putString("commandClass", command.getCommandClass());
     command.saveState(commandState);
     outState.putBundle("cmdStack." + i, commandState);
   }
 }
  @Override
  public boolean runImpl(Player player, User user, String[] args) throws Exception {

    AbstractCommand cmd = commands.getCommand(args[0]);

    if (cmd == null) {
      EdgeCore.log.info("Command " + args[0] + " not found!");
      sendUsage(player);
      return true;
    }

    cmd.run(player, args);

    return true;
  }
  public void undoToCheckpoint() {
    /*
     * I originally planned to just call undo but this way it doesn't need to
     * validateCells() until the run is complete
     */
    AbstractCommand c;
    while (!mCommandStack.empty()) {
      c = mCommandStack.pop();
      c.undo();

      if (mCommandStack.empty() || mCommandStack.peek().isCheckpoint()) {
        break;
      }
    }
    validateCells();
  }
 public void execute() {
   super.execute();
   setUndoActivity(createUndoActivity());
   getUndoActivity().setAffectedFigures(view().selectionElements());
   view().addToSelectionAll(view().drawing().figures());
   view().checkDamage();
 }
 public void execute() {
   super.execute();
   setUndoActivity(createUndoActivity());
   getUndoActivity().setAffectedFigures(view().selection());
   FigureEnumeration fe = getUndoActivity().getAffectedFigures();
   while (fe.hasNextFigure()) {
     view().drawing().bringToFront(fe.nextFigure());
   }
   view().checkDamage();
 }
    private void processResponse(final String line) {
      try {
        final ProtocolFrame frame = new ProtocolFrame(line);
        logFrame(frame, false);

        if (AbstractThreadCommand.isThreadCommand(frame.getCommand())) {
          processThreadEvent(frame);
        } else if (AbstractCommand.isWriteToConsole(frame.getCommand())) {
          writeToConsole(ProtocolParser.parseIo(frame.getPayload()));
        } else if (AbstractCommand.isExitEvent(frame.getCommand())) {
          fireCommunicationError();
        } else if (AbstractCommand.isCallSignatureTrace(frame.getCommand())) {
          recordCallSignature(ProtocolParser.parseCallSignature(frame.getPayload()));
        } else {
          placeResponse(frame.getSequence(), frame);
        }
      } catch (Throwable t) {
        // shouldn't interrupt reader thread
        LOG.error(t);
      }
    }
  @Override
  public void execute(@NotNull final AbstractCommand command) {
    if (command instanceof ResumeOrStepCommand) {
      final String threadId = ((ResumeOrStepCommand) command).getThreadId();
      clearTempVariables(threadId);
    }

    try {
      command.execute();
    } catch (PyDebuggerException e) {
      LOG.error(e);
    }
  }
 @Override
 public void doCommand() throws Exception {
   super.doCommand();
   Thread.sleep(200);
 }
示例#12
0
  public boolean execute(ScriptEntry scriptEntry) {
    Matcher m;
    StringBuffer sb;
    if (scriptEntry.getCommandName().indexOf('%') != -1) {
      m = definition_pattern.matcher(scriptEntry.getCommandName());
      sb = new StringBuffer();
      while (m.find()) {
        String definition = scriptEntry.getResidingQueue().getDefinition(m.group(1));
        if (definition == null) definition = "null";
        m.appendReplacement(sb, definition);
      }
      m.appendTail(sb);
      scriptEntry.setCommandName(sb.toString());
    }

    // Get the command instance ready for the execution of the scriptEntry
    AbstractCommand command = plugin.getCommandRegistry().get(scriptEntry.getCommandName());

    if (command == null) {
      dB.echoDebug(
          scriptEntry, DebugElement.Header, "Executing command: " + scriptEntry.getCommandName());
      dB.echoError(
          scriptEntry.getCommandName() + " is an invalid dCommand! Are you sure it loaded?");
      dB.echoDebug(scriptEntry, DebugElement.Footer);
      return false;
    }

    // Debugger information
    if (scriptEntry.getPlayer() != null)
      dB.echoDebug(
          scriptEntry,
          DebugElement.Header,
          "Executing dCommand: "
              + scriptEntry.getCommandName()
              + "/"
              + scriptEntry.getPlayer().getName());
    else
      dB.echoDebug(
          scriptEntry,
          DebugElement.Header,
          "Executing dCommand: "
              + scriptEntry.getCommandName()
              + (scriptEntry.getNPC() != null ? "/" + scriptEntry.getNPC().getName() : ""));

    // Don't execute() if problems arise in parseArgs()
    boolean keepGoing = true;

    try {

      // Throw exception if arguments are required for this command, but not supplied.
      if (command.getOptions().REQUIRED_ARGS > scriptEntry.getArguments().size())
        throw new InvalidArgumentsException("");

      if (scriptEntry.has_tags)
        scriptEntry.setArguments(
            TagManager.fillArguments(
                scriptEntry.getArguments(), scriptEntry, true)); // Replace tags

      /*  If using NPC:# or PLAYER:Name arguments, these need to be changed out immediately because...
       *  1) Denizen/Player flags need the desired NPC/PLAYER before parseArgs's getFilledArguments() so that
       *     the Player/Denizen flags will read from the correct Object. If using PLAYER or NPCID arguments,
       *     the desired Objects are obviously not the same objects that were sent with the ScriptEntry.
       *  2) These arguments should be valid for EVERY ScriptCommand, so why not just take care of it
       *     here, instead of requiring each command to take care of the argument.
       */

      List<String> newArgs = new ArrayList<String>();

      // Don't fill in tags if there were brackets detected..
      // This means we're probably in a nested if.
      int nested_depth = 0;
      // Watch for IF command to avoid filling player and npc arguments
      // prematurely
      boolean if_ignore = false;

      for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (arg.getValue().equals("{")) nested_depth++;
        if (arg.getValue().equals("}")) nested_depth--;

        // If nested, continue.
        if (nested_depth > 0) {
          newArgs.add(arg.raw_value);
          continue;
        }

        if (arg.raw_value.indexOf('%') != -1) {
          m = definition_pattern.matcher(arg.raw_value);
          sb = new StringBuffer();
          while (m.find()) {
            String definition = scriptEntry.getResidingQueue().getDefinition(m.group(1));
            if (definition == null) definition = "null";
            m.appendReplacement(sb, definition);
          }
          m.appendTail(sb);
          arg = aH.Argument.valueOf(sb.toString());
        }

        // If using IF, check if we've reached the command + args
        // so that we don't fill player: or npc: prematurely
        if (command.getName().equalsIgnoreCase("if")
            && DenizenAPI.getCurrentInstance().getCommandRegistry().get(arg.getValue()) != null)
          if_ignore = true;

        // Fill player/off-line player
        if (arg.matchesPrefix("player") && !if_ignore) {
          dB.echoDebug(scriptEntry, "...replacing the linked player with " + arg.getValue());
          String value =
              TagManager.tag(
                  scriptEntry.getPlayer(),
                  scriptEntry.getNPC(),
                  arg.getValue(),
                  false,
                  scriptEntry);
          dPlayer player = dPlayer.valueOf(value);
          if (player == null || !player.isValid()) {
            dB.echoError(value + " is an invalid player!");
            return false;
          }
          scriptEntry.setPlayer(player);
        }

        // Fill NPCID/NPC argument
        else if (arg.matchesPrefix("npc, npcid") && !if_ignore) {
          dB.echoDebug(scriptEntry, "...replacing the linked NPC with " + arg.getValue());
          String value =
              TagManager.tag(
                  scriptEntry.getPlayer(),
                  scriptEntry.getNPC(),
                  arg.getValue(),
                  false,
                  scriptEntry);
          dNPC npc = dNPC.valueOf(value);
          if (npc == null || !npc.isValid()) {
            dB.echoError(value + " is an invalid NPC!");
            return false;
          }
          scriptEntry.setNPC(npc);
        }

        // Save the scriptentry if needed later for fetching scriptentry context
        else if (arg.matchesPrefix("save") && !if_ignore) {
          dB.echoDebug(scriptEntry, "...remembering this script entry!");
          scriptEntry.getResidingQueue().holdScriptEntry(arg.getValue(), scriptEntry);
        } else newArgs.add(arg.raw_value);
      }

      // Add the arguments back to the scriptEntry.
      scriptEntry.setArguments(newArgs);

      // Now process non-instant tags.
      if (scriptEntry.has_tags)
        scriptEntry.setArguments(
            TagManager.fillArguments(scriptEntry.getArguments(), scriptEntry, false));

      // Parse the rest of the arguments for execution.
      command.parseArgs(scriptEntry);

    } catch (InvalidArgumentsException e) {

      keepGoing = false;
      // Give usage hint if InvalidArgumentsException was called.
      dB.echoError("Woah! Invalid arguments were specified!");
      if (e.getMessage() != null && e.getMessage().length() > 0)
        dB.log(
            ChatColor.YELLOW
                + "+> MESSAGE follows: "
                + ChatColor.WHITE
                + "'"
                + e.getMessage()
                + "'");
      dB.log("Usage: " + command.getUsageHint());
      dB.echoDebug(scriptEntry, DebugElement.Footer);
      scriptEntry.setFinished(true);

    } catch (Exception e) {

      keepGoing = false;
      dB.echoError("Woah! An exception has been called with this command!");
      dB.echoError(e);
      dB.echoDebug(scriptEntry, DebugElement.Footer);
      scriptEntry.setFinished(true);

    } finally {

      if (keepGoing)
        try {
          // Run the execute method in the command
          command.execute(scriptEntry);
        } catch (Exception e) {
          dB.echoError("Woah!! An exception has been called with this command!");
          dB.echoError(e);
          scriptEntry.setFinished(true);
        }
    }

    return true;
  }
 /** {@inheritDoc} */
 @Override
 protected void onValidate() throws Exception {
   super.onValidate();
   Assert.notNull(result, "Task result is required.");
   Assert.notNull(result.getFixture(), "Task result must have a fixture");
 }
 public LoginCommand(HttpWrapper http, String login, String password) {
   this.login = login;
   this.password = password;
   super.setHttpWrapper(http);
 }
 public LoginCommand(HttpWrapper http) {
   super.setHttpWrapper(http);
 }
  public static boolean makeChezSnooteeRequest(final String parameters) {
    if (!KoLCharacter.canadiaAvailable()) {
      KoLmafia.updateDisplay(
          "Since you have no access to Little Canadia, you may not visit the restaurant.");
      return false;
    }

    if (KoLConstants.restaurantItems.isEmpty()) {
      ChezSnooteeRequest.getMenu();
    }

    if (parameters.equals("")) {
      RequestLogger.printLine("Today's Special: " + ChezSnooteeRequest.getDailySpecial());
      return false;
    }

    String[] splitParameters = AbstractCommand.splitCountAndName(parameters);
    String countString = splitParameters[0];
    String nameString = splitParameters[1];

    if (nameString.equalsIgnoreCase("daily special")) {
      nameString = ChezSnooteeRequest.getDailySpecial().getName();
    } else if (nameString.startsWith("\u00B6")) {
      String name = ItemDatabase.getItemName(StringUtilities.parseInt(nameString.substring(1)));
      if (name != null) {
        nameString = name;
      }
    }

    nameString = nameString.toLowerCase();

    for (int i = 0; i < KoLConstants.restaurantItems.size(); ++i) {
      String name = (String) KoLConstants.restaurantItems.get(i);

      if (!StringUtilities.substringMatches(name.toLowerCase(), nameString, false)) {
        continue;
      }

      if (KoLmafiaCLI.isExecutingCheckOnlyCommand) {
        RequestLogger.printLine(name);
        return true;
      }

      int count =
          countString == null || countString.length() == 0
              ? 1
              : StringUtilities.parseInt(countString);

      if (count == 0) {
        int fullness = ItemDatabase.getFullness(name);
        if (fullness > 0) {
          count = (KoLCharacter.getFullnessLimit() - KoLCharacter.getFullness()) / fullness;
        }
      }

      for (int j = 0; j < count; ++j) {
        RequestThread.postRequest(new ChezSnooteeRequest(name));
      }

      return true;
    }

    return false;
  }
示例#17
0
 public void setValue(GeneralizedWord node) {
   super.setChild(BaseVariableAssingment.VALUE, node);
 }
 public void execute() {
   super.execute();
   setUndoActivity(createUndoActivity());
   ((InsertImageCommand.UndoActivity) getUndoActivity()).insertImage();
   view().checkDamage();
 }
示例#19
0
 public void setConditionalExpression(ConditionalExpression node) {
   super.setChild(ConditionalCommand.CONDITIONAL_EXPRESSION, node);
 }
示例#20
0
 public void setLvalue(LValue node) {
   super.setChild(BaseVariableAssingment.LVALUE, node);
 }
 public void execute(AbstractCommand command) {
   push(command);
   command.execute();
 }
 public boolean hasCheckpoint() {
   for (AbstractCommand c : mCommandStack) {
     if (c.isCheckpoint()) return true;
   }
   return false;
 }
 public void setCheckpoint() {
   if (!mCommandStack.empty()) {
     AbstractCommand c = mCommandStack.peek();
     c.setCheckpoint(true);
   }
 }