From 73dae7842d5a5a4abad488749a7395694a606dc7 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 22 Apr 2020 12:09:00 +0100 Subject: [PATCH] Only poll for updates every 30 mins. - Don't do GET requests on player join (bad idea, it was sync...) - If there's an update it will notify the player still, it just caches the update status --- .../bukkit/listener/PlayerEvents.java | 43 +++++-------------- .../bukkit/util/UpdateUtility.java | 8 +++- 2 files changed, 16 insertions(+), 35 deletions(-) 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 18f8e18e4..62cd2c5db 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -661,39 +661,16 @@ public class PlayerEvents extends PlotListener implements Listener { }, 20); if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated()) - && Settings.Enabled_Components.UPDATE_NOTIFICATIONS && PremiumVerification.isPremium()) { - 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").getAsString(); - } catch (IOException e) { - new PlotMessage(Captions.PREFIX - + "Unable to check for updates, check console for further information.") - .color("$13"); - PlotSquared.log(Captions.PREFIX + "&cUnable to check for updates because: " + e); - return; - } - - try { - if (!UpdateUtility.internalVersion.equals(spigotVersion)) { - new PlotMessage("-----------------------------------").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) { - e.printStackTrace(); - } + && Settings.Enabled_Components.UPDATE_NOTIFICATIONS && PremiumVerification.isPremium() + && UpdateUtility.hasUpdate) { + new PlotMessage("-----------------------------------").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); } } 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 42b805142..dbec1bc78 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java @@ -43,7 +43,9 @@ public class UpdateUtility implements Listener { public static String internalVersion; public static String spigotVersion; + public static boolean hasUpdate; public final JavaPlugin javaPlugin; + private boolean notify = true; public UpdateUtility(final JavaPlugin javaPlugin) { this.javaPlugin = javaPlugin; @@ -73,10 +75,12 @@ public class UpdateUtility implements Listener { + ", &6latest version is " + spigotVersion); PlotSquared .log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/77506/updates"); - } else { + hasUpdate = true; + } else if (notify) { + notify = false; PlotSquared.log(Captions.PREFIX + "Congratulations! You are running the latest PlotSquared version."); } - }, 0L, 12000L); + }, 0L, 36000L); } }