From 45331de38c4acd191cfab1601c3ab5c8ca46c19a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 7 Jul 2020 12:03:46 +1200 Subject: [PATCH] Hopefully delay update checks on constant restarts to still be 6 hours --- .../libraryaddict/disguise/DisguiseConfig.java | 17 +++++++++++++++-- .../utilities/updates/UpdateChecker.java | 3 +++ src/main/resources/internal.yml | 4 +++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index c9fade9c..66d853d6 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -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); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java b/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java index cd1c738c..5096e1cd 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java @@ -156,6 +156,9 @@ public class UpdateChecker { } public LibsMsg doUpdateCheck() { + DisguiseConfig.setLastUpdateRequest(System.currentTimeMillis()); + DisguiseConfig.saveInternalConfig(); + downloading.set(true); try { diff --git a/src/main/resources/internal.yml b/src/main/resources/internal.yml index e6e97553..612ad827 100644 --- a/src/main/resources/internal.yml +++ b/src/main/resources/internal.yml @@ -5,4 +5,6 @@ Bisect-Hosted: %data% Server-IP: %data% # Should the plugin be doing release or dev builds updating? -ReleaseBuild: %data% \ No newline at end of file +ReleaseBuild: %data% +# Make sure the plugin aint spamming update requests +LastUpdateCheck: %data% \ No newline at end of file