|
19 | 19 | import net.kyori.adventure.text.Component; |
20 | 20 | import net.kyori.adventure.text.format.NamedTextColor; |
21 | 21 | import org.apache.commons.io.FileUtils; |
22 | | -import org.apache.http.HttpResponse; |
23 | | -import org.apache.http.client.methods.HttpGet; |
24 | | -import org.apache.http.impl.client.CloseableHttpClient; |
25 | | -import org.apache.http.impl.client.HttpClients; |
26 | | -import org.apache.http.util.EntityUtils; |
27 | 22 | import org.bukkit.Bukkit; |
28 | 23 | import org.bukkit.command.CommandSender; |
29 | 24 | import org.json.JSONException; |
30 | | -import org.json.JSONObject; |
31 | 25 |
|
32 | 26 | public class UpdateChecker implements PlexBase |
33 | 27 | { |
@@ -154,49 +148,54 @@ public boolean getUpdateStatusMessage(CommandSender sender, boolean cached, int |
154 | 148 |
|
155 | 149 | public void updateJar(CommandSender sender, String name, boolean module) |
156 | 150 | { |
157 | | - CloseableHttpClient client = HttpClients.createDefault(); |
158 | 151 | AtomicReference<String> url = new AtomicReference<>(DOWNLOAD_PAGE + name); |
159 | 152 | if (!module) |
160 | 153 | { |
161 | 154 | url.set(url.get() + "/job/" + BRANCH); |
162 | 155 | } |
163 | 156 | PlexLog.debug(url.toString()); |
164 | | - HttpGet get = new HttpGet(url + "/lastSuccessfulBuild/api/json"); |
165 | 157 | try |
166 | 158 | { |
167 | | - HttpResponse response = client.execute(get); |
168 | | - int statusCode = response.getStatusLine().getStatusCode(); |
| 159 | + HttpURLConnection connection = (HttpURLConnection) URI.create(url + "/lastSuccessfulBuild/api/json").toURL().openConnection(); |
| 160 | + int statusCode = connection.getResponseCode(); |
169 | 161 |
|
170 | 162 | if (statusCode == HttpURLConnection.HTTP_OK) |
171 | 163 | { |
172 | | - JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)); |
173 | | - JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0); |
174 | | - String jarFile = artifact.getString("fileName"); |
175 | | - sender.sendMessage(PlexUtils.mmDeserialize("<green>Downloading latest JAR file: " + jarFile)); |
176 | | - File copyTo; |
177 | | - if (!module) |
| 164 | + try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) |
178 | 165 | { |
179 | | - copyTo = new File(Bukkit.getUpdateFolderFile(), jarFile); |
180 | | - } |
181 | | - else |
182 | | - { |
183 | | - copyTo = new File(plugin.getModulesFolder().getPath(), jarFile); |
184 | | - } |
185 | | - CompletableFuture.runAsync(() -> |
186 | | - { |
187 | | - try |
| 166 | + JsonObject object = new Gson().fromJson(reader, JsonObject.class); |
| 167 | + JsonObject artifact = object.getAsJsonArray("artifacts").asList().getFirst().getAsJsonObject(); |
| 168 | + String jarFile = artifact.get("fileName").getAsString(); |
| 169 | + sender.sendMessage(PlexUtils.mmDeserialize("<green>Downloading latest JAR file: " + jarFile)); |
| 170 | + File copyTo; |
| 171 | + if (!module) |
188 | 172 | { |
189 | | - FileUtils.copyURLToFile( |
190 | | - URI.create(url + "/lastSuccessfulBuild/artifact/build/libs/" + jarFile).toURL(), |
191 | | - copyTo |
192 | | - ); |
193 | | - sender.sendMessage(PlexUtils.mmDeserialize("<green>New JAR file downloaded successfully.")); |
| 173 | + copyTo = new File(Bukkit.getUpdateFolderFile(), jarFile); |
194 | 174 | } |
195 | | - catch (IOException e) |
| 175 | + else |
196 | 176 | { |
197 | | - e.printStackTrace(); |
| 177 | + copyTo = new File(plugin.getModulesFolder().getPath(), jarFile); |
198 | 178 | } |
199 | | - }); |
| 179 | + CompletableFuture.runAsync(() -> |
| 180 | + { |
| 181 | + try |
| 182 | + { |
| 183 | + FileUtils.copyURLToFile( |
| 184 | + URI.create(url + "/lastSuccessfulBuild/artifact/build/libs/" + jarFile).toURL(), |
| 185 | + copyTo |
| 186 | + ); |
| 187 | + sender.sendMessage(PlexUtils.mmDeserialize("<green>New JAR file downloaded successfully.")); |
| 188 | + } |
| 189 | + catch (IOException e) |
| 190 | + { |
| 191 | + e.printStackTrace(); |
| 192 | + } |
| 193 | + }); |
| 194 | + } |
| 195 | + catch (JsonSyntaxException | NumberFormatException e) |
| 196 | + { |
| 197 | + e.printStackTrace(); |
| 198 | + } |
200 | 199 | } |
201 | 200 | else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) |
202 | 201 | { |
|
0 commit comments