diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index e9cb28a85..42faf6beb 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -190,7 +190,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain return; } - new UpdateUtility(this).updateChecker(); + if (Settings.Enabled_Components.UPDATE_NOTIFICATIONS) { + new UpdateUtility(this).updateChecker(); + } if (PremiumVerification.isPremium()) { PlotSquared.log(Captions.PREFIX + "&6PlotSquared version licensed to Spigot user " + getUserID()); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 48cba40ca..d88ced453 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -26,6 +26,9 @@ package com.plotsquared.bukkit.listener; import com.destroystokyo.paper.MaterialTags; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.stream.JsonReader; import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.UpdateUtility; @@ -660,11 +663,13 @@ public class PlayerEvents extends PlotListener implements Listener { && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) { try { HttpsURLConnection connection = (HttpsURLConnection) new URL( - "https://api.spigotmc.org/legacy/update.php?resource=77506").openConnection(); + "https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506") + .openConnection(); connection.setRequestMethod("GET"); - spigotVersion = - (new BufferedReader(new InputStreamReader(connection.getInputStream()))) - .readLine(); + JsonObject result = (new JsonParser()) + .parse(new JsonReader(new InputStreamReader(connection.getInputStream()))) + .getAsJsonObject(); + spigotVersion = result.get("current_version").toString(); } catch (IOException e) { new PlotMessage(Captions.PREFIX + "Unable to check for updates, check console for further information.") @@ -674,14 +679,15 @@ public class PlayerEvents extends PlotListener implements Listener { } try { - if (!UpdateUtility.internalVersion.equals(UpdateUtility.spigotVersion)) { + if (!UpdateUtility.internalVersion.equals(spigotVersion)) { new PlotMessage("-----------------------------------").send(pp); - new PlotMessage(Captions.PREFIX + "There appears to be a PlotSquared update available!") - .color("$1").tooltip("https://www.spigotmc.org/resources/77506/updates").send(pp); - new PlotMessage(Captions.PREFIX + "The latest version is " + spigotVersion).color("$1").tooltip("https://www.spigotmc.org/resources/77506/updates") - .send(pp); - new PlotMessage(Captions.PREFIX + "https://www.spigotmc.org/resources/77506/updates") - .color("$1").tooltip("https://www.spigotmc.org/resources/77506/updates").send(pp); + new PlotMessage( + Captions.PREFIX + "There appears to be a PlotSquared update available!") + .color("$1").send(pp); + new PlotMessage(Captions.PREFIX + "The latest version is " + spigotVersion) + .color("$1").send(pp); + new PlotMessage(Captions.PREFIX + "Download at:").color("$1").send(pp); + player.sendMessage(" https://www.spigotmc.org/resources/77506/updates"); new PlotMessage("-----------------------------------").send(pp); } } catch (final Exception e) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java index 3378776a5..949522ef0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java @@ -25,16 +25,16 @@ */ package com.plotsquared.bukkit.util; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.stream.JsonReader; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; -import com.plotsquared.core.configuration.Settings; import org.bukkit.Bukkit; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; import javax.net.ssl.HttpsURLConnection; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; @@ -51,32 +51,32 @@ public class UpdateUtility implements Listener { } public void updateChecker() { - new BukkitRunnable() { - public void run() { - Bukkit.getScheduler().runTaskAsynchronously(UpdateUtility.this.javaPlugin, () -> { - if (Settings.Enabled_Components.UPDATE_NOTIFICATIONS) { - try { - HttpsURLConnection connection = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=77506").openConnection(); - connection.setRequestMethod("GET"); - spigotVersion = (new BufferedReader(new InputStreamReader(connection.getInputStream()))).readLine(); - } catch (IOException e) { - PlotSquared.log( - Captions.PREFIX + "&cUnable to check for updates because: " + e); - this.cancel(); - return; - } - - if (!internalVersion.equals(spigotVersion)) { - PlotSquared.log(Captions.PREFIX + "&6There appears to be a PlotSquared update available!"); - PlotSquared.log(Captions.PREFIX + "&6You are running version " + internalVersion + ", &6latest version is " + spigotVersion); - PlotSquared.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/77506/updates"); - } else { - PlotSquared.log(Captions.PREFIX + "Congratulations! You are running the latest PlotSquared version."); - } - } - this.cancel(); - }); + Bukkit.getScheduler().runTaskTimerAsynchronously(this.javaPlugin, () -> { + try { + HttpsURLConnection connection = (HttpsURLConnection) new URL( + "https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506") + .openConnection(); + connection.setRequestMethod("GET"); + JsonObject result = (new JsonParser()) + .parse(new JsonReader(new InputStreamReader(connection.getInputStream()))) + .getAsJsonObject(); + spigotVersion = result.get("current_version").toString(); + } catch (IOException e) { + PlotSquared.log(Captions.PREFIX + "&cUnable to check for updates because: " + e); + return; } - }.runTaskTimer(this.javaPlugin, 0L, 12000L); + + if (!internalVersion.equals(spigotVersion)) { + PlotSquared + .log(Captions.PREFIX + "&6There appears to be a PlotSquared update available!"); + PlotSquared.log(Captions.PREFIX + "&6You are running version " + internalVersion + + ", &6latest version is " + spigotVersion); + PlotSquared + .log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/77506/updates"); + } else { + PlotSquared.log(Captions.PREFIX + + "Congratulations! You are running the latest PlotSquared version."); + } + }, 0L, 12000L); } }