diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java index b6a921f6b..6c05a78d2 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java @@ -17,7 +17,9 @@ package com.djrapitops.plan.system.listeners.bukkit; import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.db.access.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.db.access.transactions.events.WorldNameStoreTransaction; +import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.ServerInfo; @@ -54,6 +56,7 @@ public class PlayerOnlineListener implements Listener { private final Processing processing; private final ServerInfo serverInfo; private final DBSystem dbSystem; + private final GeolocationCache geolocationCache; private final SessionCache sessionCache; private final ErrorHandler errorHandler; private final Status status; @@ -66,6 +69,7 @@ public class PlayerOnlineListener implements Listener { Processing processing, ServerInfo serverInfo, DBSystem dbSystem, + GeolocationCache geolocationCache, SessionCache sessionCache, Status status, RunnableFactory runnableFactory, @@ -76,6 +80,7 @@ public class PlayerOnlineListener implements Listener { this.processing = processing; this.serverInfo = serverInfo; this.dbSystem = dbSystem; + this.geolocationCache = geolocationCache; this.sessionCache = sessionCache; this.status = status; this.runnableFactory = runnableFactory; @@ -148,11 +153,15 @@ public class PlayerOnlineListener implements Listener { String displayName = player.getDisplayName(); boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); + if (gatheringGeolocations) { + dbSystem.getDatabase().executeTransaction( + new GeoInfoStoreTransaction(uuid, address, time, geolocationCache::getCountry) + ); + } processing.submitCritical(() -> sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, world, gm))); runnableFactory.create("Player Register: " + uuid, processors.player().registerProcessor(uuid, player::getFirstPlayed, playerName, - gatheringGeolocations ? processors.player().ipUpdateProcessor(uuid, address, time) : null, processors.player().nameProcessor(uuid, playerName, displayName), processors.info().playerPageUpdateProcessor(uuid) ) diff --git a/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java b/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java index e59e35351..fd4793700 100644 --- a/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java +++ b/Plan/bungeecord/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java @@ -17,7 +17,10 @@ package com.djrapitops.plan.system.listeners.bungee; import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.db.access.transactions.events.GeoInfoStoreTransaction; +import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.SessionCache; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.Processors; @@ -48,6 +51,8 @@ public class PlayerOnlineListener implements Listener { private final PlanConfig config; private final Processors processors; private final Processing processing; + private final DBSystem dbSystem; + private final GeolocationCache geolocationCache; private final SessionCache sessionCache; private final ServerInfo serverInfo; private final ErrorHandler errorHandler; @@ -57,6 +62,8 @@ public class PlayerOnlineListener implements Listener { PlanConfig config, Processors processors, Processing processing, + DBSystem dbSystem, + GeolocationCache geolocationCache, SessionCache sessionCache, ServerInfo serverInfo, ErrorHandler errorHandler @@ -64,6 +71,8 @@ public class PlayerOnlineListener implements Listener { this.config = config; this.processors = processors; this.processing = processing; + this.dbSystem = dbSystem; + this.geolocationCache = geolocationCache; this.sessionCache = sessionCache; this.serverInfo = serverInfo; this.errorHandler = errorHandler; @@ -81,10 +90,13 @@ public class PlayerOnlineListener implements Listener { sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, null, null)); boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); + if (gatheringGeolocations) { + dbSystem.getDatabase().executeTransaction( + new GeoInfoStoreTransaction(uuid, address, time, geolocationCache::getCountry) + ); + } - processing.submit(processors.player().proxyRegisterProcessor(uuid, name, time, - gatheringGeolocations ? processors.player().ipUpdateProcessor(uuid, address, time) : null - )); + processing.submit(processors.player().proxyRegisterProcessor(uuid, name, time)); processing.submit(processors.info().playerPageUpdateProcessor(uuid)); ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID())); } catch (Exception e) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/DataStoreQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/DataStoreQueries.java index 6926b3715..59ad9a85b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/DataStoreQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/DataStoreQueries.java @@ -16,6 +16,7 @@ */ package com.djrapitops.plan.db.access.queries; +import com.djrapitops.plan.data.container.GeoInfo; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.keys.SessionKeys; import com.djrapitops.plan.data.time.GMTimes; @@ -137,4 +138,38 @@ public class DataStoreQueries { } }; } + + public static Executable storeGeoInfo(UUID playerUUID, GeoInfo geoInfo) { + return connection -> { + if (!updateGeoInfo(playerUUID, geoInfo).execute(connection)) { + return insertGeoInfo(playerUUID, geoInfo).execute(connection); + } + return false; + }; + } + + private static Executable updateGeoInfo(UUID playerUUID, GeoInfo geoInfo) { + return new ExecStatement(GeoInfoTable.UPDATE_STATEMENT) { + @Override + public void prepare(PreparedStatement statement) throws SQLException { + statement.setLong(1, geoInfo.getDate()); + statement.setString(2, playerUUID.toString()); + statement.setString(3, geoInfo.getIpHash()); + statement.setString(4, geoInfo.getGeolocation()); + } + }; + } + + private static Executable insertGeoInfo(UUID playerUUID, GeoInfo geoInfo) { + return new ExecStatement(GeoInfoTable.INSERT_STATEMENT) { + @Override + public void prepare(PreparedStatement statement) throws SQLException { + statement.setString(1, playerUUID.toString()); + statement.setString(2, geoInfo.getIp()); + statement.setString(3, geoInfo.getIpHash()); + statement.setString(4, geoInfo.getGeolocation()); + statement.setLong(5, geoInfo.getDate()); + } + }; + } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/GeoInfoStoreTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/GeoInfoStoreTransaction.java new file mode 100644 index 000000000..1b2aa5e89 --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/GeoInfoStoreTransaction.java @@ -0,0 +1,82 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package com.djrapitops.plan.db.access.transactions.events; + +import com.djrapitops.plan.data.container.GeoInfo; +import com.djrapitops.plan.db.access.queries.DataStoreQueries; +import com.djrapitops.plan.db.access.transactions.Transaction; + +import java.net.InetAddress; +import java.security.NoSuchAlgorithmException; +import java.util.UUID; +import java.util.function.Function; + +/** + * Transaction to update Geo information of a player in the database. + * + * @author Rsl1122 + */ +public class GeoInfoStoreTransaction extends Transaction { + + private static boolean hasFailed = false; + + private final UUID playerUUID; + private InetAddress ip; + private long time; + private Function geolocationFunction; + + private GeoInfo geoInfo; + + public GeoInfoStoreTransaction( + UUID playerUUID, + InetAddress ip, + long time, + Function geolocationFunction + ) { + this.playerUUID = playerUUID; + this.ip = ip; + this.time = time; + this.geolocationFunction = geolocationFunction; + } + + public GeoInfoStoreTransaction(UUID playerUUID, GeoInfo geoInfo) { + this.playerUUID = playerUUID; + this.geoInfo = geoInfo; + } + + @Override + protected boolean shouldBeExecuted() { + return !hasFailed; + } + + @Override + protected void performOperations() { + try { + if (geoInfo == null) geoInfo = createGeoInfo(); + + execute(DataStoreQueries.storeGeoInfo(playerUUID, geoInfo)); + } catch (NoSuchAlgorithmException noSHA256Available) { + // SHA256 not available. + hasFailed = true; + } + } + + private GeoInfo createGeoInfo() throws NoSuchAlgorithmException { + String country = geolocationFunction.apply(ip.getHostAddress()); + return new GeoInfo(ip, country, time); + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java index 042afbd67..92755fe3c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java @@ -19,19 +19,20 @@ package com.djrapitops.plan.db.sql.tables; import com.djrapitops.plan.data.container.GeoInfo; import com.djrapitops.plan.db.DBType; import com.djrapitops.plan.db.SQLDB; -import com.djrapitops.plan.db.access.ExecStatement; import com.djrapitops.plan.db.access.QueryStatement; import com.djrapitops.plan.db.access.queries.LargeFetchQueries; import com.djrapitops.plan.db.patches.*; import com.djrapitops.plan.db.sql.parsing.CreateTableParser; -import com.djrapitops.plan.db.sql.parsing.Select; import com.djrapitops.plan.db.sql.parsing.Sql; import com.djrapitops.plan.utilities.comparators.GeoInfoComparator; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; /** * Table that is in charge of storing common IP and Geolocation data for users. @@ -65,6 +66,11 @@ public class GeoInfoTable extends Table { + GEOLOCATION + ", " + LAST_USED + ") VALUES (?, ?, ?, ?, ?)"; + public static final String UPDATE_STATEMENT = "UPDATE " + TABLE_NAME + " SET " + + LAST_USED + "=?" + + " WHERE " + USER_UUID + "=?" + + " AND " + IP_HASH + "=?" + + " AND " + GEOLOCATION + "=?"; public GeoInfoTable(SQLDB db) { super(TABLE_NAME, db); @@ -106,67 +112,6 @@ public class GeoInfoTable extends Table { }); } - private void updateGeoInfo(UUID uuid, GeoInfo info) { - String sql = "UPDATE " + tableName + " SET " - + LAST_USED + "=?" + - " WHERE " + USER_UUID + "=?" + - " AND " + IP_HASH + "=?" + - " AND " + GEOLOCATION + "=?"; - - execute(new ExecStatement(sql) { - @Override - public void prepare(PreparedStatement statement) throws SQLException { - statement.setLong(1, info.getDate()); - statement.setString(2, uuid.toString()); - statement.setString(3, info.getIpHash()); - statement.setString(4, info.getGeolocation()); - } - }); - } - - public void saveGeoInfo(UUID uuid, GeoInfo info) { - List geoInfo = getGeoInfo(uuid); - if (geoInfo.contains(info)) { - updateGeoInfo(uuid, info); - } else { - insertGeoInfo(uuid, info); - } - } - - private void insertGeoInfo(UUID uuid, GeoInfo info) { - execute(new ExecStatement(INSERT_STATEMENT) { - @Override - public void prepare(PreparedStatement statement) throws SQLException { - statement.setString(1, uuid.toString()); - statement.setString(2, info.getIp()); - statement.setString(3, info.getIpHash()); - statement.setString(4, info.getGeolocation()); - statement.setLong(5, info.getDate()); - } - }); - } - - public Optional getGeolocation(String ip) { - String sql = Select.from(tableName, GEOLOCATION) - .where(IP + "=?") - .toString(); - - return query(new QueryStatement>(sql) { - @Override - public void prepare(PreparedStatement statement) throws SQLException { - statement.setString(1, ip); - } - - @Override - public Optional processResults(ResultSet set) throws SQLException { - if (set.next()) { - return Optional.of(set.getString(GEOLOCATION)); - } - return Optional.empty(); - } - }); - } - public List getNetworkGeolocations() { List geolocations = new ArrayList<>(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/operation/SaveOperations.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/operation/SaveOperations.java index 16a051f4d..45f3fad6d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/operation/SaveOperations.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/operation/SaveOperations.java @@ -73,9 +73,6 @@ public interface SaveOperations { @Deprecated void registerNewUser(UUID uuid, long registered, String name); - @Deprecated - void geoInfo(UUID uuid, GeoInfo geoInfo); - @Deprecated void playerWasKicked(UUID uuid); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLSaveOps.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLSaveOps.java index 18eb2e3f1..702e38230 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLSaveOps.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLSaveOps.java @@ -142,11 +142,6 @@ public class SQLSaveOps extends SQLOps implements SaveOperations { usersTable.registerUser(uuid, registered, name); } - @Override - public void geoInfo(UUID uuid, GeoInfo geoInfo) { - geoInfoTable.saveGeoInfo(uuid, geoInfo); - } - @Override public void playerWasKicked(UUID uuid) { usersTable.kicked(uuid); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java b/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java deleted file mode 100644 index d46350572..000000000 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of Player Analytics (Plan). - * - * Plan is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License v3 as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Plan is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Plan. If not, see . - */ -package com.djrapitops.plan.system.processing.processors.player; - -import com.djrapitops.plan.data.container.GeoInfo; -import com.djrapitops.plan.db.Database; -import com.djrapitops.plan.system.cache.GeolocationCache; -import com.djrapitops.plan.system.processing.CriticalRunnable; - -import java.net.InetAddress; -import java.security.NoSuchAlgorithmException; -import java.util.UUID; - -/** - * Updates the IP and Geolocation of a user. - * - * @author Rsl1122 - */ -public class IPUpdateProcessor implements CriticalRunnable { - - private final UUID uuid; - private final InetAddress ip; - private final long time; - - private final Database database; - private final GeolocationCache geolocationCache; - - IPUpdateProcessor( - UUID uuid, InetAddress ip, long time, - Database database, - GeolocationCache geolocationCache - ) { - this.uuid = uuid; - this.ip = ip; - this.time = time; - this.database = database; - this.geolocationCache = geolocationCache; - } - - @Override - public void run() { - try { - String country = geolocationCache.getCountry(ip.getHostAddress()); - GeoInfo geoInfo = new GeoInfo(ip, country, time); - database.save().geoInfo(uuid, geoInfo); - } catch (NoSuchAlgorithmException ignore) { - // Ignored, SHA-256 should be available - } - } -} diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/player/PlayerProcessors.java b/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/player/PlayerProcessors.java index 92c4f0838..e3b82ee7f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/player/PlayerProcessors.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/player/PlayerProcessors.java @@ -27,7 +27,6 @@ import dagger.Lazy; import javax.inject.Inject; import javax.inject.Singleton; -import java.net.InetAddress; import java.util.List; import java.util.UUID; import java.util.function.BooleanSupplier; @@ -74,10 +73,6 @@ public class PlayerProcessors { return new EndSessionProcessor(uuid, time, dataCache.get()); } - public IPUpdateProcessor ipUpdateProcessor(UUID uuid, InetAddress ip, long time) { - return new IPUpdateProcessor(uuid, ip, time, dbSystem.get().getDatabase(), geolocationCache.get()); - } - public KickProcessor kickProcessor(UUID uuid) { return new KickProcessor(uuid, dbSystem.get().getDatabase()); } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/db/CommonDBTest.java b/Plan/common/src/test/java/com/djrapitops/plan/db/CommonDBTest.java index ed33abba1..6f48f9b76 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/db/CommonDBTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/db/CommonDBTest.java @@ -34,6 +34,7 @@ import com.djrapitops.plan.db.access.queries.*; import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.db.access.transactions.*; import com.djrapitops.plan.db.access.transactions.events.CommandStoreTransaction; +import com.djrapitops.plan.db.access.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.db.access.transactions.events.WorldNameStoreTransaction; import com.djrapitops.plan.db.patches.Patch; import com.djrapitops.plan.db.sql.tables.*; @@ -233,28 +234,20 @@ public abstract class CommonDBTest { } @Test - public void testIPTable() throws DBInitException { + public void geoInformationIsStored() throws DBInitException { saveUserOne(); - GeoInfoTable geoInfoTable = db.getGeoInfoTable(); String expectedIP = "1.2.3.4"; String expectedGeoLoc = "TestLocation"; long time = System.currentTimeMillis(); GeoInfo expected = new GeoInfo(expectedIP, expectedGeoLoc, time, "3"); - geoInfoTable.saveGeoInfo(playerUUID, expected); - geoInfoTable.saveGeoInfo(playerUUID, expected); + saveGeoInfo(playerUUID, expected); commitTest(); - List getInfo = geoInfoTable.getGeoInfo(playerUUID); - assertEquals(1, getInfo.size()); - GeoInfo actual = getInfo.get(0); - assertEquals(expected, actual); - assertEquals(time, actual.getDate()); - - Optional result = geoInfoTable.getGeolocation(expectedIP); - assertTrue(result.isPresent()); - assertEquals(expectedGeoLoc, result.get()); + List geolocations = db.query(LargeFetchQueries.fetchAllGeoInformation()).getOrDefault(playerUUID, new ArrayList<>()); + assertEquals(1, geolocations.size()); + assertEquals(expected, geolocations.get(0)); } @Test @@ -518,7 +511,7 @@ public abstract class CommonDBTest { execute(DataStoreQueries.storeSession(session)); nicknamesTable.saveUserName(playerUUID, new Nickname("TestNick", System.currentTimeMillis(), serverUUID)); - geoInfoTable.saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L, "3")); + saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L, "3")); assertTrue(usersTable.isRegistered(playerUUID)); @@ -576,7 +569,7 @@ public abstract class CommonDBTest { execute(DataStoreQueries.storeSession(session)); nicknamesTable.saveUserName(playerUUID, new Nickname("TestNick", System.currentTimeMillis(), serverUUID)); - geoInfoTable.saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L, + saveGeoInfo(playerUUID, new GeoInfo("1.2.3.4", "TestLoc", 223456789L, new SHA256Hash("1.2.3.4").create())); assertTrue(usersTable.isRegistered(playerUUID)); @@ -613,6 +606,10 @@ public abstract class CommonDBTest { securityTable.addNewUser(new WebUser("Test", "RandomGarbageBlah", 0)); } + private void saveGeoInfo(UUID uuid, GeoInfo geoInfo) { + db.executeTransaction(new GeoInfoStoreTransaction(uuid, geoInfo)); + } + @Test public void testSessionTableNPEWhenNoPlayers() { Map lastSeen = db.getSessionsTable().getLastSeenForAllPlayers(); @@ -815,11 +812,11 @@ public abstract class CommonDBTest { usersTable.registerUser(secondUuid, 0, ""); usersTable.registerUser(thirdUuid, 0, ""); - geoInfoTable.saveGeoInfo(firstUuid, new GeoInfo("-", "Test1", 0, "3")); + saveGeoInfo(firstUuid, new GeoInfo("-", "Test1", 0, "3")); GeoInfo secondInfo = new GeoInfo("-", "Test2", 5, "3"); - geoInfoTable.saveGeoInfo(firstUuid, secondInfo); - geoInfoTable.saveGeoInfo(secondUuid, new GeoInfo("-", "Test3", 0, "3")); - geoInfoTable.saveGeoInfo(thirdUuid, new GeoInfo("-", "Test4", 0, "3")); + saveGeoInfo(firstUuid, secondInfo); + saveGeoInfo(secondUuid, new GeoInfo("-", "Test3", 0, "3")); + saveGeoInfo(thirdUuid, new GeoInfo("-", "Test4", 0, "3")); List geolocations = geoInfoTable.getNetworkGeolocations(); diff --git a/Plan/sponge/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java b/Plan/sponge/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java index 092c8b6d2..6a7bbd420 100644 --- a/Plan/sponge/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java +++ b/Plan/sponge/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java @@ -17,7 +17,9 @@ package com.djrapitops.plan.system.listeners.sponge; import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.db.access.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.db.access.transactions.events.WorldNameStoreTransaction; +import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.ServerInfo; @@ -58,10 +60,11 @@ public class SpongePlayerListener { private final Processing processing; private final ServerInfo serverInfo; private final DBSystem dbSystem; - private SessionCache sessionCache; + private final GeolocationCache geolocationCache; + private final SessionCache sessionCache; private final Status status; - private RunnableFactory runnableFactory; - private ErrorHandler errorHandler; + private final RunnableFactory runnableFactory; + private final ErrorHandler errorHandler; @Inject public SpongePlayerListener( @@ -70,6 +73,7 @@ public class SpongePlayerListener { Processing processing, ServerInfo serverInfo, DBSystem dbSystem, + GeolocationCache geolocationCache, SessionCache sessionCache, Status status, RunnableFactory runnableFactory, @@ -80,6 +84,7 @@ public class SpongePlayerListener { this.processing = processing; this.serverInfo = serverInfo; this.dbSystem = dbSystem; + this.geolocationCache = geolocationCache; this.sessionCache = sessionCache; this.status = status; this.runnableFactory = runnableFactory; @@ -153,11 +158,15 @@ public class SpongePlayerListener { String displayName = player.getDisplayNameData().displayName().get().toPlain(); boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); + if (gatheringGeolocations) { + dbSystem.getDatabase().executeTransaction( + new GeoInfoStoreTransaction(uuid, address, time, geolocationCache::getCountry) + ); + } processing.submitCritical(() -> sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, world, gm))); runnableFactory.create("Player Register: " + uuid, processors.player().registerProcessor(uuid, () -> time, playerName, - gatheringGeolocations ? processors.player().ipUpdateProcessor(uuid, address, time) : null, processors.player().nameProcessor(uuid, playerName, displayName), processors.info().playerPageUpdateProcessor(uuid) ) diff --git a/Plan/velocity/src/main/java/com/djrapitops/plan/system/listeners/velocity/PlayerOnlineListener.java b/Plan/velocity/src/main/java/com/djrapitops/plan/system/listeners/velocity/PlayerOnlineListener.java index 9019379bf..2a9e2fad9 100644 --- a/Plan/velocity/src/main/java/com/djrapitops/plan/system/listeners/velocity/PlayerOnlineListener.java +++ b/Plan/velocity/src/main/java/com/djrapitops/plan/system/listeners/velocity/PlayerOnlineListener.java @@ -17,7 +17,10 @@ package com.djrapitops.plan.system.listeners.velocity; import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.db.access.transactions.events.GeoInfoStoreTransaction; +import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.SessionCache; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.Processors; @@ -51,6 +54,8 @@ public class PlayerOnlineListener { private final PlanConfig config; private final Processors processors; private final Processing processing; + private final DBSystem dbSystem; + private final GeolocationCache geolocationCache; private final SessionCache sessionCache; private final ServerInfo serverInfo; private final ErrorHandler errorHandler; @@ -60,6 +65,8 @@ public class PlayerOnlineListener { PlanConfig config, Processing processing, Processors processors, + DBSystem dbSystem, + GeolocationCache geolocationCache, SessionCache sessionCache, ServerInfo serverInfo, ErrorHandler errorHandler @@ -67,6 +74,8 @@ public class PlayerOnlineListener { this.config = config; this.processing = processing; this.processors = processors; + this.dbSystem = dbSystem; + this.geolocationCache = geolocationCache; this.sessionCache = sessionCache; this.serverInfo = serverInfo; this.errorHandler = errorHandler; @@ -84,10 +93,13 @@ public class PlayerOnlineListener { sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, null, null)); boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); + if (gatheringGeolocations) { + dbSystem.getDatabase().executeTransaction( + new GeoInfoStoreTransaction(uuid, address, time, geolocationCache::getCountry) + ); + } - processing.submit(processors.player().proxyRegisterProcessor(uuid, name, time, - gatheringGeolocations ? processors.player().ipUpdateProcessor(uuid, address, time) : null - )); + processing.submit(processors.player().proxyRegisterProcessor(uuid, name, time)); processing.submit(processors.info().playerPageUpdateProcessor(uuid)); ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID())); } catch (Exception e) {