Advertisement
Guest User

Untitled

a guest
May 29th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.cloudcraftgaming.bettermessages; //change this to your package name.
  2.  
  3. import java.io.InputStream;
  4. import java.net.MalformedURLException;
  5. import java.net.URL;
  6.  
  7. import javax.xml.parsers.DocumentBuilderFactory;
  8.  
  9. import org.w3c.dom.Document;
  10. import org.w3c.dom.Node;
  11. import org.w3c.dom.NodeList;
  12.  
  13. public class UpdateChecker
  14. {
  15.   private Main plugin;
  16.   private URL filesFeed;
  17.   private String version;
  18.   private String link;
  19.  
  20.   public UpdateChecker(Main plugin, String url)
  21.   {
  22.     this.plugin = plugin;
  23.     try
  24.     {
  25.       this.filesFeed = new URL(url);
  26.     }
  27.     catch (MalformedURLException e)
  28.     {
  29.       e.printStackTrace();
  30.     }
  31.   }
  32.  
  33. public boolean UpdateNeeded()
  34.   {
  35.     try
  36.     {
  37.       InputStream input = this.filesFeed.openConnection().getInputStream();
  38.       Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input);
  39.       Node latestFile = document.getElementsByTagName("item").item(0);
  40.       NodeList children = latestFile.getChildNodes();
  41.       this.version = children.item(1).getTextContent().replaceAll("[a-zA-z ]", "");
  42.       this.link = children.item(3).getTextContent();
  43.       if (!this.plugin.getDescription().getVersion().equals(this.version)) {
  44.         return true;
  45.       }
  46.     }
  47.     catch (Exception e)
  48.     {
  49.       e.printStackTrace();
  50.     }
  51.     return false;
  52.   }
  53.  
  54.   public String getVersion()
  55.   {
  56.     return this.version;
  57.   }
  58.  
  59.   public String getLink()
  60.   {
  61.     return this.link;
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement