mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 16:37:58 +01:00
Made Geolocator init asynchronous.
This commit is contained in:
parent
304d8da86b
commit
9480245dae
@ -23,6 +23,8 @@ import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
|
|||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
import com.djrapitops.plan.settings.locale.lang.PluginLang;
|
import com.djrapitops.plan.settings.locale.lang.PluginLang;
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
|
import com.djrapitops.plugin.task.AbsRunnable;
|
||||||
|
import com.djrapitops.plugin.task.RunnableFactory;
|
||||||
import com.github.benmanes.caffeine.cache.Cache;
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ public class GeolocationCache implements SubSystem {
|
|||||||
private final Locale locale;
|
private final Locale locale;
|
||||||
private final PlanConfig config;
|
private final PlanConfig config;
|
||||||
private final PluginLogger logger;
|
private final PluginLogger logger;
|
||||||
|
private final RunnableFactory runnableFactory;
|
||||||
private final Cache<String, String> cache;
|
private final Cache<String, String> cache;
|
||||||
|
|
||||||
private final Geolocator geoLite2Geolocator;
|
private final Geolocator geoLite2Geolocator;
|
||||||
@ -59,13 +62,15 @@ public class GeolocationCache implements SubSystem {
|
|||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
GeoLite2Geolocator geoLite2Geolocator,
|
GeoLite2Geolocator geoLite2Geolocator,
|
||||||
IP2CGeolocator ip2cGeolocator,
|
IP2CGeolocator ip2cGeolocator,
|
||||||
PluginLogger logger
|
PluginLogger logger,
|
||||||
|
RunnableFactory runnableFactory
|
||||||
) {
|
) {
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.geoLite2Geolocator = geoLite2Geolocator;
|
this.geoLite2Geolocator = geoLite2Geolocator;
|
||||||
this.ip2cGeolocator = ip2cGeolocator;
|
this.ip2cGeolocator = ip2cGeolocator;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.runnableFactory = runnableFactory;
|
||||||
|
|
||||||
this.cache = Caffeine.newBuilder()
|
this.cache = Caffeine.newBuilder()
|
||||||
.expireAfterAccess(1, TimeUnit.MINUTES)
|
.expireAfterAccess(1, TimeUnit.MINUTES)
|
||||||
@ -75,9 +80,14 @@ public class GeolocationCache implements SubSystem {
|
|||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
if (config.isTrue(DataGatheringSettings.GEOLOCATIONS)) {
|
if (config.isTrue(DataGatheringSettings.GEOLOCATIONS)) {
|
||||||
|
runnableFactory.create("Geolocator init", new AbsRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (inUseGeolocator == null) tryToPrepareGeoLite2();
|
if (inUseGeolocator == null) tryToPrepareGeoLite2();
|
||||||
if (inUseGeolocator == null) tryToPrepareIP2CGeolocator();
|
if (inUseGeolocator == null) tryToPrepareIP2CGeolocator();
|
||||||
if (inUseGeolocator == null) logger.error("Failed to enable geolocation.");
|
if (inUseGeolocator == null) logger.error("Failed to enable geolocation.");
|
||||||
|
}
|
||||||
|
}).runTaskAsynchronously();
|
||||||
} else {
|
} else {
|
||||||
logger.info(locale.getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_DISABLED));
|
logger.info(locale.getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_DISABLED));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user