Skip to content

Commit dff7c42

Browse files
committed
refactor
1 parent 1a9b105 commit dff7c42

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/main/java/fr/lumi/Main.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,9 @@ public void init(){
141141
}
142142

143143

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 {
149147
// Make HTTP GET request
150148
URL url = new URL("https://api.github.com/repos/lumi-git/AutoCommands/tags");
151149
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -159,26 +157,34 @@ public String VerifyPluginVersion() {
159157

160158
// Read response
161159
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
162-
StringBuilder response = new StringBuilder();
160+
163161
String line;
164162
while ((line = reader.readLine()) != null) {
165163
response.append(line);
166164
}
167165
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();
168177

169178
// Parse JSON response
170179
JsonParser parser = new JsonParser();
171-
JsonElement jsonElement = parser.parse(response.toString());
180+
JsonElement jsonElement = parser.parse(response);
172181
if (jsonElement.isJsonArray()) {
173182
JsonArray jsonArray = jsonElement.getAsJsonArray();
174183
if (jsonArray.size() > 0) {
175184
JsonObject latestTag = jsonArray.get(0).getAsJsonObject();
176185
spigotResponse = latestTag.get("name").getAsString();
177186
}
178187
}
179-
} catch (IOException e) {
180-
getLogger().log(Level.WARNING, "Failed to check for a new version on spigot.", e);
181-
}
182188

183189
if (spigotResponse.equals("")) {
184190
return "&cFailed to check for a new version on spigot.";
@@ -188,7 +194,7 @@ public String VerifyPluginVersion() {
188194
return "&aYou are running the latest version of AutoCommands "+ currentVersion +" !";
189195
}
190196

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";
192198
}
193199

194200
@Override

0 commit comments

Comments
 (0)