diff --git a/src/main/java/com/songoda/core/SongodaCore.java b/src/main/java/com/songoda/core/SongodaCore.java index 2101161e..713bb1ee 100644 --- a/src/main/java/com/songoda/core/SongodaCore.java +++ b/src/main/java/com/songoda/core/SongodaCore.java @@ -46,7 +46,7 @@ public class SongodaCore { * Whenever we make a major change to the core GUI, updater, * or other function used by the core, increment this number */ - private final static int coreRevision = 3; + private final static int coreRevision = 4; private final static int updaterVersion = 1; private final static Set registeredPlugins = new HashSet<>(); diff --git a/src/main/java/com/songoda/core/core/LocaleModule.java b/src/main/java/com/songoda/core/core/LocaleModule.java index f2bb20a9..8d8a5908 100644 --- a/src/main/java/com/songoda/core/core/LocaleModule.java +++ b/src/main/java/com/songoda/core/core/LocaleModule.java @@ -1,6 +1,5 @@ package com.songoda.core.core; -import com.songoda.core.core.PluginInfoModule; import com.songoda.core.locale.Locale; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -35,8 +34,24 @@ public class LocaleModule implements PluginInfoModule { HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); urlConnection.setRequestProperty("Accept", "*/*"); + urlConnection.setInstanceFollowRedirects(true); urlConnection.setConnectTimeout(5000); + // do we need to follow a redirect? + int status = urlConnection.getResponseCode(); + if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER) { + // get redirect url from "location" header field + String newUrl = urlConnection.getHeaderField("Location"); + // get the cookie if needed + String cookies = urlConnection.getHeaderField("Set-Cookie"); + // open the new connnection again + urlConnection = (HttpURLConnection) new URL(newUrl).openConnection(); + urlConnection.setRequestProperty("Cookie", cookies); + urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); + urlConnection.setRequestProperty("Accept", "*/*"); + urlConnection.setConnectTimeout(5000); + } + Locale.saveLocale(plugin.getJavaPlugin(), urlConnection.getInputStream(), fileName); urlConnection.disconnect();