From 997f6f2e02f9abe07a61de975d5db28467fdfb0c Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Sat, 11 Jan 2020 21:25:04 +0800
Subject: [PATCH] Switch to HttpRequest util.
Former-commit-id: 52b65d3821d1bfe04b838c7c86c00c72e52459b2
---
pom.xml | 2 +-
.../org/maxgamer/quickshop/Util/Updater.java | 19 +++++++++----------
.../quickshop/Watcher/UpdateWatcher.java | 2 +-
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/pom.xml b/pom.xml
index c392a72cf..a6680a801 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
org.maxgamer
QuickShop
- Reremake 3.0.6
+ Reremake 3.0.7
diff --git a/src/main/java/org/maxgamer/quickshop/Util/Updater.java b/src/main/java/org/maxgamer/quickshop/Util/Updater.java
index 54323a62b..c2b22bfae 100644
--- a/src/main/java/org/maxgamer/quickshop/Util/Updater.java
+++ b/src/main/java/org/maxgamer/quickshop/Util/Updater.java
@@ -29,7 +29,6 @@ import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.Util.Github.GithubAPI;
import org.maxgamer.quickshop.Util.Github.ReleaseJsonContainer;
-import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.URL;
import java.util.Objects;
@@ -45,18 +44,18 @@ public class Updater {
return new UpdateInfomation(false, null);
}
try {
- HttpsURLConnection connection = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=62575")
- .openConnection();
- int timed_out = 300000;
- connection.setConnectTimeout(timed_out);
- connection.setReadTimeout(timed_out);
+
String localPluginVersion = QuickShop.instance.getDescription().getVersion();
- String spigotPluginVersion = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
- if (spigotPluginVersion != null && !spigotPluginVersion.isEmpty() && !spigotPluginVersion.equals(localPluginVersion)) {
- connection.disconnect();
+ String spigotPluginVersion = HttpRequest.get(new URL("https://api.spigotmc.org/legacy/update.php?resource=62575"))
+ .execute()
+ .expectResponseCode(200)
+ .returnContent()
+ .asString("UTF-8")
+ .trim();
+ if (!spigotPluginVersion.isEmpty() && !spigotPluginVersion.equals(localPluginVersion)) {
+ Util.debugLog(spigotPluginVersion);
return new UpdateInfomation(spigotPluginVersion.toLowerCase().contains("beta"), spigotPluginVersion);
}
- connection.disconnect();
return new UpdateInfomation(false, spigotPluginVersion);
} catch (IOException e) {
Bukkit.getConsoleSender()
diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java
index fd9e1d162..4bd1509e8 100644
--- a/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java
+++ b/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java
@@ -67,7 +67,7 @@ public class UpdateWatcher implements Listener {
hasNewUpdate = true;
if (!info.isBeta()) {
- QuickShop.instance.getLogger().info("A new version of QuickShop has been released!");
+ QuickShop.instance.getLogger().info("A new version of QuickShop has been released! ["+info.getVersion()+"]");
QuickShop.instance.getLogger().info("Update here: https://www.spigotmc.org/resources/62575/");
Bukkit.getOnlinePlayers().forEach(player -> {