Search in sources :

Example 91 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class NicknameQueries method fetchNicknameDataOfPlayer.

public static Query<List<Nickname>> fetchNicknameDataOfPlayer(UUID playerUUID) {
    String sql = SELECT + NicknamesTable.NICKNAME + ',' + NicknamesTable.LAST_USED + ',' + NicknamesTable.SERVER_UUID + FROM + NicknamesTable.TABLE_NAME + WHERE + NicknamesTable.USER_UUID + "=?";
    return new QueryStatement<List<Nickname>>(sql, 5000) {

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

        @Override
        public List<Nickname> processResults(ResultSet set) throws SQLException {
            List<Nickname> nicknames = new ArrayList<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(NicknamesTable.SERVER_UUID));
                String nickname = set.getString(NicknamesTable.NICKNAME);
                nicknames.add(new Nickname(nickname, set.getLong(NicknamesTable.LAST_USED), serverUUID));
            }
            return nicknames;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 92 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class ServerQueries method fetchPlanServerInformation.

/**
 * Query database for all Plan server information.
 *
 * @return Map: Server UUID - Plan Server Information
 */
public static Query<Map<ServerUUID, Server>> fetchPlanServerInformation() {
    String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME + WHERE + ServerTable.INSTALLED + "=?";
    return new QueryStatement<Map<ServerUUID, Server>>(sql, 100) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setBoolean(1, true);
        }

        @Override
        public Map<ServerUUID, Server> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, Server> servers = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID));
                servers.put(serverUUID, new Server(set.getInt(ServerTable.SERVER_ID), serverUUID, set.getString(ServerTable.NAME), set.getString(ServerTable.WEB_ADDRESS), set.getBoolean(ServerTable.PROXY)));
            }
            return servers;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 93 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class ServerPlayerContainersQuery method executeQuery.

@Override
public List<PlayerContainer> executeQuery(SQLDB db) {
    List<PlayerContainer> containers = new ArrayList<>();
    Collection<BaseUser> baseUsers = db.query(BaseUserQueries.fetchServerBaseUsers(serverUUID));
    Map<UUID, List<GeoInfo>> geoInformation = db.query(GeoInfoQueries.fetchServerGeoInformation(serverUUID));
    Map<UUID, List<Nickname>> nicknames = db.query(NicknameQueries.fetchNicknameDataOfServer(serverUUID));
    Map<UUID, List<Ping>> pingData = db.query(PingQueries.fetchPingDataOfServer(serverUUID));
    Map<UUID, List<FinishedSession>> sessions = db.query(SessionQueries.fetchSessionsOfServer(serverUUID));
    Map<UUID, UserInfo> userInformation = db.query(UserInfoQueries.fetchUserInformationOfServer(serverUUID));
    Map<UUID, PerServerContainer> perServerInfo = getPerServerData(userInformation, sessions, pingData);
    for (BaseUser user : baseUsers) {
        PlayerContainer container = new PlayerContainer();
        // BaseUser
        UUID uuid = user.getUuid();
        container.putRawData(PlayerKeys.UUID, uuid);
        container.putRawData(PlayerKeys.NAME, user.getName());
        container.putRawData(PlayerKeys.REGISTERED, user.getRegistered());
        container.putRawData(PlayerKeys.KICK_COUNT, user.getTimesKicked());
        // GeoInfo
        container.putRawData(PlayerKeys.GEO_INFO, geoInformation.getOrDefault(uuid, Collections.emptyList()));
        // Ping
        container.putRawData(PlayerKeys.PING, pingData.get(uuid));
        // Nickname, only used for the raw server JSON.
        container.putRawData(PlayerKeys.NICKNAMES, nicknames.get(uuid));
        // PerServerContainer
        container.putRawData(PlayerKeys.PER_SERVER, perServerInfo.get(uuid));
        container.putCachingSupplier(PlayerKeys.SESSIONS, () -> {
            List<FinishedSession> playerSessions = sessions.getOrDefault(uuid, new ArrayList<>());
            container.getValue(PlayerKeys.ACTIVE_SESSION).map(ActiveSession::toFinishedSessionFromStillActive).ifPresent(playerSessions::add);
            return playerSessions;
        });
        // Calculating getters
        container.putCachingSupplier(PlayerKeys.WORLD_TIMES, () -> {
            WorldTimes worldTimes = new PerServerMutator(container.getUnsafe(PlayerKeys.PER_SERVER)).flatMapWorldTimes();
            container.getValue(PlayerKeys.ACTIVE_SESSION).ifPresent(session -> worldTimes.add(session.getExtraData(WorldTimes.class).orElseGet(WorldTimes::new)));
            return worldTimes;
        });
        container.putSupplier(PlayerKeys.BANNED, () -> PerServerMutator.forContainer(container).isBanned());
        container.putSupplier(PlayerKeys.OPERATOR, () -> PerServerMutator.forContainer(container).isOperator());
        container.putSupplier(PlayerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen());
        container.putSupplier(PlayerKeys.PLAYER_KILLS, () -> SessionsMutator.forContainer(container).toPlayerKillList());
        container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, () -> container.getUnsafe(PlayerKeys.PLAYER_KILLS).size());
        container.putSupplier(PlayerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount());
        container.putSupplier(PlayerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount());
        containers.add(container);
    }
    return containers;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PerServerMutator(com.djrapitops.plan.delivery.domain.mutators.PerServerMutator) PerServerContainer(com.djrapitops.plan.delivery.domain.container.PerServerContainer) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 94 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class UserIdentifierQueries method fetchPlayerUUIDsOfServer.

/**
 * Query database for all player UUIDs that have joined a server.
 *
 * @param serverUUID UUID of the Plan server.
 * @return Set of UUIDs.
 */
public static Query<Set<UUID>> fetchPlayerUUIDsOfServer(ServerUUID serverUUID) {
    String sql = SELECT + UsersTable.TABLE_NAME + '.' + UsersTable.USER_UUID + ',' + FROM + UsersTable.TABLE_NAME + INNER_JOIN + UserInfoTable.TABLE_NAME + " on " + UsersTable.TABLE_NAME + '.' + UsersTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + WHERE + UserInfoTable.SERVER_UUID + "=?";
    return new QueryStatement<Set<UUID>>(sql, 1000) {

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

        @Override
        public Set<UUID> processResults(ResultSet set) throws SQLException {
            Set<UUID> playerUUIDs = new HashSet<>();
            while (set.next()) {
                UUID playerUUID = UUID.fromString(set.getString(UsersTable.USER_UUID));
                playerUUIDs.add(playerUUID);
            }
            return playerUUIDs;
        }
    };
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 95 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionPlayerTableValuesAreInserted.

@Test
default void extensionPlayerTableValuesAreInserted() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register(new TableExtension());
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    Map<ServerUUID, List<ExtensionData>> ofPlayer = db().query(new ExtensionPlayerDataQuery(playerUUID));
    assertFalse(ofPlayer.isEmpty());
    List<ExtensionData> ofServer = ofPlayer.get(serverUUID());
    assertEquals(1, ofServer.size());
    ExtensionData extensionServerData = ofServer.get(0);
    List<ExtensionTabData> tabs = extensionServerData.getTabs();
    // No tab defined, should contain 1 tab
    assertEquals(1, tabs.size());
    ExtensionTabData tabData = tabs.get(0);
    List<ExtensionTableData> tableData = tabData.getTableData();
    assertEquals(1, tableData.size());
    ExtensionTableData table = tableData.get(0);
    HtmlTable expected = HtmlTable.fromExtensionTable(Table.builder().columnOne("first", Icon.called("gavel").build()).columnTwo("second", Icon.called("what").build()).columnThree("third", Icon.called("question").build()).addRow("value", 3, 0.5, 400L).build(), com.djrapitops.plan.delivery.rendering.html.icon.Color.AMBER);
    assertEquals(expected.toHtml(), table.getHtmlTable().toHtml());
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

ServerUUID (com.djrapitops.plan.identification.ServerUUID)105 UUID (java.util.UUID)26 ResultSet (java.sql.ResultSet)23 PreparedStatement (java.sql.PreparedStatement)21 Database (com.djrapitops.plan.storage.database.Database)17 Test (org.junit.jupiter.api.Test)17 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)14 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)12 Nickname (com.djrapitops.plan.delivery.domain.Nickname)11 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)11 Server (com.djrapitops.plan.identification.Server)11 HashMap (java.util.HashMap)11 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)9 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)9 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)9 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)9 Lists (com.djrapitops.plan.utilities.java.Lists)9 CallEvents (com.djrapitops.plan.extension.CallEvents)8 List (java.util.List)8 Map (java.util.Map)8