mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
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:
parent
92a18d810c
commit
73dae7842d
@ -661,39 +661,16 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
}, 20);
|
}, 20);
|
||||||
|
|
||||||
if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated())
|
if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated())
|
||||||
&& Settings.Enabled_Components.UPDATE_NOTIFICATIONS && PremiumVerification.isPremium()) {
|
&& Settings.Enabled_Components.UPDATE_NOTIFICATIONS && PremiumVerification.isPremium()
|
||||||
try {
|
&& UpdateUtility.hasUpdate) {
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(
|
new PlotMessage("-----------------------------------").send(pp);
|
||||||
"https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506")
|
new PlotMessage(Captions.PREFIX + "There appears to be a PlotSquared update available!")
|
||||||
.openConnection();
|
.color("$1").send(pp);
|
||||||
connection.setRequestMethod("GET");
|
new PlotMessage(Captions.PREFIX + "The latest version is " + spigotVersion).color("$1")
|
||||||
JsonObject result = (new JsonParser())
|
.send(pp);
|
||||||
.parse(new JsonReader(new InputStreamReader(connection.getInputStream())))
|
new PlotMessage(Captions.PREFIX + "Download at:").color("$1").send(pp);
|
||||||
.getAsJsonObject();
|
player.sendMessage(" https://www.spigotmc.org/resources/77506/updates");
|
||||||
spigotVersion = result.get("current_version").getAsString();
|
new PlotMessage("-----------------------------------").send(pp);
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,9 @@ public class UpdateUtility implements Listener {
|
|||||||
|
|
||||||
public static String internalVersion;
|
public static String internalVersion;
|
||||||
public static String spigotVersion;
|
public static String spigotVersion;
|
||||||
|
public static boolean hasUpdate;
|
||||||
public final JavaPlugin javaPlugin;
|
public final JavaPlugin javaPlugin;
|
||||||
|
private boolean notify = true;
|
||||||
|
|
||||||
public UpdateUtility(final JavaPlugin javaPlugin) {
|
public UpdateUtility(final JavaPlugin javaPlugin) {
|
||||||
this.javaPlugin = javaPlugin;
|
this.javaPlugin = javaPlugin;
|
||||||
@ -73,10 +75,12 @@ public class UpdateUtility implements Listener {
|
|||||||
+ ", &6latest version is " + spigotVersion);
|
+ ", &6latest version is " + spigotVersion);
|
||||||
PlotSquared
|
PlotSquared
|
||||||
.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/77506/updates");
|
.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/77506/updates");
|
||||||
} else {
|
hasUpdate = true;
|
||||||
|
} else if (notify) {
|
||||||
|
notify = false;
|
||||||
PlotSquared.log(Captions.PREFIX
|
PlotSquared.log(Captions.PREFIX
|
||||||
+ "Congratulations! You are running the latest PlotSquared version.");
|
+ "Congratulations! You are running the latest PlotSquared version.");
|
||||||
}
|
}
|
||||||
}, 0L, 12000L);
|
}, 0L, 36000L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user