|
13 | 13 | import org.bukkit.command.CommandSender;
|
14 | 14 | import org.bukkit.entity.Player;
|
15 | 15 | import org.bukkit.plugin.Plugin;
|
| 16 | +import org.json.JSONArray; |
16 | 17 | import org.json.JSONObject;
|
17 | 18 |
|
18 | 19 | import java.io.BufferedReader;
|
|
21 | 22 | import java.io.OutputStream;
|
22 | 23 | import java.net.HttpURLConnection;
|
23 | 24 | import java.net.URL;
|
24 |
| -import java.util.ArrayList; |
25 |
| -import java.util.List; |
26 | 25 |
|
27 | 26 | @CommandAlias("slreport|sldump|synklibsreport|synklibsdump")
|
28 | 27 | public class ReportCmd extends BaseCommand {
|
@@ -81,68 +80,36 @@ public void onReport(CommandSender sender) {
|
81 | 80 | }
|
82 | 81 |
|
83 | 82 | private String getJsonString() {
|
84 |
| - String s = "{\n" + |
85 |
| - " \"serverVersion\": \""+ Bukkit.getServer().getVersion()+ "\",\n" + |
86 |
| - " \"serverSoftware\": \""+ Bukkit.getServer().getBukkitVersion()+ "\",\n" + |
87 |
| - " \"operatingSystem\": \""+ System.getProperty("os.name")+" "+System.getProperty("os.version")+" "+ System.getProperty("os.arch")+ "\",\n" + |
88 |
| - " \"plugins\": [\n" + |
89 |
| - pluginsString() + |
90 |
| - " ],\n" + |
91 |
| - " \"additionalInfo\": {\n" + |
92 |
| - " \"online-mode\": \""+Bukkit.getServer().getOnlineMode()+"\"\n" + |
93 |
| - " },\n" + |
94 |
| - " \"configs\": [\n" + |
95 |
| - configsString() + |
96 |
| - " ],\n" + |
97 |
| - " }\n" + |
98 |
| - "}\n"; |
99 |
| - return s; |
100 |
| - } |
| 83 | + JSONObject jsonObject = new JSONObject(); |
| 84 | + jsonObject.put("serverVersion", Bukkit.getServer().getVersion()); |
| 85 | + jsonObject.put("serverSoftware", Bukkit.getServer().getBukkitVersion()); |
| 86 | + jsonObject.put("operatingSystem", System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch")); |
| 87 | + jsonObject.put("javaVersion", System.getProperty("java.version")+" "+ System.getProperty("java.vendor")+" "+System.getProperty("java.vm.name")); |
101 | 88 |
|
102 |
| - private String pluginsString() { |
103 |
| - List<String> list = new ArrayList<>(); |
| 89 | + JSONArray pluginsArray = new JSONArray(); |
104 | 90 | for (Plugin pl : Bukkit.getPluginManager().getPlugins()) {
|
105 |
| - list.add("{\n" + |
106 |
| - " \"name\": \""+pl.getName()+"\",\n" + |
107 |
| - " \"version\": \""+pl.getDescription().getVersion()+"\"\n" + |
108 |
| - " }"); |
| 91 | + JSONObject pluginObject = new JSONObject(); |
| 92 | + pluginObject.put("name", pl.getName()); |
| 93 | + pluginObject.put("version", pl.getDescription().getVersion()); |
| 94 | + pluginsArray.put(pluginObject); |
109 | 95 | }
|
| 96 | + jsonObject.put("plugins", pluginsArray); |
110 | 97 |
|
111 |
| - if (list.size() == 1) { |
112 |
| - return list.get(0); |
113 |
| - } |
114 |
| - StringBuilder sb = new StringBuilder(); |
115 |
| - int index=0; |
116 |
| - for (int i = 0; i < list.size()-1; i++) { |
117 |
| - sb.append(list.get(i)).append(", \n"); |
118 |
| - index = i; |
119 |
| - } |
120 |
| - sb.append(list.get(index+1)); |
121 |
| - return sb.toString(); |
122 |
| - } |
123 |
| - private String configsString() { |
124 |
| - List<String> list = new ArrayList<>(); |
| 98 | + JSONObject additionalInfo = new JSONObject(); |
| 99 | + additionalInfo.put("online-mode", Bukkit.getServer().getOnlineMode()); |
| 100 | + jsonObject.put("additionalInfo", additionalInfo); |
| 101 | + |
| 102 | + JSONArray configsArray = new JSONArray(); |
125 | 103 | for (Plugin pl : Bukkit.getPluginManager().getPlugins()) {
|
126 | 104 | if (pl.getDescription().getAuthors().contains("Synk")) {
|
127 |
| - |
128 |
| - list.add("{\n" + |
129 |
| - " \"name\": \""+pl.getName()+"\",\n" + |
130 |
| - " \"config\": \""+pl.getConfig().saveToString()+"\"\n" + |
131 |
| - " }"); |
| 105 | + JSONObject configObject = new JSONObject(); |
| 106 | + configObject.put("name", pl.getName()); |
| 107 | + configObject.put("config", pl.getConfig().saveToString()); |
| 108 | + configsArray.put(configObject); |
132 | 109 | }
|
133 |
| - |
134 | 110 | }
|
| 111 | + jsonObject.put("configs", configsArray); |
135 | 112 |
|
136 |
| - if (list.size() == 1) { |
137 |
| - return list.get(0); |
138 |
| - } |
139 |
| - StringBuilder sb = new StringBuilder(); |
140 |
| - int index=0; |
141 |
| - for (int i = 0; i < list.size()-1; i++) { |
142 |
| - sb.append(list.get(i)).append(", \n"); |
143 |
| - index = i; |
144 |
| - } |
145 |
| - sb.append(list.get(index+1)); |
146 |
| - return sb.toString(); |
| 113 | + return jsonObject.toString(2); |
147 | 114 | }
|
148 | 115 | }
|
0 commit comments