@@ -141,11 +141,9 @@ public void init(){
141
141
}
142
142
143
143
144
-
145
- public String VerifyPluginVersion () {
146
- String spigotResponse = "" ;
147
- String currentVersion = this .getDescription ().getVersion ();
148
- try {
144
+ public String callGithubForTag (){
145
+ StringBuilder response = new StringBuilder ();
146
+ try {
149
147
// Make HTTP GET request
150
148
URL url = new URL ("https://api.github.com/repos/lumi-git/AutoCommands/tags" );
151
149
HttpURLConnection connection = (HttpURLConnection ) url .openConnection ();
@@ -159,26 +157,34 @@ public String VerifyPluginVersion() {
159
157
160
158
// Read response
161
159
BufferedReader reader = new BufferedReader (new InputStreamReader (connection .getInputStream ()));
162
- StringBuilder response = new StringBuilder ();
160
+
163
161
String line ;
164
162
while ((line = reader .readLine ()) != null ) {
165
163
response .append (line );
166
164
}
167
165
reader .close ();
166
+ } catch (IOException e ) {
167
+ getLogger ().log (Level .WARNING , "Failed to check for a new version on spigot." , e );
168
+ }
169
+ return response .toString ();
170
+ }
171
+
172
+ public String VerifyPluginVersion () {
173
+ String spigotResponse = "" ;
174
+ String currentVersion = this .getDescription ().getVersion ();
175
+
176
+ String response = callGithubForTag ();
168
177
169
178
// Parse JSON response
170
179
JsonParser parser = new JsonParser ();
171
- JsonElement jsonElement = parser .parse (response . toString () );
180
+ JsonElement jsonElement = parser .parse (response );
172
181
if (jsonElement .isJsonArray ()) {
173
182
JsonArray jsonArray = jsonElement .getAsJsonArray ();
174
183
if (jsonArray .size () > 0 ) {
175
184
JsonObject latestTag = jsonArray .get (0 ).getAsJsonObject ();
176
185
spigotResponse = latestTag .get ("name" ).getAsString ();
177
186
}
178
187
}
179
- } catch (IOException e ) {
180
- getLogger ().log (Level .WARNING , "Failed to check for a new version on spigot." , e );
181
- }
182
188
183
189
if (spigotResponse .equals ("" )) {
184
190
return "&cFailed to check for a new version on spigot." ;
@@ -188,7 +194,7 @@ public String VerifyPluginVersion() {
188
194
return "&aYou are running the latest version of AutoCommands " + currentVersion +" !" ;
189
195
}
190
196
191
- return "&eAutoCommands &a&l" + spigotResponse +" &eis available! &c(https ://www.spigotmc.org/resources/acmd-%E2%8F%B0-%E2%8F%B3-autocommands-1-13-1-20-4.100090) " ;
197
+ return "&eAutoCommands &a&l" + spigotResponse +" &eis available! &chttps ://www.spigotmc.org/resources/acmd-%E2%8F%B0-%E2%8F%B3-autocommands-1-13-1-20-4.100090" ;
192
198
}
193
199
194
200
@ Override
0 commit comments