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
This commit is contained in:
dordsor21 2020-04-22 12:09:00 +01:00
parent 92a18d810c
commit 73dae7842d
2 changed files with 16 additions and 35 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}