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; }
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()); } }
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; }
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); } }
public String[] getArgs() { if (activeCom == null) return null; return activeCom.getArgs(); }
public String getCommand() { if (activeCom == null) return null; return activeCom.getCommand(); }
public boolean isDone() { if (activeCom == null) return false; return activeCom.isDone(); }