mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 11:49:12 +00:00
parent
752565b8f1
commit
d581f48cd1
3 changed files with 18 additions and 10 deletions
|
@ -72,7 +72,7 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf {
|
||||||
String city;
|
String city;
|
||||||
String region;
|
String region;
|
||||||
String country;
|
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.
|
// 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();
|
city = ((city=response.getCity().getNames().get(locale))!=null) ? city : response.getCity().getName();
|
||||||
region = ((region=response.getMostSpecificSubdivision().getNames().get(locale))!=null) ? region : response.getMostSpecificSubdivision().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.
|
// 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.
|
// 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.getLocalizedMessage());
|
||||||
//logger.log(Level.INFO, tl("cantReadGeoIpDB") + " " + ex.getMessage());
|
|
||||||
} catch (IOException | GeoIp2Exception ex) {
|
} catch (IOException | GeoIp2Exception ex) {
|
||||||
// GeoIP2 API forced this when address not found in their DB. jar will not complied without this.
|
// 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.getLocalizedMessage());
|
||||||
//logger.log(Level.SEVERE, tl("cantReadGeoIpDB") + " " + ex.getMessage());
|
|
||||||
}
|
}
|
||||||
if (config.getBoolean("show-on-whois", true)) {
|
if (config.getBoolean("show-on-whois", true)) {
|
||||||
u.setGeoLocation(sb.toString());
|
u.setGeoLocation(sb.toString());
|
||||||
|
@ -121,10 +119,20 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf {
|
||||||
public final void reloadConfig() {
|
public final void reloadConfig() {
|
||||||
config.load();
|
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)) {
|
if (config.getBoolean("database.show-cities", false)) {
|
||||||
databaseFile = new File(dataFolder, "Geo2-City.mmdb");
|
databaseFile = new File(dataFolder, "GeoIP2-City.mmdb");
|
||||||
} else {
|
} else {
|
||||||
databaseFile = new File(dataFolder, "Geo2-Country.mmdb");
|
databaseFile = new File(dataFolder, "GeoIP2-Country.mmdb");
|
||||||
}
|
}
|
||||||
if (!databaseFile.exists()) {
|
if (!databaseFile.exists()) {
|
||||||
if (config.getBoolean("database.download-if-missing", true)) {
|
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)) {
|
} else if (config.getBoolean("database.update.enable", true)) {
|
||||||
// try to update expired mmdb files
|
// try to update expired mmdb files
|
||||||
long diff = new Date().getTime() - databaseFile.lastModified();
|
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();
|
downloadDatabase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@ database:
|
||||||
by-every-x-days: 30
|
by-every-x-days: 30
|
||||||
show-on-login: true
|
show-on-login: true
|
||||||
show-on-whois: 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.
|
# Check your Essentials/config.yml "locale" section for details.
|
||||||
enable-locale: true
|
enable-locale: true
|
Loading…
Reference in a new issue