geforkt von Mirrors/FastAsyncWorldEdit
refactor: use HttpClient for update check (#2331)
Dieser Commit ist enthalten in:
Ursprung
90587e56fc
Commit
68eb4e214a
@ -14,7 +14,13 @@ import org.w3c.dom.Document;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.net.URL;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public class UpdateNotification {
|
||||
|
||||
@ -28,11 +34,29 @@ public class UpdateNotification {
|
||||
*/
|
||||
public static void doUpdateCheck() {
|
||||
if (Settings.settings().ENABLED_COMPONENTS.UPDATE_NOTIFICATIONS) {
|
||||
final HttpRequest request = HttpRequest
|
||||
.newBuilder()
|
||||
.uri(URI.create("https://ci.athion.net/job/FastAsyncWorldEdit/api/xml/"))
|
||||
.timeout(Duration.of(10L, ChronoUnit.SECONDS))
|
||||
.build();
|
||||
HttpClient.newHttpClient()
|
||||
.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream())
|
||||
.whenComplete((response, thrown) -> {
|
||||
if (thrown != null) {
|
||||
LOGGER.error("Update check failed: {} ", thrown.getMessage());
|
||||
}
|
||||
processResponseBody(response.body());
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void processResponseBody(InputStream body) {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document doc = db.parse(new URL("https://ci.athion.net/job/FastAsyncWorldEdit/api/xml/").openStream());
|
||||
Document doc = db.parse(body);
|
||||
faweVersion = doc.getElementsByTagName("lastSuccessfulBuild").item(0).getFirstChild().getTextContent();
|
||||
FaweVersion faweVersion = Fawe.instance().getVersion();
|
||||
if (faweVersion.build == 0) {
|
||||
@ -53,11 +77,9 @@ public class UpdateNotification {
|
||||
UpdateNotification.faweVersion
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
LOGGER.error("Unable to check for updates. Skipping.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren