package net.t2code.t2codelib.BUNGEE.api.update; import net.md_5.bungee.api.CommandSender; 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; import java.util.HashMap; import java.util.concurrent.TimeUnit; public class T2CBupdateAPI { public static HashMap bungeePluginVersins = new HashMap<>(); public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin, CommandSender sender) { String publicVersion = webData.getVersion(); String pluginVersion = plugin.getDescription().getVersion(); String value; if (webData.isPreRelease()) { value = UpdateType.PRERELEASE.text; if (publicVersion.toLowerCase().contains("dev")) { value = UpdateType.DEVELOPMENT.text; } if (publicVersion.toLowerCase().contains("beta")) { value = UpdateType.BETA.text; } if (publicVersion.toLowerCase().contains("snapshot")) { value = UpdateType.SNAPSHOT.text; } } else value = UpdateType.STABLE.text; String h = "
╔══════════════" + prefix + "══════════════"; String s1 = "
A new [value] version was found!".replace("[value]", value); String s2 = "
Your version: " + pluginVersion + " - Current version: " + webData.getVersion() + ""; String s3 = "
You can download it here: " + webData.getUpdateUrl() + ""; String s4 = "
You can find more information on Discord: " + discord + ""; String f = "
╚══════════════" + prefix + "══════════════"; String text = h + s1 + s2 + s3 + s4 + f; if (sender == null) { T2CBsend.console(text); } else T2CBsend.sender(sender, text); } private static Boolean noUpdate = true; private static String pluginVersion; 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( plugin.getDescription().getName(), plugin.getDescription().getVersion(), webData, false, !plugin.getDescription().getVersion().equals(webData.getVersion()), true ); bungeePluginVersins.put(plugin.getDescription().getName(), update); if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(webData.getVersion())) { sendUpdateMsg(prefix, discord, webData, plugin, null); noUpdate = true; } else { if (noUpdate) { T2CBsend.console(prefix + " §2No update found."); noUpdate = false; } } }, pluginVersion, spigotID, url); } }, 0, T2CBlibConfig.getUpdateTimer() * 60 * 20L, TimeUnit.SECONDS); } }