From 66dc27483b18a7ca0417a00699da35195c384fab Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Wed, 10 May 2023 21:07:36 +0200 Subject: [PATCH 1/2] new UpdateCheck option Added an option to completely disable the UpdateCheck of all plugins that check via the T2CodeLib --- .../BUNGEE/api/update/T2CBupdateAPI.java | 2 ++ .../api/update/T2CBupdateCheckerGit.java | 2 ++ .../BUNGEE/system/config/T2CBlibConfig.java | 30 +++++++------------ .../SPIGOT/api/update/T2CupdateAPI.java | 2 ++ .../api/update/T2CupdateCheckerGit.java | 3 ++ .../system/config/config/ConfigCreate.java | 2 ++ .../system/config/config/SelectLibConfig.java | 3 ++ 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java index 47dccf1..64f6710 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java @@ -5,6 +5,7 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.plugin.Plugin; import net.t2code.t2codelib.BUNGEE.api.messages.T2CBsend; import net.t2code.t2codelib.BUNGEE.system.config.T2CBlibConfig; +import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.T2CupdateWebData; import net.t2code.t2codelib.UpdateType; @@ -50,6 +51,7 @@ public class T2CBupdateAPI { public static void onUpdateCheckTimer(Plugin plugin, String prefix, String discord, Integer spigotID, String url) { ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() { public void run() { + if (T2CBlibConfig.getUpdateCheckFullDisable()) return; (new T2CBupdateCheckerGit(plugin, spigotID)).getVersion((webData) -> { pluginVersion = plugin.getDescription().getVersion(); T2CupdateObject update = new T2CupdateObject( diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java index c471712..d1d83d9 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java @@ -3,6 +3,7 @@ package net.t2code.t2codelib.BUNGEE.api.update; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.plugin.Plugin; import net.t2code.t2codelib.BUNGEE.system.config.T2CBlibConfig; +import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.T2CupdateWebData; import org.json.JSONArray; @@ -26,6 +27,7 @@ public class T2CBupdateCheckerGit { } public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String gitKey) { + if (T2CBlibConfig.getUpdateCheckFullDisable()) return; String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1"; if (!T2CBlibConfig.getSeePreReleaseUpdates()) { RepoURL = RepoURL + "&pre-release=false"; diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java index 1ee83fd..87c0643 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java @@ -1,5 +1,6 @@ package net.t2code.t2codelib.BUNGEE.system.config; +import lombok.Getter; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.YamlConfiguration; @@ -22,6 +23,8 @@ public class T2CBlibConfig { } Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); T2CBconfig.set("UpdateCheck.TimerInMin", 60, configuration); + T2CBconfig.set("UpdateCheck.SeePreReleaseUpdates", true, configuration); + T2CBconfig.set("Plugin.UpdateCheck.AllPlugins.FullDisable", false, configuration); T2CBconfig.set("API.CommandGUI.Enable", false, configuration); T2CBconfig.set("API.AutoResponse.Enable", false, configuration); @@ -37,35 +40,24 @@ public class T2CBlibConfig { updateTimer = configuration.getInt("UpdateCheck.TimerInMin"); seePreReleaseUpdates = configuration.getBoolean("UpdateCheck.SeePreReleaseUpdates"); + updateCheckFullDisable = configuration.getBoolean("Plugin.UpdateCheck.AllPlugins.FullDisable"); apiCommandGUIEnable = configuration.getBoolean("API.CommandGUI.Enable"); apiAutoResponse = configuration.getBoolean("API.AutoResponse.Enable"); apiOpSecurity = configuration.getBoolean("API.OPSecurity.Enable"); } + @Getter private static Integer updateTimer; + @Getter private static Boolean seePreReleaseUpdates; + @Getter + private static Boolean updateCheckFullDisable; + @Getter private static Boolean apiCommandGUIEnable; + @Getter private static Boolean apiAutoResponse; + @Getter private static Boolean apiOpSecurity; - public static Integer getUpdateTimer() { - return updateTimer; - } - - public static Boolean getSeePreReleaseUpdates() { - return seePreReleaseUpdates; - } - - public static Boolean getApiCommandGUIEnable() { - return apiCommandGUIEnable; - } - - public static Boolean getApiAutoResponse() { - return apiAutoResponse; - } - - public static Boolean getApiOpSecurity() { - return apiOpSecurity; - } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java index ac04b09..ee0c7d3 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java @@ -2,6 +2,7 @@ package net.t2code.t2codelib.SPIGOT.api.update; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; +import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.UpdateType; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.T2CupdateWebData; @@ -180,6 +181,7 @@ public class T2CupdateAPI { } public static void onUpdateCheck(Plugin plugin, String prefix, String gitKey, Integer spigotID, String discord, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) { + if (SelectLibConfig.getUpdateCheckFullDisable()) return; new T2CupdateCheckerGit((JavaPlugin) plugin, prefix, gitKey, spigotID, discord, updateCheckOnJoin, seePreReleaseUpdates, timeInterval); } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java index 7ed87e5..6af3098 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java @@ -1,6 +1,8 @@ package net.t2code.t2codelib.SPIGOT.api.update; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; +import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; +import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.T2CupdateWebData; import org.bukkit.Bukkit; @@ -38,6 +40,7 @@ public class T2CupdateCheckerGit { Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { @Override public void run() { + if (SelectLibConfig.getUpdateCheckFullDisable()) return; getVersion((webData) -> { T2CupdateObject update = new T2CupdateObject( plugin.getName(), diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java index 5abb50e..37f677a 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java @@ -22,9 +22,11 @@ public class ConfigCreate { File config = new File(T2CodeLibMain.getPath(), "config.yml"); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); + T2Cconfig.set("Plugin.UpdateCheck.OnJoin", true, yamlConfiguration); T2Cconfig.set("Plugin.UpdateCheck.TimeInterval", 60, yamlConfiguration); T2Cconfig.set("Plugin.UpdateCheck.SeePreReleaseUpdates", true, yamlConfiguration); + T2Cconfig.set("Plugin.UpdateCheck.AllPlugins.FullDisable", false, yamlConfiguration); T2Cconfig.set("Plugin.language", "english", yamlConfiguration); T2Cconfig.set("BungeeCord.Enable", T2CodeLibMain.getIsBungee(), yamlConfiguration); diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java index 9da1842..6b2c641 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java @@ -17,6 +17,8 @@ public class SelectLibConfig { @Getter private static Boolean seePreReleaseUpdates; @Getter + private static Boolean updateCheckFullDisable; + @Getter private static Boolean debug; @Getter private static String language; @@ -36,6 +38,7 @@ public class SelectLibConfig { updateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheck.OnJoin"); updateCheckTimeInterval = yamlConfiguration.getInt("Plugin.UpdateCheck.TimeInterval"); seePreReleaseUpdates = yamlConfiguration.getBoolean("Plugin.UpdateCheck.SeePreReleaseUpdates"); + updateCheckFullDisable = yamlConfiguration.getBoolean("Plugin.UpdateCheck.AllPlugins.FullDisable"); debug = yamlConfiguration.getBoolean("Plugin.Debug"); language = yamlConfiguration.getString("Plugin.language"); bungee = yamlConfiguration.getBoolean("BungeeCord.Enable"); -- 2.34.1 From 709bd16317a6d404ba57efbfe89f4e4fff9d12ba Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Wed, 10 May 2023 21:09:27 +0200 Subject: [PATCH 2/2] [Bungee] Fixed a small performance bug: If the update check interval was set to 0, it could crash the server and cause spam in the console both to the update check server of T2Code. --- .../t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java | 6 +++++- .../t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java index 64f6710..c9450d0 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java @@ -49,6 +49,10 @@ public class T2CBupdateAPI { private static String pluginVersion; public static void onUpdateCheckTimer(Plugin plugin, String prefix, String discord, Integer spigotID, String url) { + Integer finalInterval; + if (T2CBlibConfig.getUpdateTimer() < 1){ + finalInterval = 1; + } else finalInterval = T2CBlibConfig.getUpdateTimer(); ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() { public void run() { if (T2CBlibConfig.getUpdateCheckFullDisable()) return; @@ -74,6 +78,6 @@ public class T2CBupdateAPI { } }, pluginVersion, spigotID, url); } - }, 0, T2CBlibConfig.getUpdateTimer() * 60 * 20L, TimeUnit.SECONDS); + }, 0, finalInterval * 60 * 20L, TimeUnit.SECONDS); } } diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java index d1d83d9..e03825d 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java @@ -3,7 +3,6 @@ package net.t2code.t2codelib.BUNGEE.api.update; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.plugin.Plugin; import net.t2code.t2codelib.BUNGEE.system.config.T2CBlibConfig; -import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.T2CupdateWebData; import org.json.JSONArray; -- 2.34.1