package ot.utils;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import ot.OpenTechnology;

import java.io.InputStream;
import java.net.URL;

/**
 * Created by Avaja on 28.12.2016.
 */
public class CheckVersion {

    public static void check(EntityPlayer player) {
        try{
            String latestVersion = getLatestVersion();
            if(latestVersion != null){
                latestVersion = latestVersion.replace("\n", "");
                if(!latestVersion.equals(OpenTechnology.VERSION)){
                    player.addChatComponentMessage(new ChatComponentText(String.format("§aOpenTechnology§f: A newer version is available: %s", latestVersion)));
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private static String getLatestVersion(){
        try{
            InputStream in = new URL("https://raw.githubusercontent.com/Avaja/OpenTechnology/master/LATEST_VERSION").openStream();

            byte[] buff = new byte[in.available()];
            in.read(buff);

            return new String(buff, "UTF-8");
        }catch (Exception e){
            return null;
        }
    }
}

@@ -133,16 +133,88 @@
 ology;%0A%0A
+import javax.net.ssl.HttpsURLConnection;%0Aimport java.io.BufferedReader;%0A
 import j
@@ -231,16 +231,22 @@
 utStream
+Reader
 ;%0Aimport
@@ -259,16 +259,80 @@
 net.URL;
+%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;
 %0A%0A/**%0A *
@@ -1010,32 +1010,33 @@
 n()%7B%0A        try
+ 
 %7B%0A            In
@@ -1037,24 +1037,60 @@
     
-InputStream in =
+HttpsURLConnection connection = (HttpsURLConnection)
  new
@@ -1107,29 +1107,14 @@
 s://
-raw.
 github
-usercontent
 .com
@@ -1139,171 +1139,661 @@
 ogy/
-master/LATEST_VERSION%22).openStream();%0A%0A            byte%5B%5D buff = new byte%5Bin.available()%5D;%0A            in.read(buff);%0A%0A            return new String(buff, %22UTF-8%22)
+releases%22).openConnection();%0A            connection.setRequestMethod(%22GET%22);%0A            connection.setDoInput(true);%0A            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));%0A%0A            String input;%0A            String all = %22%22;%0A            while ((input = br.readLine()) != null)%7B%0A                all += input;%0A            %7D%0A            br.close();%0A            Pattern pattern = Pattern.compile(%22latest-build%5C%5C((.+?)%5C%5C)%22);%0A            Matcher matcher = pattern.matcher(all);%0A            if(matcher.find())%7B%0A                return matcher.group(1);%0A            %7D%0A            return OpenTechnology.VERSION
 ;%0A  
@@ -1791,32 +1791,33 @@
 RSION;%0A        %7D
+ 
 catch (Exception
@@ -1811,32 +1811,33 @@
 ch (Exception e)
+ 
 %7B%0A            re
@@ -1838,30 +1838,77 @@
     
-return null;%0A        %7D
+e.printStackTrace();%0A        %7D%0A        return OpenTechnology.VERSION;
 %0A   

change CheckVersion