Advertisement
Guest User

UpdateChecker

a guest
Feb 7th, 2013
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. package ;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.URL;
  7. import java.util.logging.Logger;
  8.  
  9. public class UpdateChecker {
  10.     <MAINCLASS> plugin;
  11.     public UpdateChecker(<MAINCLASS> plugin) {
  12.         this.plugin = plugin;
  13.         currentVersion = plugin.version;
  14.     }
  15.  
  16.     private String currentVersion;
  17.     private String readurl = "[url]https://raw.github.com/keybordpiano459/Newspaper/master/version.txt[/url]";
  18.  
  19.     public void startUpdateCheck() {
  20.         if (plugin.getConfig().getBoolean("update-checker")) {
  21.             Logger log = plugin.getLogger();
  22.             try {
  23.                 log.info("Checking for a new version...");
  24.                 URL url = new URL(readurl);
  25.                 BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
  26.                 String str;
  27.                 while ((str = br.readLine()) != null) {
  28.                     String line = str;
  29.                     if (line.charAt(0) == '1' && line.charAt(2) == '3') {
  30.                         plugin.updatemsg = line.substring(5);
  31.                         log.info(plugin.updatemsg);
  32.                     }
  33.                 }
  34.                 br.close();
  35.             } catch (IOException e) {
  36.                 log.severe("The UpdateChecker URL is invalid! Please let me know!");
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement