diff --git a/plugin.yml b/plugin.yml index 6a52a95..9274bcf 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: PluginManager author: Lenni0451 -version: 1.0 +version: 1.1 main: net.Lenni0451.SpigotPluginManager.PluginManager commands: diff --git a/src/net/Lenni0451/SpigotPluginManager/PluginManager.java b/src/net/Lenni0451/SpigotPluginManager/PluginManager.java index b1e9491..f85b088 100644 --- a/src/net/Lenni0451/SpigotPluginManager/PluginManager.java +++ b/src/net/Lenni0451/SpigotPluginManager/PluginManager.java @@ -2,11 +2,14 @@ import java.util.Arrays; +import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import net.Lenni0451.SpigotPluginManager.commands.PluginManager_Command; import net.Lenni0451.SpigotPluginManager.commands.Reload_Command; import net.Lenni0451.SpigotPluginManager.tabcomplete.PluginManager_TabComplete; +import net.Lenni0451.SpigotPluginManager.utils.DownloadUtils; +import net.Lenni0451.SpigotPluginManager.utils.Logger; import net.Lenni0451.SpigotPluginManager.utils.PluginUtils; public class PluginManager extends JavaPlugin { @@ -41,6 +44,18 @@ public void onEnable() { this.getCommand("pluginmanager").setExecutor(new PluginManager_Command()); this.getCommand("pluginmanager").setAliases(Arrays.asList("pm")); this.getCommand("pluginmanager").setTabCompleter(new PluginManager_TabComplete()); + + try { + String newestVersion = DownloadUtils.getNewestVersion(); + if(!newestVersion.equals(this.getDescription().getVersion())) { + Logger.sendPrefixMessage(Bukkit.getConsoleSender(), "A new update of PluginManager is available §e(" + this.getDescription().getVersion() + " -> " + newestVersion + ")."); + Logger.sendPrefixMessage(Bukkit.getConsoleSender(), "You can download it here: §6https://github.com/Lenni0451/SpigotPluginManager/releases/latest/download/PluginManager.jar"); + } else { + Logger.sendPrefixMessage(Bukkit.getConsoleSender(), "You are using the latest version of PluginManager."); + } + } catch (Throwable e) { + Logger.sendPrefixMessage(Bukkit.getConsoleSender(), "§cCould not check for updates."); + } } } diff --git a/src/net/Lenni0451/SpigotPluginManager/utils/DownloadUtils.java b/src/net/Lenni0451/SpigotPluginManager/utils/DownloadUtils.java index 5f5f79d..f90375a 100644 --- a/src/net/Lenni0451/SpigotPluginManager/utils/DownloadUtils.java +++ b/src/net/Lenni0451/SpigotPluginManager/utils/DownloadUtils.java @@ -110,4 +110,27 @@ public static JsonArray getSpigotMcPluginList(final int count, final int page) t return jsonParser.parse(responseBuilder.toString()).getAsJsonArray(); } + public static String getNewestVersion() throws IOException { + //https://github.com/Lenni0451/SpigotPluginManager/releases/tag/1.0 + URL url = new URL("https://github.com/Lenni0451/SpigotPluginManager/releases/latest"); + HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.setRequestProperty("user-agent", PluginManager.getInstance().getConfig().getString("UserAgent")); + + BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); + StringBuilder responseBuilder = new StringBuilder(); + String line; + while((line = br.readLine()) != null) { + responseBuilder.append(line); + } + br.close(); + + String urlBase = "https://github.com/Lenni0451/SpigotPluginManager/releases/tag/"; + String source = responseBuilder.toString(); + String version = source.substring(source.indexOf(urlBase) + urlBase.length()); + version = version.substring(0, version.indexOf("&")); + + return version; + } + }