Disabled geolocations by default on Sponge

This commit is contained in:
Rsl1122 2018-04-11 19:36:50 +03:00
parent cb9c99108d
commit 2b6564bb32
2 changed files with 19 additions and 11 deletions

View File

@ -3,6 +3,8 @@ package com.djrapitops.plan.system.cache;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
@ -45,12 +47,14 @@ public class GeolocationCache implements SubSystem {
@Override @Override
public void enable() throws EnableException { public void enable() throws EnableException {
geolocationDB = new File(FileSystem.getDataFolder(), "GeoIP.dat"); geolocationDB = new File(FileSystem.getDataFolder(), "GeoIP.dat");
try { if (!Check.isSpongeAvailable() || Settings.DATA_GEOLOCATIONS.isTrue()) {
GeolocationCache.checkDB(); try {
} catch (UnknownHostException e) { GeolocationCache.checkDB();
Log.error("Plan Requires internet access on first run to download GeoLite2 Geolocation database."); } catch (UnknownHostException e) {
} catch (IOException e) { Log.error("Plan Requires internet access on first run to download GeoLite2 Geolocation database.");
throw new EnableException("Something went wrong saving the downloaded GeoLite2 Geolocation database", e); } catch (IOException e) {
throw new EnableException("Something went wrong saving the downloaded GeoLite2 Geolocation database", e);
}
} }
} }

View File

@ -9,6 +9,8 @@ import com.djrapitops.plan.data.container.GeoInfo;
import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.GeolocationCache;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.processing.CriticalRunnable; import com.djrapitops.plan.system.processing.CriticalRunnable;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import java.util.UUID; import java.util.UUID;
@ -32,11 +34,13 @@ public class IPUpdateProcessor implements CriticalRunnable {
@Override @Override
public void run() { public void run() {
String country = GeolocationCache.getCountry(ip); if (!Check.isSpongeAvailable() || Settings.DATA_GEOLOCATIONS.isTrue()) {
try { String country = GeolocationCache.getCountry(ip);
Database.getActive().save().geoInfo(uuid, new GeoInfo(ip, country, time)); try {
} catch (DBException e) { Database.getActive().save().geoInfo(uuid, new GeoInfo(ip, country, time));
Log.toLog(this.getClass(), e); } catch (DBException e) {
Log.toLog(this.getClass(), e);
}
} }
} }
} }