use of com.djrapitops.plan.gathering.domain.event.JoinAddress in project Plan by plan-player-analytics.
the class FinishedSession method deserializeCSV.
/**
* Deserialize csv format of the session.
*
* @param serialized Serialized version of the session
* @return Proper session if the csv had 9 columns or more
* @throws com.google.gson.JsonSyntaxException if serialized format has a json syntax error
*/
public static Optional<FinishedSession> deserializeCSV(String serialized) {
String[] array = StringUtils.split(serialized, ';');
OptionalArray<String> asOptionals = OptionalArray.of(array);
if (array.length < 5)
return Optional.empty();
// Note for the future: Use length to determine version of serialized class
Gson gson = new Gson();
UUID playerUUID = UUID.fromString(array[0]);
ServerUUID serverUUID = ServerUUID.fromString(array[1]);
long start = Long.parseLong(array[2]);
long end = Long.parseLong(array[3]);
long afkTime = Long.parseLong(array[4]);
DataMap extraData = new DataMap();
asOptionals.get(5).ifPresent(value -> extraData.put(WorldTimes.class, gson.fromJson(value, WorldTimes.class)));
asOptionals.get(6).ifPresent(value -> extraData.put(PlayerKills.class, gson.fromJson(value, PlayerKills.class)));
asOptionals.get(7).ifPresent(value -> extraData.put(MobKillCounter.class, gson.fromJson(value, MobKillCounter.class)));
asOptionals.get(8).ifPresent(value -> extraData.put(DeathCounter.class, gson.fromJson(value, DeathCounter.class)));
asOptionals.get(9).ifPresent(value -> extraData.put(JoinAddress.class, new JoinAddress(value)));
asOptionals.get(10).ifPresent(value -> extraData.put(PlayerName.class, new PlayerName(value)));
return Optional.of(new FinishedSession(playerUUID, serverUUID, start, end, afkTime, extraData));
}
use of com.djrapitops.plan.gathering.domain.event.JoinAddress in project Plan by plan-player-analytics.
the class PlayerOnlineListener method actOnJoinEvent.
private void actOnJoinEvent(ClientConnectionEvent.Join event) {
Player player = event.getTargetEntity();
UUID playerUUID = player.getUniqueId();
ServerUUID serverUUID = serverInfo.getServerUUID();
long time = System.currentTimeMillis();
SpongeAFKListener.afkTracker.performedAction(playerUUID, time);
String world = player.getWorld().getName();
Optional<GameMode> gameMode = player.getGameModeData().get(Keys.GAME_MODE);
String gm = gameMode.map(mode -> mode.getName().toUpperCase()).orElse("ADVENTURE");
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
InetAddress address = player.getConnection().getAddress().getAddress();
Supplier<String> getHostName = () -> player.getConnection().getVirtualHost().getHostString();
String playerName = player.getName();
String displayName = player.getDisplayNameData().displayName().get().toPlain();
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time, playerName, serverUUID, getHostName)).thenRunAsync(() -> {
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(new StoreGeoInfoTransaction(playerUUID, address, time, geolocationCache::getCountry));
}
database.executeTransaction(new StoreJoinAddressTransaction(getHostName));
ActiveSession session = new ActiveSession(playerUUID, serverUUID, time, world, gm);
session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName()));
session.getExtraData().put(JoinAddress.class, new JoinAddress(getHostName));
sessionCache.cacheSession(playerUUID, session).map(StoreSessionTransaction::new).ifPresent(database::executeTransaction);
database.executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname(displayName, time, serverUUID), (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
});
}
use of com.djrapitops.plan.gathering.domain.event.JoinAddress in project Plan by plan-player-analytics.
the class JoinAddressQueriesTest method latestJoinAddressIsUpdatedUponSecondSession.
@Test
default void latestJoinAddressIsUpdatedUponSecondSession() {
joinAddressCanBeUnknown();
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get();
session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress));
db().executeTransaction(new StoreSessionTransaction(session));
Map<String, Integer> expected = Map.of(expectedAddress, 1);
Map<String, Integer> result = db().query(JoinAddressQueries.latestJoinAddresses());
assertEquals(expected, result);
}
use of com.djrapitops.plan.gathering.domain.event.JoinAddress in project Plan by plan-player-analytics.
the class JoinAddressQueriesTest method joinAddressUpdateIsUniquePerServer.
@Test
default void joinAddressUpdateIsUniquePerServer() {
joinAddressCanBeUnknown();
db().executeTransaction(TestData.storeServers());
db().executeTransaction(new WorldNameStoreTransaction(TestConstants.SERVER_TWO_UUID, worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(TestConstants.SERVER_TWO_UUID, worlds[1]));
FinishedSession session = RandomData.randomSession(TestConstants.SERVER_TWO_UUID, worlds, playerUUID, player2UUID);
String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get();
session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress));
db().executeTransaction(new StoreSessionTransaction(session));
Map<String, Integer> expected1 = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1);
Map<String, Integer> result1 = db().query(JoinAddressQueries.latestJoinAddresses(serverUUID()));
assertEquals(expected1, result1);
Map<String, Integer> expected2 = Map.of(expectedAddress, 1);
Map<String, Integer> result2 = db().query(JoinAddressQueries.latestJoinAddresses(TestConstants.SERVER_TWO_UUID));
assertEquals(expected2, result2);
}
Aggregations