Search in sources :

Example 6 with ServerUUID

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

the class ServerSettingsManager method checkDBForNewConfigSettings.

private void checkDBForNewConfigSettings(Database database) {
    File configFile = files.getConfigFile();
    long lastModified = configFile.exists() ? configFile.lastModified() : -1;
    Optional<ServerUUID> serverUUID = serverInfo.getServerUUIDSafe();
    if (!serverUUID.isPresent()) {
        return;
    }
    Optional<Config> foundConfig = database.query(new NewerConfigQuery(serverUUID.get(), lastModified));
    if (foundConfig.isPresent()) {
        try {
            new ConfigWriter(configFile.toPath()).write(foundConfig.get());
            logger.info("The Config was updated to match one on the Proxy. Reload for changes to take effect.");
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}
Also used : ConfigWriter(com.djrapitops.plan.settings.config.ConfigWriter) NewerConfigQuery(com.djrapitops.plan.storage.database.queries.objects.NewerConfigQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Config(com.djrapitops.plan.settings.config.Config) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) WatchedFile(com.djrapitops.plan.settings.upkeep.WatchedFile) File(java.io.File)

Example 7 with ServerUUID

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

the class PerServerAggregateQueries method lastSeenOnServers.

/**
 * Find last seen date on servers.
 *
 * @param playerUUID UUID of the player.
 * @return Map: Server UUID - Last seen epoch ms.
 */
public static Query<Map<ServerUUID, Long>> lastSeenOnServers(UUID playerUUID) {
    String sql = SELECT + "MAX(" + SessionsTable.SESSION_END + ") as last_seen, " + SessionsTable.SERVER_UUID + FROM + SessionsTable.TABLE_NAME + WHERE + SessionsTable.USER_UUID + "=?" + GROUP_BY + SessionsTable.SERVER_UUID;
    return new QueryStatement<Map<ServerUUID, Long>>(sql) {

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

        @Override
        public Map<ServerUUID, Long> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, Long> lastSeenMap = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(SessionsTable.SERVER_UUID));
                long lastSeen = set.getLong("last_seen");
                lastSeenMap.put(serverUUID, lastSeen);
            }
            return lastSeenMap;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 8 with ServerUUID

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

the class PerServerAggregateQueries method getQueryForCountOf.

private static QueryStatement<Map<ServerUUID, Integer>> getQueryForCountOf(UUID playerUUID, String sql, String column) {
    return new QueryStatement<Map<ServerUUID, Integer>>(sql) {

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

        @Override
        public Map<ServerUUID, Integer> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, Integer> killCountMap = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(SessionsTable.SERVER_UUID));
                int count = set.getInt(column);
                killCountMap.put(serverUUID, count);
            }
            return killCountMap;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 9 with ServerUUID

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

the class ServerAggregateQueries method serverUserCounts.

/**
 * Count how many users are on each server in the network.
 * <p>
 * Please note that counts can overlap as one user can join multiple servers.
 * Use {@link ServerAggregateQueries#baseUserCount()} if you want to count total number of users.
 *
 * @return Map: Server UUID - Count of users registered to that server
 */
public static Query<Map<ServerUUID, Integer>> serverUserCounts() {
    String sql = SELECT + "COUNT(1) as c, " + UserInfoTable.SERVER_UUID + FROM + UserInfoTable.TABLE_NAME + GROUP_BY + UserInfoTable.SERVER_UUID;
    return new QueryAllStatement<Map<ServerUUID, Integer>>(sql, 100) {

        @Override
        public Map<ServerUUID, Integer> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, Integer> ofServer = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(UserInfoTable.SERVER_UUID));
                int count = set.getInt("c");
                ofServer.put(serverUUID, count);
            }
            return ofServer;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet)

Example 10 with ServerUUID

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

the class PageFactory method inspectPluginTabs.

public PlayerPluginTab inspectPluginTabs(UUID playerUUID) {
    Database database = dbSystem.get().getDatabase();
    Map<ServerUUID, List<ExtensionData>> extensionPlayerData = database.query(new ExtensionPlayerDataQuery(playerUUID));
    if (extensionPlayerData.isEmpty()) {
        return new PlayerPluginTab("", Collections.emptyList(), formatters.get());
    }
    List<PlayerPluginTab> playerPluginTabs = new ArrayList<>();
    for (Map.Entry<ServerUUID, Server> entry : database.query(ServerQueries.fetchPlanServerInformation()).entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        String serverName = entry.getValue().getIdentifiableName();
        List<ExtensionData> ofServer = extensionPlayerData.get(serverUUID);
        if (ofServer == null) {
            continue;
        }
        playerPluginTabs.add(new PlayerPluginTab(serverName, ofServer, formatters.get()));
    }
    StringBuilder navs = new StringBuilder();
    StringBuilder tabs = new StringBuilder();
    playerPluginTabs.stream().sorted().forEach(tab -> {
        navs.append(tab.getNav());
        tabs.append(tab.getTab());
    });
    return new PlayerPluginTab(navs.toString(), tabs.toString());
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) ExtensionData(com.djrapitops.plan.extension.implementation.results.ExtensionData) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Database(com.djrapitops.plan.storage.database.Database)

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