예제 #1
0
  private static Command parseCommand(Node n) {
    NamedNodeMap atts = n.getAttributes();
    String name = atts.getNamedItem("name").getNodeValue();
    String desc = atts.getNamedItem("description").getNodeValue();
    String command = atts.getNamedItem("command").getNodeValue();

    Command com = new Command(name, desc, command);

    NodeList children = n.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);

      if (!child.getNodeName().equals("Argument")) continue;

      NamedNodeMap childAtts = child.getAttributes();
      String childName = childAtts.getNamedItem("name").getNodeValue();
      String childDesc = childAtts.getNamedItem("description").getNodeValue();
      String childVal = "";
      if (childAtts.getNamedItem("default") != null)
        childVal = childAtts.getNamedItem("default").getNodeValue();

      Argument arg = new Argument(childName, childDesc, childVal);

      com.addArgument(arg);
    }

    return com;
  }
예제 #2
0
  private void displayCategory(Category c, Player p) {
    p.sendMessage("----Available Commands and Sub-Categories----");
    p.sendMessage("-----------------------------------------");
    for (Command com : c.listCommands()) {
      p.sendMessage(com.toString());
    }

    for (Category subCat : c.listCategories()) {
      p.sendMessage(subCat.toString());
    }
  }
예제 #3
0
 private void displayCommand(Command c, Player p) {
   p.sendMessage("-------------Command Arguments---------------");
   p.sendMessage("--------------------------------------------");
   for (Argument arg : c.listArguments()) {
     p.sendMessage(arg.toString());
   }
 }
 public Command executeStep(Element stepRow) throws Exception {
   Command command = new Command();
   NodeList stepFields = stepRow.getElementsByTagName("td");
   String cmd = stepFields.item(0).getTextContent().trim();
   command.cmd = cmd;
   ArrayList<String> argList = new ArrayList<String>();
   if (stepFields.getLength() == 1) {
     // skip comments
     command.result = "OK";
     return command;
   }
   for (int i = 1; i < stepFields.getLength(); i++) {
     String content = stepFields.item(i).getTextContent();
     content = content.replaceAll(" +", " ");
     content = content.replace('\u00A0', ' ');
     content = content.trim();
     argList.add(content);
   }
   String args[] = argList.toArray(new String[0]);
   command.args = args;
   if (this.verbose) {
     System.out.println(cmd + " " + Arrays.asList(args));
   }
   try {
     command.result = this.commandProcessor.doCommand(cmd, args);
     command.error = false;
   } catch (Exception e) {
     command.result = e.getMessage();
     command.error = true;
   }
   command.failure = command.error && !cmd.startsWith("verify");
   if (this.verbose) {
     System.out.println(command.result);
   }
   return command;
 }
예제 #5
0
  public void update(Player p, String value, boolean showPrompt) {
    if (value.equals("reset")) {
      reset();
      return;
    }

    if (activeCom != null) {
      activeCom.update(this, value);
      if (showPrompt) nextPrompt(p);
    }

    if (activeCat != null) {
      activeCat.update(this, value);
      if (showPrompt) nextPrompt(p);
    }

    if (activeCom == null && activeCat == null) {
      rootNode.update(this, value);
      if (showPrompt) nextPrompt(p);
    }
  }
예제 #6
0
  public String[] getArgs() {
    if (activeCom == null) return null;

    return activeCom.getArgs();
  }
예제 #7
0
  public String getCommand() {
    if (activeCom == null) return null;

    return activeCom.getCommand();
  }
예제 #8
0
  public boolean isDone() {
    if (activeCom == null) return false;

    return activeCom.isDone();
  }