SkyeDarkhawk

Updates for version checking.

May 9th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. Main.java - Addition
  2.     public static int onlineVersion;
  3.    
  4.    
  5.     public static void main(String[] args) throws IOException {
  6.     String str = "";
  7.         String readText ="0";
  8.         try {
  9.     // Create a URL for the desired page
  10.     URL url = new URL("http://dl.canarymod.net:80/version.txt");
  11.  
  12.     // Read all the text returned by the server
  13.     BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  14.     while ((str = in.readLine()) != null) {
  15.         onlineVersion = Integer.parseInt(str);
  16.     }
  17.     in.close();
  18. } catch (MalformedURLException e) {
  19. } catch (IOException e) {
  20. }
  21.         if (etc.getInstance().getVersion() == Integer.parseInt(readText))
  22.             log("Thank you for running the latest version of Canary");
  23.         else
  24.             log("There is an updated version of Canary available at:\nhttp://dl.canarymod.net/get.php?v=latest");
  25.  
  26.  
  27. Player.java - Addition/Modification @End of /mspawn
  28. } else if (cmd.equals("/update")){
  29.                 if (Main.onlineVersion == etc.getInstance().getVersion())
  30.                     sendMessage(Colors.Rose + "You have the latest version of Canary.");
  31.                 else
  32.                     sendMessage(Colors.Rose + "You need to update your version of Canary.");
  33.  
  34.  
  35. ServerConsoleCommands.java - Modified
  36. public final static BaseCommand version       = new BaseCommand("- Displays the server version and checks for updates") {
  37.                                                       @Override
  38.                                                       void execute(MessageReceiver caller, String[] parameters) {
  39.                                                           if (!etc.getInstance().getTainted())
  40.                                                               caller.notify(Colors.Gold + "Canary Server Mod Build " + etc.getInstance().getVersion());
  41.                                                           else
  42.                                                               caller.notify(Colors.Gold + "Unofficial CanaryMod Build " + etc.getInstance().getVersionStr());
  43.                                                           if (Main.onlineVersion == etc.getInstance().getVersion())
  44.                                                               caller.notify(Colors.Gold + "Your have the latest version of Canary.");
  45.                                                           else
  46.                                                               caller.notify(Colors.Rose + "You need to update your version of Canary.");
  47.                                                       }
  48.                                                   };
Advertisement
Add Comment
Please, Sign In to add comment