Search in sources :

Example 76 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID 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[] asArray = StringUtils.split(serialized, ';');
    if (asArray.length < 9)
        return Optional.empty();
    // Note for the future: Use length to determine version of serialized class
    Gson gson = new Gson();
    UUID playerUUID = UUID.fromString(asArray[0]);
    ServerUUID serverUUID = ServerUUID.fromString(asArray[1]);
    long start = Long.parseLong(asArray[2]);
    long end = Long.parseLong(asArray[3]);
    long afkTime = Long.parseLong(asArray[4]);
    DataMap extraData = new DataMap();
    extraData.put(WorldTimes.class, gson.fromJson(asArray[5], WorldTimes.class));
    extraData.put(PlayerKills.class, gson.fromJson(asArray[6], PlayerKills.class));
    extraData.put(MobKillCounter.class, gson.fromJson(asArray[7], MobKillCounter.class));
    extraData.put(DeathCounter.class, gson.fromJson(asArray[8], DeathCounter.class));
    return Optional.of(new FinishedSession(playerUUID, serverUUID, start, end, afkTime, extraData));
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Gson(com.google.gson.Gson) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID)

Example 77 with ServerUUID

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

the class UserInfoQueries method fetchUserInformationOfServer.

/**
 * Query database for all User information of a specific server.
 *
 * @param serverUUID UUID of the Plan server.
 * @return Map: Player UUID - user information
 */
public static Query<Map<UUID, UserInfo>> fetchUserInformationOfServer(ServerUUID serverUUID) {
    String sql = SELECT + UserInfoTable.REGISTERED + ',' + UserInfoTable.BANNED + ',' + UserInfoTable.JOIN_ADDRESS + ',' + UserInfoTable.OP + ',' + UserInfoTable.USER_UUID + ',' + UserInfoTable.SERVER_UUID + FROM + UserInfoTable.TABLE_NAME + WHERE + UserInfoTable.SERVER_UUID + "=?";
    return new QueryStatement<Map<UUID, UserInfo>>(sql, 1000) {

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

        @Override
        public Map<UUID, UserInfo> processResults(ResultSet set) throws SQLException {
            Map<UUID, UserInfo> userInformation = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(UserInfoTable.SERVER_UUID));
                UUID uuid = UUID.fromString(set.getString(UserInfoTable.USER_UUID));
                long registered = set.getLong(UserInfoTable.REGISTERED);
                boolean banned = set.getBoolean(UserInfoTable.BANNED);
                boolean op = set.getBoolean(UserInfoTable.OP);
                String joinAddress = set.getString(UserInfoTable.JOIN_ADDRESS);
                userInformation.put(uuid, new UserInfo(uuid, serverUUID, registered, op, joinAddress, banned));
            }
            return userInformation;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) ResultSet(java.sql.ResultSet) UserInfo(com.djrapitops.plan.gathering.domain.UserInfo) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 78 with ServerUUID

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

the class UserInfoQueries method fetchUserInformationOfUser.

/**
 * Query database for User information of a specific player.
 *
 * @param playerUUID UUID of the player.
 * @return List of UserInfo objects, one for each server where the player has played.
 */
public static Query<Set<UserInfo>> fetchUserInformationOfUser(UUID playerUUID) {
    String sql = SELECT + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.REGISTERED + ',' + UserInfoTable.BANNED + ',' + UserInfoTable.OP + ',' + UserInfoTable.SERVER_UUID + ',' + UserInfoTable.JOIN_ADDRESS + FROM + UserInfoTable.TABLE_NAME + WHERE + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + "=?";
    return new QueryStatement<Set<UserInfo>>(sql) {

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

        @Override
        public Set<UserInfo> processResults(ResultSet set) throws SQLException {
            Set<UserInfo> userInformation = new HashSet<>();
            while (set.next()) {
                long registered = set.getLong(UserInfoTable.REGISTERED);
                boolean op = set.getBoolean(UserInfoTable.OP);
                boolean banned = set.getBoolean(UserInfoTable.BANNED);
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(UserInfoTable.SERVER_UUID));
                String joinAddress = set.getString(UserInfoTable.JOIN_ADDRESS);
                userInformation.add(new UserInfo(playerUUID, serverUUID, registered, op, joinAddress, banned));
            }
            return userInformation;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) ResultSet(java.sql.ResultSet) UserInfo(com.djrapitops.plan.gathering.domain.UserInfo) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 79 with ServerUUID

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

the class UserInfoQueries method uuidsOfRegisteredBetween.

public static Query<Set<UUID>> uuidsOfRegisteredBetween(long after, long before, List<ServerUUID> serverUUIDs) {
    String sql = SELECT + DISTINCT + UserInfoTable.USER_UUID + FROM + UserInfoTable.TABLE_NAME + WHERE + UserInfoTable.REGISTERED + ">=?" + AND + UserInfoTable.REGISTERED + "<=?" + AND + UserInfoTable.SERVER_UUID + " IN ('" + new TextStringBuilder().appendWithSeparators(serverUUIDs, "','") + "')";
    return new QueryStatement<Set<UUID>>(sql) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setLong(1, after);
            statement.setLong(2, before);
        }

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

Example 80 with ServerUUID

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

the class UserInfoQueries method fetchAllUserInformation.

/**
 * Query database for user information.
 * <p>
 * The user information does not contain player names.
 *
 * @return Map: Server UUID - List of user information
 */
public static Query<Map<ServerUUID, List<UserInfo>>> fetchAllUserInformation() {
    String sql = SELECT + UserInfoTable.REGISTERED + ',' + UserInfoTable.BANNED + ',' + UserInfoTable.OP + ',' + UserInfoTable.USER_UUID + ',' + UserInfoTable.SERVER_UUID + ',' + UserInfoTable.JOIN_ADDRESS + FROM + UserInfoTable.TABLE_NAME;
    return new QueryAllStatement<Map<ServerUUID, List<UserInfo>>>(sql, 50000) {

        @Override
        public Map<ServerUUID, List<UserInfo>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, List<UserInfo>> serverMap = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(UserInfoTable.SERVER_UUID));
                UUID uuid = UUID.fromString(set.getString(UserInfoTable.USER_UUID));
                List<UserInfo> userInfos = serverMap.computeIfAbsent(serverUUID, Lists::create);
                long registered = set.getLong(UserInfoTable.REGISTERED);
                boolean banned = set.getBoolean(UserInfoTable.BANNED);
                boolean op = set.getBoolean(UserInfoTable.OP);
                String joinAddress = set.getString(UserInfoTable.JOIN_ADDRESS);
                userInfos.add(new UserInfo(uuid, serverUUID, registered, op, joinAddress, banned));
            }
            return serverMap;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) UserInfo(com.djrapitops.plan.gathering.domain.UserInfo) QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) Lists(com.djrapitops.plan.utilities.java.Lists) ResultSet(java.sql.ResultSet) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

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