Skip to content

Commit 4c15933

Browse files
committed
Initial commit.
Signed-off-by: Robert Xu <robxu9@gmail.com>
0 parents  commit 4c15933

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

pom.xml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.theminequest</groupId>
5+
<artifactId>docparser</artifactId>
6+
<version>dev-SNAPSHOT</version>
7+
8+
<repositories>
9+
<repository>
10+
<id>bukkit-repo</id>
11+
<url>http://repo.bukkit.org/content/groups/public/</url>
12+
</repository>
13+
<repository>
14+
<id>jci-repo</id>
15+
<url>http://jci.lincomlinux.org/plugin/repository/everything/</url>
16+
</repository>
17+
</repositories>
18+
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>maven-compiler-plugin</artifactId>
24+
<version>2.0.2</version>
25+
<configuration>
26+
<source>1.7</source>
27+
<target>1.7</target>
28+
</configuration>
29+
</plugin>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-shade-plugin</artifactId>
33+
<version>1.6</version>
34+
<executions>
35+
<execution>
36+
<phase>package</phase>
37+
<goals>
38+
<goal>shade</goal>
39+
</goals>
40+
<configuration>
41+
<artifactSet>
42+
<excludes>
43+
<exclude>org.bukkit:*</exclude>
44+
<exclude>com.theminequest:api</exclude>
45+
</excludes>
46+
</artifactSet>
47+
</configuration>
48+
</execution>
49+
</executions>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
54+
<dependencies>
55+
<dependency>
56+
<groupId>org.bukkit</groupId>
57+
<artifactId>bukkit</artifactId>
58+
<version>LATEST</version>
59+
<type>jar</type>
60+
<scope>compile</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>com.theminequest</groupId>
64+
<artifactId>api</artifactId>
65+
<version>3.0.0-SNAPSHOT</version>
66+
<type>jar</type>
67+
<scope>compile</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.reflections</groupId>
71+
<artifactId>reflections</artifactId>
72+
<version>0.9.9-RC1</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>com.google.code.gson</groupId>
76+
<artifactId>gson</artifactId>
77+
<version>2.2.4</version>
78+
</dependency>
79+
</dependencies>
80+
81+
</project>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.theminequest.docparser;
2+
3+
import java.io.BufferedWriter;
4+
import java.io.File;
5+
import java.io.FileWriter;
6+
import java.io.IOException;
7+
import java.io.PrintWriter;
8+
import java.util.HashMap;
9+
import java.util.Set;
10+
11+
import org.bukkit.Bukkit;
12+
import org.bukkit.plugin.java.JavaPlugin;
13+
import org.reflections.Reflections;
14+
import org.reflections.scanners.SubTypesScanner;
15+
import org.reflections.scanners.TypeAnnotationsScanner;
16+
import org.reflections.util.ClasspathHelper;
17+
18+
import com.google.gson.Gson;
19+
import com.google.gson.GsonBuilder;
20+
import com.theminequest.doc.V1Documentation;
21+
22+
// ty to http://stackoverflow.com/a/60766
23+
public class Main extends JavaPlugin {
24+
25+
public void onEnable() {
26+
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
27+
28+
@Override
29+
public void run() {
30+
Reflections reflections = new Reflections(ClasspathHelper.forClassLoader(), new TypeAnnotationsScanner(), new SubTypesScanner());
31+
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(V1Documentation.class);
32+
33+
HashMap<String, HashMap<String, HashMap<String, Object>>> information = new HashMap<>();
34+
Gson gson = new GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create();
35+
36+
for (Class<?> clazz : classes) {
37+
V1Documentation doc = clazz.getAnnotation(V1Documentation.class);
38+
if (!information.containsKey(doc.type()))
39+
information.put(doc.type(), new HashMap<String, HashMap<String, Object>>());
40+
41+
HashMap<String, HashMap<String, Object>> type = information.get(doc.type());
42+
HashMap<String, Object> props = new HashMap<String, Object>();
43+
props.put("description", doc.description());
44+
props.put("arguments", doc.arguments());
45+
props.put("typearguments", doc.typeArguments());
46+
props.put("hidden", Boolean.toString(doc.hide()));
47+
type.put(doc.ident(), props);
48+
}
49+
50+
File f = new File("result");
51+
52+
try {
53+
if (!f.exists())
54+
f.createNewFile();
55+
try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(f)))) {
56+
writer.println(gson.toJson(information));
57+
}
58+
} catch (IOException e1) {
59+
e1.printStackTrace();
60+
}
61+
62+
}
63+
64+
}, 5);
65+
}
66+
}

src/main/resources/plugin.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: MineQuest-DocParser
2+
main: com.theminequest.docparser.Main
3+
version: 0
4+
5+
author: Xu_R
6+
7+
description: Documentation Parser
8+
website: www.theminequest.com
9+
10+
load: POSTWORLD
11+
12+
depend: [MineQuest]

0 commit comments

Comments
 (0)