Last active
December 7, 2021 04:17
-
-
Save VitorBlog/48ec363d9158a21b4ea603d370d89a5c to your computer and use it in GitHub Desktop.
UpdateChecker usando Github. Coloque o titulo da release igual a versão da plugin.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void checkUpdate(){ | |
String version = this.getDescription().getVersion(); | |
try { | |
//Abrindo conexão | |
URL url = new URL("https://api.github.com/repos/User/Repositório/releases/latest"); | |
URLConnection connection = url.openConnection(); | |
//Convertendo dados | |
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |
String response = reader.lines().collect(Collectors.joining("\n")); | |
//Lendo dados | |
JSONObject jsonObject = (JSONObject) new JSONParser().parse(response); | |
String latestVersion = (String) jsonObject.get("tag_name"); | |
if (!version.equals(latestVersion)){ | |
System.out.println("Uma nova versão esta disponível"); | |
} | |
} catch (Exception e) { | |
System.out.println("Não foi possível verificar atualizações"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tinha feito na correria e esqueci de arrumar.