Search in sources :

Example 11 with Nickname

use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.

the class ImportBuilderTest method userDataBuilderConstructsCorrectItem.

@Test
void userDataBuilderConstructsCorrectItem() {
    UserImportData.UserImportDataBuilder builder = UserImportData.builder(TestConstants.SERVER_UUID);
    UUID uuid = UUID.randomUUID();
    PlayerKill playerKill = TestData.getPlayerKill(uuid, uuid, TestConstants.SERVER_UUID, randomString, 1);
    GMTimes gmTimes = new GMTimes(randomString, randomInt);
    UserImportData data = builder.uuid(uuid).banned().banned(false).op().ips(randomString, randomString).ips(Collections.singletonList(randomString)).kills(playerKill, playerKill, playerKill).kills(Collections.singleton(playerKill)).name(randomString).registered(randomInt).timesKicked(randomInt).mobKills(randomInt).worldTimes(randomString, randomInt, randomInt, randomInt, randomInt).worldTimes(randomString, gmTimes).deaths(randomInt).worldTimes(ImmutableMap.of(randomString, gmTimes)).nicknames(randomString, randomString).nicknames(Collections.singletonList(new Nickname(randomString, System.currentTimeMillis(), TestConstants.SERVER_UUID))).build();
    assertNotNull(data);
    assertFalse(data.isBanned());
    assertTrue(data.isOp());
    assertEquals(randomInt, data.getDeaths());
    assertEquals(1, data.getWorldTimes().size());
    assertEquals(3, data.getIps().size());
    assertEquals(playerKill, data.getKills().get(0));
    assertEquals(randomInt, data.getMobKills());
    assertEquals(3, data.getNicknames().size());
    assertEquals(randomInt, data.getTimesKicked());
    assertEquals(uuid, data.getUuid());
    assertEquals(randomString, data.getName());
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) UUID(java.util.UUID) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Test(org.junit.jupiter.api.Test)

Example 12 with Nickname

use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.

the class ChatListener method actOnChatEvent.

private void actOnChatEvent(PlayerChatEvent event) {
    long time = System.currentTimeMillis();
    Player player = event.getPlayer();
    UUID uuid = player.getUniqueId();
    String displayName = player.getDisplayName();
    dbSystem.getDatabase().executeTransaction(new NicknameStoreTransaction(uuid, new Nickname(displayName, time, serverInfo.getServerUUID()), (playerUUID, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)));
}
Also used : NicknameCache(com.djrapitops.plan.gathering.cache.NicknameCache) ServerInfo(com.djrapitops.plan.identification.ServerInfo) UUID(java.util.UUID) EventHandler(cn.nukkit.event.EventHandler) Listener(cn.nukkit.event.Listener) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) Player(cn.nukkit.Player) NicknameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction) EventPriority(cn.nukkit.event.EventPriority) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) Nickname(com.djrapitops.plan.delivery.domain.Nickname) PlayerChatEvent(cn.nukkit.event.player.PlayerChatEvent) Player(cn.nukkit.Player) NicknameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction) UUID(java.util.UUID) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 13 with Nickname

use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.

the class PlayerOnlineListener method actOnJoinEvent.

private void actOnJoinEvent(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    UUID playerUUID = player.getUniqueId();
    ServerUUID serverUUID = serverInfo.getServerUUID();
    long time = System.currentTimeMillis();
    NukkitAFKListener.afkTracker.performedAction(playerUUID, time);
    String world = player.getLevel().getName();
    String gm = GMTimes.magicNumberToGMName(player.getGamemode());
    Database database = dbSystem.getDatabase();
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
    InetAddress address = player.getSocketAddress().getAddress();
    Supplier<String> getHostName = () -> null;
    String playerName = player.getName();
    String displayName = player.getDisplayName();
    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
    }
    long registerDate = TimeUnit.SECONDS.toMillis(player.getFirstPlayed());
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> registerDate, playerName, serverUUID, getHostName));
    dbSystem.getDatabase().executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, player.isOp()));
    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()));
    sessionCache.cacheSession(playerUUID, session).ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
    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 : PlayerLoginEvent(cn.nukkit.event.player.PlayerLoginEvent) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) NicknameCache(com.djrapitops.plan.gathering.cache.NicknameCache) Exporter(com.djrapitops.plan.delivery.export.Exporter) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerUUID(com.djrapitops.plan.identification.ServerUUID) 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) GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) PlayerJoinEvent(cn.nukkit.event.player.PlayerJoinEvent) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) SessionCache(com.djrapitops.plan.gathering.cache.SessionCache) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) EventPriority(cn.nukkit.event.EventPriority) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) PlayerKickEvent(cn.nukkit.event.player.PlayerKickEvent) ServerName(com.djrapitops.plan.delivery.domain.ServerName) ServerInfo(com.djrapitops.plan.identification.ServerInfo) ExportSettings(com.djrapitops.plan.settings.config.paths.ExportSettings) UUID(java.util.UUID) EventHandler(cn.nukkit.event.EventHandler) Listener(cn.nukkit.event.Listener) TimeUnit(java.util.concurrent.TimeUnit) 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) Player(cn.nukkit.Player) PlayerQuitEvent(cn.nukkit.event.player.PlayerQuitEvent) CallEvents(com.djrapitops.plan.extension.CallEvents) Processing(com.djrapitops.plan.processing.Processing) GeolocationCache(com.djrapitops.plan.gathering.geolocation.GeolocationCache) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Player(cn.nukkit.Player) ServerUUID(com.djrapitops.plan.identification.ServerUUID) 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) InetAddress(java.net.InetAddress) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 14 with Nickname

use of com.djrapitops.plan.delivery.domain.Nickname 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();
    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
    }
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time, playerName, serverUUID, 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()));
    sessionCache.cacheSession(playerUUID, session).ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
    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) 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) InetAddress(java.net.InetAddress) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 15 with Nickname

use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.

the class LargeStoreQueries method storeAllNicknameData.

/**
 * Execute a big batch of nickname insert statements.
 *
 * @param ofServersAndUsers Multimap: Server UUID - (Player UUID - List of nicknames)
 * @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
 */
public static Executable storeAllNicknameData(Map<ServerUUID, Map<UUID, List<Nickname>>> ofServersAndUsers) {
    if (ofServersAndUsers == null || ofServersAndUsers.isEmpty())
        return Executable.empty();
    return new ExecBatchStatement(NicknamesTable.INSERT_STATEMENT) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            // Every Server
            for (Map.Entry<ServerUUID, Map<UUID, List<Nickname>>> serverEntry : ofServersAndUsers.entrySet()) {
                ServerUUID serverUUID = serverEntry.getKey();
                // Every User
                for (Map.Entry<UUID, List<Nickname>> entry : serverEntry.getValue().entrySet()) {
                    UUID uuid = entry.getKey();
                    // Every Nickname
                    List<Nickname> nicknames = entry.getValue();
                    for (Nickname nickname : nicknames) {
                        statement.setString(1, uuid.toString());
                        statement.setString(2, serverUUID.toString());
                        statement.setString(3, nickname.getName());
                        statement.setLong(4, nickname.getDate());
                        statement.addBatch();
                    }
                }
            }
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PreparedStatement(java.sql.PreparedStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Aggregations

Nickname (com.djrapitops.plan.delivery.domain.Nickname)18 UUID (java.util.UUID)11 ServerUUID (com.djrapitops.plan.identification.ServerUUID)9 NicknameCache (com.djrapitops.plan.gathering.cache.NicknameCache)8 ServerInfo (com.djrapitops.plan.identification.ServerInfo)8 DBSystem (com.djrapitops.plan.storage.database.DBSystem)8 ErrorContext (com.djrapitops.plan.utilities.logging.ErrorContext)8 ErrorLogger (com.djrapitops.plan.utilities.logging.ErrorLogger)8 Inject (javax.inject.Inject)8 NicknameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction)6 ResultSet (java.sql.ResultSet)6 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)5 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)5 com.djrapitops.plan.storage.database.transactions.events (com.djrapitops.plan.storage.database.transactions.events)5 PreparedStatement (java.sql.PreparedStatement)5 PlayerName (com.djrapitops.plan.delivery.domain.PlayerName)4 ServerName (com.djrapitops.plan.delivery.domain.ServerName)4 Exporter (com.djrapitops.plan.delivery.export.Exporter)4 CallEvents (com.djrapitops.plan.extension.CallEvents)4 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)4