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; import net.t2code.t2codelib.Util; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; public class T2CupdateAPI { public static HashMap pluginVersions = new HashMap<>(); public static void join(Plugin plugin, String prefix, String perm, Player player, Integer spigotID, String discord) { if (pluginVersions.get(plugin.getName()) == null) { Bukkit.getScheduler().runTaskLaterAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() { @Override public void run() { join(plugin, prefix, perm, player, spigotID, discord); } }, 2 * 20L); return; } if (!pluginVersions.get(plugin.getName()).updateCheckOnJoin) { return; } if (!player.hasPermission(perm) && !player.isOp()) { return; } if (pluginVersions.get(plugin.getName()) == null) { new BukkitRunnable() { @Override public void run() { join(plugin, prefix, perm, player, spigotID, discord); } }.runTaskLaterAsynchronously(plugin, 20L); return; } T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData; if (!pluginVersions.get(plugin.getName()).updateAvailable) return; new BukkitRunnable() { @Override public void run() { sendUpdateMsg(prefix, webData, discord, plugin, player); } }.runTaskLaterAsynchronously(T2CodeLibMain.getPlugin(), 200L); } public static void sendUpdateMsg(String prefix, T2CupdateWebData webData, String discord, Plugin plugin, Player player) { String publicVersion = webData.getVersion(); String pluginVersion = plugin.getDescription().getVersion(); if (!pluginVersions.get(plugin.getName()).updateAvailable) { return; } String st = "[prefix]
" + "You can download it here: [link]'>[prefix] A new [value] version was" + " found!
" + "You can download it here: [link]'>[prefix] [plv] -> " + "[puv]
" + "[dc]'>[prefix] You can find more information on Discord.
" + "[prefix] Click for more information'>Update information
" + "[prefix]"; String updateStatusVersion; if (webData.isPreRelease()) { //todo if (!SelectLibConfig.getSeePreReleaseUpdates()) return; updateStatusVersion = UpdateType.PRERELEASE.text; if (publicVersion.toLowerCase().contains("dev")) { updateStatusVersion = UpdateType.DEVELOPMENT.text; } if (publicVersion.toLowerCase().contains("beta")) { updateStatusVersion = UpdateType.BETA.text; } if (publicVersion.toLowerCase().contains("snapshot")) { updateStatusVersion = UpdateType.SNAPSHOT.text; } } else updateStatusVersion = UpdateType.STABLE.text; T2Csend.player(player, st.replace("[prefix]", prefix).replace("[value]", updateStatusVersion).replace("[link]", webData.getUpdateUrl()) .replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord)); } public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin) { String publicVersion = webData.getVersion(); String pluginVersion = plugin.getDescription().getVersion(); String updateStatusVersion; if (webData.isPreRelease()) { updateStatusVersion = UpdateType.PRERELEASE.text; if (publicVersion.toLowerCase().contains("dev")) { updateStatusVersion = UpdateType.DEVELOPMENT.text; } if (publicVersion.toLowerCase().contains("beta")) { updateStatusVersion = UpdateType.BETA.text; } if (publicVersion.toLowerCase().contains("snapshot")) { updateStatusVersion = UpdateType.SNAPSHOT.text; } } else updateStatusVersion = UpdateType.STABLE.text; String h = "
╔══════════════" + prefix + "══════════════"; String s1 = "
A new [value] version was found!".replace("[value]", updateStatusVersion); 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; T2Csend.console(text); } public static String updateInfo(String[] args, Boolean player) { T2CupdateObject object; try { object = T2CupdateAPI.pluginVersions.get(args[1]); } catch (Exception e) { return Util.getPrefix() + " The plugin " + args[1] + " is not registered in the update checker of T2Code!"; } if (object == null) return Util.getPrefix() + " The plugin " + args[1] + " is not registered in the update checker of T2Code!"; T2CupdateWebData webData = object.webData; if (webData == null) { return Util.getPrefix() + " It could not be checked for updates with the plugin " + args[1] + "!"; } String pluginName = T2CupdateAPI.pluginVersions.get(args[1]).pluginName; String pluginVersion = T2CupdateAPI.pluginVersions.get(args[1]).pluginVersion; String updateTitle = webData.getUpdateTitle(); String updateVersion = webData.getVersion(); String updateType; if (webData.isPreRelease()) { updateType = UpdateType.PRERELEASE.text; if (updateVersion.toLowerCase().contains("dev")) { updateType = UpdateType.DEVELOPMENT.text; } if (updateVersion.toLowerCase().contains("beta")) { updateType = UpdateType.BETA.text; } if (updateVersion.toLowerCase().contains("snapshot")) { updateType = UpdateType.SNAPSHOT.text; } } else updateType = UpdateType.STABLE.text; String updateAt = webData.getPublishedAt(); String updateUpdate = webData.getUpdateUrl(); String updateDescription = webData.getUpdateDescription(); String pluginNameString = "
Plugin: " + pluginName + ""; String pluginVersionString = "
Your version: " + pluginVersion + ""; String updateInfoString = "
[value]:"; String updateTitleString = "
Title: " + updateTitle + ""; String updateVersionString = "
Version: " + updateVersion + ""; String updateAtString = "
Published on: " + updateAt + ""; String updateTypeString = "
Version type: " + updateType + ""; String updateButton; if (player) { updateButton = "
" + updateUpdate + "'>Download | Update Description"; } else updateButton = "
Download: " + updateUpdate + ""; String text; text = "
╔══════════════════════"; text = text + pluginNameString; text = text + pluginVersionString; text = text + updateInfoString.replace("[value]", object.updateAvailable ? "Update available" : "Info about your version"); if (!updateTitle.equals("OLD")) text = text + updateTitleString; if (object.updateAvailable) text = text + updateVersionString; if (!updateTitle.equals("OLD")) text = text + updateAtString; if (!updateTitle.equals("OLD")) text = text + updateTypeString; text = text + updateButton; if (updateTitle.equals("OLD")) text = text + "
This plugin does not have the new update checker yet, so there is no exact update / " + "version information available!"; text = text + "
╚══════════════════════"; return text; } 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); } }