Search in sources :

Example 6 with JoinAddress

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));
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Gson(com.google.gson.Gson) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress)

Example 7 with JoinAddress

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));
        }
    });
}
Also used : PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) NicknameCache(com.djrapitops.plan.gathering.cache.NicknameCache) Keys(org.spongepowered.api.data.key.Keys) KickPlayerEvent(org.spongepowered.api.event.entity.living.humanoid.player.KickPlayerEvent) Exporter(com.djrapitops.plan.delivery.export.Exporter) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerUUID(com.djrapitops.plan.identification.ServerUUID) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) DataGatheringSettings(com.djrapitops.plan.settings.config.paths.DataGatheringSettings) Supplier(java.util.function.Supplier) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) InetAddress(java.net.InetAddress) ProviderRegistration(org.spongepowered.api.service.ProviderRegistration) Order(org.spongepowered.api.event.Order) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) SessionCache(com.djrapitops.plan.gathering.cache.SessionCache) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) GameProfile(org.spongepowered.api.profile.GameProfile) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) ServerName(com.djrapitops.plan.delivery.domain.ServerName) ServerInfo(com.djrapitops.plan.identification.ServerInfo) ExportSettings(com.djrapitops.plan.settings.config.paths.ExportSettings) Sponge(org.spongepowered.api.Sponge) UUID(java.util.UUID) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Status(com.djrapitops.plan.gathering.listeners.Status) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) CallEvents(com.djrapitops.plan.extension.CallEvents) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Processing(com.djrapitops.plan.processing.Processing) Listener(org.spongepowered.api.event.Listener) GeolocationCache(com.djrapitops.plan.gathering.geolocation.GeolocationCache) Nickname(com.djrapitops.plan.delivery.domain.Nickname) BanService(org.spongepowered.api.service.ban.BanService) Player(org.spongepowered.api.entity.living.player.Player) ServerUUID(com.djrapitops.plan.identification.ServerUUID) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerName(com.djrapitops.plan.delivery.domain.ServerName) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) InetAddress(java.net.InetAddress) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 8 with JoinAddress

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);
}
Also used : StoreSessionTransaction(com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) Test(org.junit.jupiter.api.Test)

Example 9 with JoinAddress

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);
}
Also used : StoreSessionTransaction(com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) Test(org.junit.jupiter.api.Test)

Aggregations

JoinAddress (com.djrapitops.plan.gathering.domain.event.JoinAddress)9 PlayerName (com.djrapitops.plan.delivery.domain.PlayerName)5 ServerUUID (com.djrapitops.plan.identification.ServerUUID)5 ServerName (com.djrapitops.plan.delivery.domain.ServerName)4 UUID (java.util.UUID)4 Nickname (com.djrapitops.plan.delivery.domain.Nickname)3 Exporter (com.djrapitops.plan.delivery.export.Exporter)3 CallEvents (com.djrapitops.plan.extension.CallEvents)3 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)3 NicknameCache (com.djrapitops.plan.gathering.cache.NicknameCache)3 SessionCache (com.djrapitops.plan.gathering.cache.SessionCache)3 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)3 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)3 GeolocationCache (com.djrapitops.plan.gathering.geolocation.GeolocationCache)3 ServerInfo (com.djrapitops.plan.identification.ServerInfo)3 Processing (com.djrapitops.plan.processing.Processing)3 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)3 DataGatheringSettings (com.djrapitops.plan.settings.config.paths.DataGatheringSettings)3 ExportSettings (com.djrapitops.plan.settings.config.paths.ExportSettings)3 DBSystem (com.djrapitops.plan.storage.database.DBSystem)3