Update Checker

Discussion in 'Spigot Plugin Development' started by Scorpion, Sep 11, 2019.

  1. I never worked with update checkers so followed 1 of the wiki's on spigot.

    For 1 of my plugins i was trying to get an auto updater into it so any time i update it, it notified someone.(console or op players)

    https://hasteb.in/ozemedib.cs

    According to this thing, the link used return 1.0.0 but the reader returns nothing at all.

    Not sure what the issue is, and many update wiki's and forums i checked...are outdated or have changed a ton.
    any help is appreciated

    Doing reader alone on system out does return something, but not anything usefull
     
  2. Try using this code:

    Code (Text):

     public void updateChecker(){        
             try {
                 HttpURLConnection con = (HttpURLConnection) new URL(
                         "https://api.spigotmc.org/legacy/update.php?resource=YOURSPIGOTRESOURCEID").openConnection();
                 int timed_out = 1250;
                 con.setConnectTimeout(timed_out);
                 con.setReadTimeout(timed_out);
                 latestversion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
                 if (latestversion.length() <= 7) {
                   if(!version.equals(latestversion)){
                       Bukkit.getConsoleSender().sendMessage(ChatColor.RED +"There is a new version available. "+ChatColor.YELLOW+
                               "("+ChatColor.GRAY+latestversion+ChatColor.YELLOW+")");
                   }          
                 }
             } catch (Exception ex) {
               Bukkit.getConsoleSender().sendMessage(nombre + ChatColor.RED +"Error while checking update.");
             }
         }
     
     
  3. I wrote the update checker in the wiki.

    The hastebin link you sent does not work for me.