Only check for updates each 30 minutes, fixes #6
This commit is contained in:
parent
b46f6fbb1f
commit
51202f1116
2 changed files with 15 additions and 17 deletions
|
|
@ -1,25 +1,13 @@
|
||||||
package net.frankheijden.serverutils.common.managers;
|
package net.frankheijden.serverutils.common.managers;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||||
|
|
||||||
public class UpdateManager {
|
public class UpdateManager {
|
||||||
|
|
||||||
private JsonElement lastResponse;
|
private String downloadedVersion = ServerUtilsApp.VERSION;
|
||||||
private String downloadedVersion;
|
private long lastUpdateCheck = 0;
|
||||||
|
|
||||||
public UpdateManager() {
|
public UpdateManager() {}
|
||||||
this.lastResponse = null;
|
|
||||||
this.downloadedVersion = ServerUtilsApp.VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonElement getLastResponse() {
|
|
||||||
return lastResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastResponse(JsonElement lastResponse) {
|
|
||||||
this.lastResponse = lastResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDownloadedVersion() {
|
public String getDownloadedVersion() {
|
||||||
return downloadedVersion;
|
return downloadedVersion;
|
||||||
|
|
@ -32,4 +20,12 @@ public class UpdateManager {
|
||||||
public boolean hasDownloaded() {
|
public boolean hasDownloaded() {
|
||||||
return !downloadedVersion.equals(ServerUtilsApp.VERSION);
|
return !downloadedVersion.equals(ServerUtilsApp.VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canRunUpdateCheck() {
|
||||||
|
return lastUpdateCheck + 1000 * 60 * 30 <= System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateLastUpdateCheck() {
|
||||||
|
this.lastUpdateCheck = System.currentTimeMillis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,11 @@ public class UpdateCheckerTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
plugin.getLogger().info(UPDATE_CHECK_START);
|
|
||||||
|
|
||||||
UpdateManager updateManager = plugin.getUpdateManager();
|
UpdateManager updateManager = plugin.getUpdateManager();
|
||||||
|
if (!updateManager.canRunUpdateCheck()) return;
|
||||||
|
updateManager.updateLastUpdateCheck();
|
||||||
|
|
||||||
|
plugin.getLogger().info(UPDATE_CHECK_START);
|
||||||
|
|
||||||
GitHubResponse pluginResponse = getResponse(GITHUB_LINK);
|
GitHubResponse pluginResponse = getResponse(GITHUB_LINK);
|
||||||
if (pluginResponse == null) return;
|
if (pluginResponse == null) return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue