예제 #1
0
  public static void main(String[] args) throws Exception {
    try {
      // Boilerplate startup stuff
      Implementation.setServerType(Implementation.Type.BUKKIT);
      ClassDiscovery.getDefaultInstance()
          .addDiscoveryLocation(ClassDiscovery.GetClassContainer(DocGen.class));
      ExtensionManager.Initialize(ClassDiscovery.getDefaultInstance());
      Installer.Install(CommandHelperFileLocations.getDefault().getConfigDirectory());
      Prefs.init(CommandHelperFileLocations.getDefault().getPreferencesFile());
      CHLog.initialize(CommandHelperFileLocations.getDefault().getConfigDirectory());

      // System.out.println(functions("wiki", api.Platforms.INTERPRETER_JAVA, true));
      System.out.println(examples("if", true));
      // System.exit(0);
      // events("wiki");
      // System.out.println(Template("persistence_network"));
    } catch (Throwable t) {
      t.printStackTrace();
      System.exit(1);
    } finally {
      System.exit(0);
    }
  }
예제 #2
0
  public static String events(MarkupType type) {
    Set<Class> classes = ClassDiscovery.getDefaultInstance().loadClassesWithAnnotation(api.class);
    Set<Documentation> list = new TreeSet<Documentation>();
    for (Class c : classes) {
      if (Event.class.isAssignableFrom(c) && Documentation.class.isAssignableFrom(c)) {
        try {
          // First, we have to instatiate the event.
          Constructor<Event> cons = c.getConstructor();
          Documentation docs = cons.newInstance();
          list.add(docs);
        } catch (Exception ex) {
          System.err.println("Could not get documentation for " + c.getSimpleName());
        }
      }
    }

    StringBuilder doc = new StringBuilder();
    if (type == MarkupType.HTML) {
      doc.append(
          "Events allow you to trigger scripts not just on commands, but also on other actions, such as"
              + " a player logging in, or a player breaking a block. See the documentation on events for"
              + " more information"
              + "<table><thead><tr><th>Name</th><th>Description</th><th>Prefilters</th>"
              + "<th>Event Data</th><th>Mutable Fields</th><th>Since</th></thead><tbody>");
    } else if (type == MarkupType.WIKI) {
      doc.append(
          "Events allow you to trigger scripts not just on commands, but also on other actions, such as"
              + " a player logging in, or a player breaking a block. See the [[CommandHelper/Events|documentation on events]] for"
              + " more information<br />\n\n");

      doc.append(
          "{| width=\"100%\" cellspacing=\"1\" cellpadding=\"1\" border=\"1\" class=\"wikitable\"\n"
              + "|-\n"
              + "! scope=\"col\" width=\"7%\" | Event Name\n"
              + "! scope=\"col\" width=\"36%\" | Description\n"
              + "! scope=\"col\" width=\"18%\" | Prefilters\n"
              + "! scope=\"col\" width=\"18%\" | Event Data\n"
              + "! scope=\"col\" width=\"18%\" | Mutable Fields\n"
              + "! scope=\"col\" width=\"3%\" | Since\n");
    } else if (type == MarkupType.TEXT) {
      doc.append(
          "Events allow you to trigger scripts not just on commands, but also on other actions, such as"
              + " a player logging in, or a player breaking a block. See the documentation on events for"
              + " more information\n\n\n");
    }
    Pattern p = Pattern.compile("\\{(.*?)\\} *?(.*?) *?\\{(.*?)\\} *?\\{(.*?)\\}");
    for (Documentation d : list) {
      Matcher m = p.matcher(d.docs());
      if (m.find()) {
        String name = d.getName();
        String description = m.group(2).trim();
        String prefilter = PrefilterData.Get(m.group(1).split("\\|"), type);
        String eventData = EventData.Get(m.group(3).split("\\|"), type);
        String mutability = MutabilityData.Get(m.group(4).split("\\|"), type);
        // String manualTrigger = ManualTriggerData.Get(m.group(5).split("\\|"), type);
        String since = d.since().toString();

        if (type == MarkupType.HTML) {
          doc.append("<tr><td style=\"vertical-align:top\">")
              .append(name)
              .append("</td><td style=\"vertical-align:top\">")
              .append(description)
              .append("</td><td style=\"vertical-align:top\">")
              .append(prefilter)
              .append("</td><td style=\"vertical-align:top\">")
              .append(eventData)
              .append("</td><td style=\"vertical-align:top\">")
              .append(mutability)
              .append("</td><td style=\"vertical-align:top\">")
              .append(since)
              .append("</td></tr>\n");
        } else if (type == MarkupType.WIKI) {
          doc.append("|-\n" + "! scope=\"row\" | [[CommandHelper/Event API/")
              .append(name)
              .append("|")
              .append(name)
              .append("]]\n" + "| ")
              .append(description)
              .append("\n" + "| ")
              .append(prefilter)
              .append("\n" + "| ")
              .append(eventData)
              .append("\n" + "| ")
              .append(mutability)
              .append("\n" + "| ")
              .append(since)
              .append("\n");
        } else if (type == MarkupType.TEXT) {
          doc.append("Name: ")
              .append(name)
              .append("\nDescription: ")
              .append(description)
              .append("\nPrefilters:\n")
              .append(prefilter)
              .append("\nEvent Data:\n")
              .append(eventData)
              .append("\nMutable Fields:\n")
              .append(mutability)
              .append("\nSince: ")
              .append(since)
              .append("\n\n");
        }
      }
    }

    if (type == MarkupType.HTML) {
      doc.append("</tbody></table>\n");
    } else if (type == MarkupType.WIKI) {
      doc.append("|}\n");
    }

    if (type == MarkupType.HTML) {
      doc.append(
          ""
              + "<h2>Errors in documentation</h2>\n"
              + "<em>Please note that this documentation is generated automatically,"
              + " if you notice an error in the documentation, please file a bug report for the"
              + " plugin itself!</em>\n");
    } else if (type == MarkupType.WIKI) {
      doc.append(
          ""
              + "===Errors in documentation===\n"
              + "''Please note that this documentation is generated automatically,"
              + " if you notice an error in the documentation, please file a bug report for the"
              + " plugin itself!'' For information on undocumented functions, see [[CommandHelper/Sandbox|this page]]\n\n{{LearningTrail}}\n");
    }
    return doc.toString();
  }