Hopefully delay update checks on constant restarts to still be 6 hours

This commit is contained in:
libraryaddict 2020-07-07 12:03:46 +12:00
parent 3d4329942c
commit 45331de38c
3 changed files with 21 additions and 3 deletions

View File

@ -253,6 +253,9 @@ public class DisguiseConfig {
@Getter
@Setter
private static boolean saveUserPreferences;
@Getter
@Setter
private static long lastUpdateRequest;
public static boolean isArmorstandsName() {
return getPlayerNameType() == PlayerNameType.ARMORSTANDS;
@ -311,12 +314,20 @@ public class DisguiseConfig {
return;
}
long timeSinceLast = System.currentTimeMillis() - (getLastUpdateRequest() + TimeUnit.HOURS.toMillis(6));
if (timeSinceLast > 0) {
timeSinceLast /= 50;
} else {
timeSinceLast = 0;
}
updaterTask = Bukkit.getScheduler().runTaskTimerAsynchronously(LibsDisguises.getInstance(), new Runnable() {
@Override
public void run() {
LibsDisguises.getInstance().getUpdateChecker().doAutoUpdateCheck();
}
}, 0, (20 * TimeUnit.HOURS.toSeconds(6))); // Check every 6 hours
}, timeSinceLast, (20 * TimeUnit.HOURS.toSeconds(6))); // Check every 6 hours
}
public static void setUsingReleaseBuilds(boolean useReleaseBuilds) {
@ -350,6 +361,7 @@ public class DisguiseConfig {
bisectHosted = configuration.getBoolean("Bisect-Hosted", isBisectHosted());
savedServerIp = configuration.getString("Server-IP", getSavedServerIp());
usingReleaseBuild = configuration.getBoolean("ReleaseBuild", isUsingReleaseBuild());
lastUpdateRequest = configuration.getLong("LastUpdateRequest", 0L);
if (!configuration.contains("Bisect-Hosted") || !configuration.contains("Server-IP") ||
!configuration.contains("ReleaseBuild")) {
@ -364,7 +376,8 @@ public class DisguiseConfig {
.getResourceAsString(LibsDisguises.getInstance().getFile(), "internal.yml");
// Bisect hosted, server ip, release builds
for (Object s : new Object[]{isBisectHosted(), getSavedServerIp(), isUsingReleaseBuild()}) {
for (Object s : new Object[]{isBisectHosted(), getSavedServerIp(), isUsingReleaseBuild(),
getLastUpdateRequest()}) {
internalConfig = internalConfig.replaceFirst("%data%", "" + s);
}

View File

@ -156,6 +156,9 @@ public class UpdateChecker {
}
public LibsMsg doUpdateCheck() {
DisguiseConfig.setLastUpdateRequest(System.currentTimeMillis());
DisguiseConfig.saveInternalConfig();
downloading.set(true);
try {

View File

@ -5,4 +5,6 @@
Bisect-Hosted: %data%
Server-IP: %data%
# Should the plugin be doing release or dev builds updating?
ReleaseBuild: %data%
ReleaseBuild: %data%
# Make sure the plugin aint spamming update requests
LastUpdateCheck: %data%