diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java index f59437a30..aa6e773c7 100644 --- a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java @@ -4,6 +4,7 @@ import com.maxmind.geoip.LookupService; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.settings.Settings; +import org.bukkit.Bukkit; import java.io.*; import java.net.URL; @@ -12,10 +13,12 @@ import java.util.zip.GZIPInputStream; public class GeoLiteAPI { - private static final String GEOIP_URL = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry" + + public static final String LICENSE = "[LICENSE] This product uses data from the GeoLite API created by MaxMind, " + + "available at http://www.maxmind.com"; + public static final String GEOIP_URL = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry" + "/GeoIP.dat.gz"; - private static final AuthMe plugin = AuthMe.getInstance(); private static LookupService lookupService; + private static final AuthMe plugin = AuthMe.getInstance(); /** * Download (if absent) the GeoIpLite data file and then try to load it. @@ -30,15 +33,14 @@ public class GeoLiteAPI { if (data.exists()) { try { lookupService = new LookupService(data); - plugin.getLogger().info("[LICENSE] This product uses data from the GeoLite API created by MaxMind, " + - "available at http://www.maxmind.com"); + plugin.getLogger().info(LICENSE); return true; } catch (IOException e) { return false; } } // Ok, let's try to download the data file! - plugin.getGameServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { try { diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index 9b8c90bfe..63d7ec420 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -15,15 +15,12 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; -import java.io.*; +import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLConnection; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.zip.GZIPInputStream; /** * Utility class for various operations used in the codebase. @@ -38,7 +35,6 @@ public final class Utils { static { plugin = AuthMe.getInstance(); - checkGeoIP(); initializeOnlinePlayersIsCollectionField(); } @@ -46,54 +42,6 @@ public final class Utils { // Utility class } - // Check and Download GeoIP data if it doesn't exist - public static boolean checkGeoIP() { - if (lookupService != null) { - return true; - } - final File data = new File(Settings.PLUGIN_FOLDER, "GeoIP.dat"); - if (data.exists()) { - if (lookupService == null) { - try { - lookupService = new LookupService(data); - ConsoleLogger.info("[LICENSE] This product uses data from the GeoLite API created by MaxMind, " + - "available at http://www.maxmind.com"); - return true; - } catch (IOException e) { - return false; - } - } - } - plugin.getGameServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - try { - String url = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz"; - URL downloadUrl = new URL(url); - URLConnection conn = downloadUrl.openConnection(); - conn.setConnectTimeout(10000); - conn.connect(); - InputStream input = conn.getInputStream(); - if (conn.getURL().toString().endsWith(".gz")) { - input = new GZIPInputStream(input); - } - OutputStream output = new FileOutputStream(data); - byte[] buffer = new byte[2048]; - int length = input.read(buffer); - while (length >= 0) { - output.write(buffer, 0, length); - length = input.read(buffer); - } - output.close(); - input.close(); - } catch (IOException e) { - ConsoleLogger.writeStackTrace(e); - } - } - }); - return false; - } - /** * Set the group of a player, by its AuthMe group type. *