diff --git a/src/main/java/vic/mod/integratedcircuits/IntegratedCircuits.java b/src/main/java/vic/mod/integratedcircuits/IntegratedCircuits.java index 7fd67af..7aab9bb 100644 --- a/src/main/java/vic/mod/integratedcircuits/IntegratedCircuits.java +++ b/src/main/java/vic/mod/integratedcircuits/IntegratedCircuits.java @@ -1,15 +1,14 @@ package vic.mod.integratedcircuits; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; import java.net.URL; +import java.nio.charset.Charset; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.impl.client.BasicResponseHandler; -import org.apache.http.impl.client.HttpClientBuilder; import org.apache.logging.log4j.Logger; import vic.mod.integratedcircuits.compat.BPRedstoneProvider; @@ -171,14 +170,27 @@ public void postInit(FMLPostInitializationEvent event) @Override public void run() { + //I would have done it with commons, but it doesn't let me. So this is pretty much copied from AW + //https://github.com/RiskyKen/Armourers-Workshop try { - HttpClient client = HttpClientBuilder.create().build(); - HttpUriRequest request = new HttpGet(new URL("http://bit.ly/1GIaUA6").toURI()); - request.setHeader("Referer", "http://" + Constants.MOD_VERSION); - request.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"); - String newestVersion = client.execute(request, new BasicResponseHandler()); + String location = "http://bit.ly/1GIaUA6"; + HttpURLConnection conn = null; + while(location != null && !location.isEmpty()) { + URL url = new URL(location); + if(conn != null) conn.disconnect(); + + conn = (HttpURLConnection) url.openConnection(); + conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"); + conn.setRequestProperty("Referer", "http://" + Constants.MOD_VERSION); + conn.connect(); + location = conn.getHeaderField("Location"); + } + + if(conn == null) throw new NullPointerException(); + String newestVersion = new BufferedReader(new InputStreamReader(conn.getInputStream(), Charset.forName("UTF-8"))).readLine(); // TODO version checker? I don't really like them but we have the information now... logger.info("Your version: {}, Newest version: {}", Constants.MOD_VERSION, newestVersion); + conn.disconnect(); } catch (Exception e) { e.printStackTrace(); }