Skip to content

Instantly share code, notes, and snippets.

@VitorBlog
Last active December 7, 2021 04:17
Show Gist options
  • Save VitorBlog/48ec363d9158a21b4ea603d370d89a5c to your computer and use it in GitHub Desktop.
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
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");
}
}
Copy link

ghost commented Nov 3, 2019

Por que usar != se estás comparando Strings?

@VitorBlog
Copy link
Author

Por que usar != se estás comparando Strings?

Tinha feito na correria e esqueci de arrumar.

  • Código atualizado;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment