Hopefully delay update checks on constant restarts to still be 6 hours
This commit is contained in:
		| @@ -253,6 +253,9 @@ public class DisguiseConfig { | |||||||
|     @Getter |     @Getter | ||||||
|     @Setter |     @Setter | ||||||
|     private static boolean saveUserPreferences; |     private static boolean saveUserPreferences; | ||||||
|  |     @Getter | ||||||
|  |     @Setter | ||||||
|  |     private static long lastUpdateRequest; | ||||||
|  |  | ||||||
|     public static boolean isArmorstandsName() { |     public static boolean isArmorstandsName() { | ||||||
|         return getPlayerNameType() == PlayerNameType.ARMORSTANDS; |         return getPlayerNameType() == PlayerNameType.ARMORSTANDS; | ||||||
| @@ -311,12 +314,20 @@ public class DisguiseConfig { | |||||||
|             return; |             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() { |         updaterTask = Bukkit.getScheduler().runTaskTimerAsynchronously(LibsDisguises.getInstance(), new Runnable() { | ||||||
|             @Override |             @Override | ||||||
|             public void run() { |             public void run() { | ||||||
|                 LibsDisguises.getInstance().getUpdateChecker().doAutoUpdateCheck(); |                 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) { |     public static void setUsingReleaseBuilds(boolean useReleaseBuilds) { | ||||||
| @@ -350,6 +361,7 @@ public class DisguiseConfig { | |||||||
|         bisectHosted = configuration.getBoolean("Bisect-Hosted", isBisectHosted()); |         bisectHosted = configuration.getBoolean("Bisect-Hosted", isBisectHosted()); | ||||||
|         savedServerIp = configuration.getString("Server-IP", getSavedServerIp()); |         savedServerIp = configuration.getString("Server-IP", getSavedServerIp()); | ||||||
|         usingReleaseBuild = configuration.getBoolean("ReleaseBuild", isUsingReleaseBuild()); |         usingReleaseBuild = configuration.getBoolean("ReleaseBuild", isUsingReleaseBuild()); | ||||||
|  |         lastUpdateRequest = configuration.getLong("LastUpdateRequest", 0L); | ||||||
|  |  | ||||||
|         if (!configuration.contains("Bisect-Hosted") || !configuration.contains("Server-IP") || |         if (!configuration.contains("Bisect-Hosted") || !configuration.contains("Server-IP") || | ||||||
|                 !configuration.contains("ReleaseBuild")) { |                 !configuration.contains("ReleaseBuild")) { | ||||||
| @@ -364,7 +376,8 @@ public class DisguiseConfig { | |||||||
|                 .getResourceAsString(LibsDisguises.getInstance().getFile(), "internal.yml"); |                 .getResourceAsString(LibsDisguises.getInstance().getFile(), "internal.yml"); | ||||||
|  |  | ||||||
|         // Bisect hosted, server ip, release builds |         // 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); |             internalConfig = internalConfig.replaceFirst("%data%", "" + s); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -156,6 +156,9 @@ public class UpdateChecker { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public LibsMsg doUpdateCheck() { |     public LibsMsg doUpdateCheck() { | ||||||
|  |         DisguiseConfig.setLastUpdateRequest(System.currentTimeMillis()); | ||||||
|  |         DisguiseConfig.saveInternalConfig(); | ||||||
|  |  | ||||||
|         downloading.set(true); |         downloading.set(true); | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|   | |||||||
| @@ -5,4 +5,6 @@ | |||||||
| Bisect-Hosted: %data% | Bisect-Hosted: %data% | ||||||
| Server-IP: %data% | Server-IP: %data% | ||||||
| # Should the plugin be doing release or dev builds updating? | # Should the plugin be doing release or dev builds updating? | ||||||
| ReleaseBuild: %data% | ReleaseBuild: %data% | ||||||
|  | # Make sure the plugin aint spamming update requests | ||||||
|  | LastUpdateCheck: %data% | ||||||
		Reference in New Issue
	
	Block a user