Search in sources :

Example 6 with Nickname

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

the class NicknameLastSeenPatch method updateLastUsed.

private void updateLastUsed(Map<ServerUUID, Integer> serverIDsByUUID, Map<Integer, Set<Nickname>> nicknames) {
    String updateSQL = "UPDATE " + NicknamesTable.TABLE_NAME + " SET " + NicknamesTable.LAST_USED + "=?" + WHERE + NicknamesTable.NICKNAME + "=?" + AND + "user_id=?" + AND + "server_id=?";
    execute(new ExecBatchStatement(updateSQL) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            for (Map.Entry<Integer, Set<Nickname>> entry : nicknames.entrySet()) {
                Integer userId = entry.getKey();
                Set<Nickname> nicks = entry.getValue();
                for (Nickname nick : nicks) {
                    Integer serverID = serverIDsByUUID.get(nick.getServerUUID());
                    statement.setLong(1, nick.getDate());
                    statement.setString(2, nick.getName());
                    statement.setInt(3, userId);
                    statement.setInt(4, serverID);
                    statement.addBatch();
                }
            }
        }
    });
}
Also used : Set(java.util.Set) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ExecBatchStatement(com.djrapitops.plan.storage.database.transactions.ExecBatchStatement) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 7 with Nickname

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

the class SpongeChatListener method actOnChatEvent.

private void actOnChatEvent(@First Player player) {
    long time = System.currentTimeMillis();
    UUID uuid = player.getUniqueId();
    String displayName = player.getDisplayNameData().displayName().get().toPlain();
    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) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) MessageChannelEvent(org.spongepowered.api.event.message.MessageChannelEvent) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) Order(org.spongepowered.api.event.Order) NicknameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener) Nickname(com.djrapitops.plan.delivery.domain.Nickname) First(org.spongepowered.api.event.filter.cause.First) NicknameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction) UUID(java.util.UUID) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 8 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(ServerPlayerEntity player) {
    UUID playerUUID = player.getUuid();
    ServerUUID serverUUID = serverInfo.getServerUUID();
    long time = System.currentTimeMillis();
    FabricAFKListener.afkTracker.performedAction(playerUUID, time);
    String world = player.getServerWorld().getRegistryKey().getValue().toString();
    String gm = player.interactionManager.getGameMode().name();
    Database database = dbSystem.getDatabase();
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
    InetSocketAddress socketAddress = (InetSocketAddress) player.networkHandler.connection.getAddress();
    InetAddress address = InetAddresses.forString(socketAddress.getAddress().toString().replace("/", ""));
    Supplier<String> getHostName = () -> getHostname(player);
    String playerName = player.getEntityName();
    String displayName = player.getDisplayName().asString();
    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
    }
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, System::currentTimeMillis, playerName, serverUUID, getHostName));
    database.executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, server.getPlayerManager().getOpList().isOp(player.getGameProfile())));
    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) SocketAddress(java.net.SocketAddress) Exporter(com.djrapitops.plan.delivery.export.Exporter) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerUUID(com.djrapitops.plan.identification.ServerUUID) GameProfile(com.mojang.authlib.GameProfile) FabricListener(net.playeranalytics.plan.gathering.listeners.FabricListener) DataGatheringSettings(com.djrapitops.plan.settings.config.paths.DataGatheringSettings) HashMap(java.util.HashMap) MinecraftDedicatedServer(net.minecraft.server.dedicated.MinecraftDedicatedServer) 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) ServerPlayConnectionEvents(net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) SessionCache(com.djrapitops.plan.gathering.cache.SessionCache) Map(java.util.Map) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) 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) UUID(java.util.UUID) PlanFabricEvents(net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents) InetSocketAddress(java.net.InetSocketAddress) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) CallEvents(com.djrapitops.plan.extension.CallEvents) Processing(com.djrapitops.plan.processing.Processing) InetAddresses(com.google.common.net.InetAddresses) GeolocationCache(com.djrapitops.plan.gathering.geolocation.GeolocationCache) Nickname(com.djrapitops.plan.delivery.domain.Nickname) ServerUUID(com.djrapitops.plan.identification.ServerUUID) InetSocketAddress(java.net.InetSocketAddress) 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 9 with Nickname

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

the class NicknameQueries method fetchLastSeenNicknameOfPlayer.

public static Query<Optional<Nickname>> fetchLastSeenNicknameOfPlayer(UUID playerUUID, ServerUUID serverUUID) {
    String subQuery = SELECT + "MAX(" + NicknamesTable.LAST_USED + ") FROM " + NicknamesTable.TABLE_NAME + WHERE + NicknamesTable.USER_UUID + "=?" + AND + NicknamesTable.SERVER_UUID + "=?" + GROUP_BY + NicknamesTable.USER_UUID;
    String sql = SELECT + NicknamesTable.LAST_USED + ',' + NicknamesTable.NICKNAME + FROM + NicknamesTable.TABLE_NAME + WHERE + NicknamesTable.USER_UUID + "=?" + AND + NicknamesTable.SERVER_UUID + "=?" + AND + NicknamesTable.LAST_USED + "=(" + subQuery + ')';
    return new QueryStatement<Optional<Nickname>>(sql) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, playerUUID.toString());
            statement.setString(2, serverUUID.toString());
            statement.setString(3, playerUUID.toString());
            statement.setString(4, serverUUID.toString());
        }

        @Override
        public Optional<Nickname> processResults(ResultSet set) throws SQLException {
            if (set.next()) {
                return Optional.of(new Nickname(set.getString(NicknamesTable.NICKNAME), set.getLong(NicknamesTable.LAST_USED), serverUUID));
            }
            return Optional.empty();
        }
    };
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 10 with Nickname

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

the class NicknameQueries method fetchAllNicknameData.

/**
 * Query database for all nickname data.
 *
 * @return Multimap: Server UUID - (Player UUID - List of nicknames)
 */
public static Query<Map<ServerUUID, Map<UUID, List<Nickname>>>> fetchAllNicknameData() {
    String sql = SELECT + NicknamesTable.NICKNAME + ',' + NicknamesTable.LAST_USED + ',' + NicknamesTable.USER_UUID + ',' + NicknamesTable.SERVER_UUID + FROM + NicknamesTable.TABLE_NAME;
    return new QueryAllStatement<Map<ServerUUID, Map<UUID, List<Nickname>>>>(sql, 5000) {

        @Override
        public Map<ServerUUID, Map<UUID, List<Nickname>>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, Map<UUID, List<Nickname>>> map = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(NicknamesTable.SERVER_UUID));
                UUID uuid = UUID.fromString(set.getString(NicknamesTable.USER_UUID));
                Map<UUID, List<Nickname>> serverMap = map.computeIfAbsent(serverUUID, Maps::create);
                List<Nickname> nicknames = serverMap.computeIfAbsent(uuid, Lists::create);
                nicknames.add(new Nickname(set.getString(NicknamesTable.NICKNAME), set.getLong(NicknamesTable.LAST_USED), serverUUID));
            }
            return map;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) Maps(com.djrapitops.plan.utilities.java.Maps) Lists(com.djrapitops.plan.utilities.java.Lists) ResultSet(java.sql.ResultSet) ServerUUID(com.djrapitops.plan.identification.ServerUUID) 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