diff --git a/docs/config.md b/docs/config.md index dfe816b87..1c86eaf70 100644 --- a/docs/config.md +++ b/docs/config.md @@ -403,6 +403,8 @@ Protection: # Apply the protection also to registered usernames enableProtectionRegistered: true geoIpDatabase: + # Enable GeoIp database + enabled: true # The MaxMind clientId used to download the GeoIp database, # get one at https://www.maxmind.com/en/accounts/current/license-key # The EssentialsX project has a very useful tutorial on how to generate diff --git a/src/main/java/fr/xephi/authme/service/GeoIpService.java b/src/main/java/fr/xephi/authme/service/GeoIpService.java index d2e7324fe..40c3aa1e9 100644 --- a/src/main/java/fr/xephi/authme/service/GeoIpService.java +++ b/src/main/java/fr/xephi/authme/service/GeoIpService.java @@ -64,6 +64,8 @@ public class GeoIpService { private GeoIp2Provider databaseReader; private volatile boolean downloading; + private boolean enabled = true; + @Inject GeoIpService(@DataFolder File dataFolder, BukkitService bukkitService, Settings settings) { this.bukkitService = bukkitService; @@ -89,6 +91,13 @@ public class GeoIpService { * @return True if the data is available, false otherwise. */ private synchronized boolean isDataAvailable() { + + // If this feature is disabled, just stop + if (!settings.getProperty(ProtectionSettings.ENABLE_GEOIP)) { + enabled = false; + return false; + } + if (downloading) { // we are currently downloading the database return false; @@ -280,6 +289,9 @@ public class GeoIpService { * or "--" if it cannot be fetched. */ public String getCountryCode(String ip) { + if (!enabled) { + return "--"; + } if (InternetProtocolUtils.isLocalAddress(ip)) { return "LOCALHOST"; } @@ -293,6 +305,9 @@ public class GeoIpService { * @return The name of the country, "LocalHost" for local addresses, or "N/A" if it cannot be fetched. */ public String getCountryName(String ip) { + if (!enabled) { + return "N/A"; + } if (InternetProtocolUtils.isLocalAddress(ip)) { return "LocalHost"; } diff --git a/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java b/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java index f8b891d08..2c4f3431b 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java @@ -20,6 +20,10 @@ public final class ProtectionSettings implements SettingsHolder { public static final Property ENABLE_PROTECTION_REGISTERED = newProperty("Protection.enableProtectionRegistered", true); + @Comment("Enable GeoIp database") + public static final Property ENABLE_GEOIP = + newProperty("Protection.geoIpDatabase.enabled", true); + @Comment({"The MaxMind clientId used to download the GeoIp database,", "get one at https://www.maxmind.com/en/accounts/current/license-key", "The EssentialsX project has a very useful tutorial on how to generate",