From d581f48cd1c2f17afbd50771163bfa534d7ce2b6 Mon Sep 17 00:00:00 2001 From: k-jiang Date: Sun, 28 Jan 2018 09:24:30 -0500 Subject: [PATCH] Detect and update the old config.yml. Fixes #1783. (#1784) --- EssentialsGeoIP/pom.xml | 6 +++--- .../geoip/EssentialsGeoIPPlayerListener.java | 20 +++++++++++++------ EssentialsGeoIP/src/config.yml | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/EssentialsGeoIP/pom.xml b/EssentialsGeoIP/pom.xml index b73254602..bd818fc82 100644 --- a/EssentialsGeoIP/pom.xml +++ b/EssentialsGeoIP/pom.xml @@ -25,10 +25,10 @@ - + net.ess3 - EssentialsX - ${project.version} + EssentialsX + ${project.version} com.maxmind.geoip2 diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index e905bd90b..324a1a06b 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -72,7 +72,7 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf { String city; String region; String country; - if (config.getBoolean("enable-locale", true)) { + if (config.getBoolean("enable-locale")) { // Get geolocation based on locale. If not avaliable in specific language, get the default one. city = ((city=response.getCity().getNames().get(locale))!=null) ? city : response.getCity().getName(); region = ((region=response.getMostSpecificSubdivision().getNames().get(locale))!=null) ? region : response.getMostSpecificSubdivision().getName(); @@ -98,11 +98,9 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf { // GeoIP2 API forced this when address not found in their DB. jar will not complied without this. // TODO: Maybe, we can set a new custom msg about addr-not-found in messages.properties. logger.log(Level.INFO, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage()); - //logger.log(Level.INFO, tl("cantReadGeoIpDB") + " " + ex.getMessage()); } catch (IOException | GeoIp2Exception ex) { // GeoIP2 API forced this when address not found in their DB. jar will not complied without this. logger.log(Level.SEVERE, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage()); - //logger.log(Level.SEVERE, tl("cantReadGeoIpDB") + " " + ex.getMessage()); } if (config.getBoolean("show-on-whois", true)) { u.setGeoLocation(sb.toString()); @@ -121,10 +119,20 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf { public final void reloadConfig() { config.load(); + // detect and update the old config.yml. migrate from legacy GeoIP to GeoIP2. + if (!config.isSet("enable-locale")) { + config.set("database.download-url", "http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz"); + config.set("database.download-url-city", "http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz"); + config.set("database.update.enable", true); + config.set("database.update.by-every-x-days", 30); + config.set("enable-locale", true); + config.save(); + } + if (config.getBoolean("database.show-cities", false)) { - databaseFile = new File(dataFolder, "Geo2-City.mmdb"); + databaseFile = new File(dataFolder, "GeoIP2-City.mmdb"); } else { - databaseFile = new File(dataFolder, "Geo2-Country.mmdb"); + databaseFile = new File(dataFolder, "GeoIP2-Country.mmdb"); } if (!databaseFile.exists()) { if (config.getBoolean("database.download-if-missing", true)) { @@ -136,7 +144,7 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf { } else if (config.getBoolean("database.update.enable", true)) { // try to update expired mmdb files long diff = new Date().getTime() - databaseFile.lastModified(); - if (diff/24/3600/1000>config.getLong("database.update.by-every-x-days")) { + if (diff/24/3600/1000>config.getLong("database.update.by-every-x-days", 30)) { downloadDatabase(); } } diff --git a/EssentialsGeoIP/src/config.yml b/EssentialsGeoIP/src/config.yml index b52629a28..5490adcf7 100644 --- a/EssentialsGeoIP/src/config.yml +++ b/EssentialsGeoIP/src/config.yml @@ -10,6 +10,6 @@ database: by-every-x-days: 30 show-on-login: true show-on-whois: true -# Enable locale on geolocation display. Not all languages are supported. +# "enable-locale" enables locale on geolocation display. Not all languages are supported. # Check your Essentials/config.yml "locale" section for details. enable-locale: true \ No newline at end of file