Search in sources :

Example 11 with ServerUUID

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

the class PlayerKillsJSONResolver method getResponse.

private Response getResponse(Request request) {
    ServerUUID serverUUID = identifiers.getServerUUID(request);
    Optional<Long> timestamp = Identifiers.getTimestamp(request);
    JSONStorage.StoredJSON storedJSON = jsonResolverService.resolve(timestamp, DataID.KILLS, serverUUID, theUUID -> Collections.singletonMap("player_kills", jsonFactory.serverPlayerKillsAsJSONMap(theUUID)));
    return Response.builder().setMimeType(MimeType.JSON).setJSONContent(storedJSON.json).build();
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) JSONStorage(com.djrapitops.plan.delivery.webserver.cache.JSONStorage)

Example 12 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID 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();
    BukkitAFKListener.afkTracker.performedAction(playerUUID, time);
    String world = player.getWorld().getName();
    String gm = Optional.ofNullable(player.getGameMode()).map(gameMode -> gameMode.name()).orElse("Unknown");
    Database database = dbSystem.getDatabase();
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
    InetAddress address = player.getAddress().getAddress();
    Supplier<String> getHostName = () -> getHostname(player);
    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));
    }
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, player::getFirstPlayed, playerName, serverUUID, getHostName));
    database.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 : 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) HashMap(java.util.HashMap) Player(org.bukkit.entity.Player) Supplier(java.util.function.Supplier) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) EventHandler(org.bukkit.event.EventHandler) Inject(javax.inject.Inject) InetAddress(java.net.InetAddress) 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) Listener(org.bukkit.event.Listener) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) ServerName(com.djrapitops.plan.delivery.domain.ServerName) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) ServerInfo(com.djrapitops.plan.identification.ServerInfo) ExportSettings(com.djrapitops.plan.settings.config.paths.ExportSettings) UUID(java.util.UUID) Status(com.djrapitops.plan.gathering.listeners.Status) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) EventPriority(org.bukkit.event.EventPriority) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) PlayerKickEvent(org.bukkit.event.player.PlayerKickEvent) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) CallEvents(com.djrapitops.plan.extension.CallEvents) Optional(java.util.Optional) Processing(com.djrapitops.plan.processing.Processing) GeolocationCache(com.djrapitops.plan.gathering.geolocation.GeolocationCache) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Player(org.bukkit.entity.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 13 with ServerUUID

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

the class SessionQueriesTest method serverPreferencePieValuesAreCorrect.

@Test
default void serverPreferencePieValuesAreCorrect() {
    prepareForSessionSave();
    List<FinishedSession> server1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
    server1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    ServerUUID serverTwoUuid = TestConstants.SERVER_TWO_UUID;
    executeTransactions(new StoreServerInformationTransaction(new Server(serverTwoUuid, TestConstants.SERVER_TWO_NAME, "")));
    db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[1]));
    List<FinishedSession> server2Sessions = RandomData.randomSessions(serverTwoUuid, worlds, playerUUID, player2UUID);
    server2Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    Map<String, Long> expected = Maps.builder(String.class, Long.class).put(TestConstants.SERVER_NAME, new SessionsMutator(server1Sessions).toPlaytime()).put(TestConstants.SERVER_TWO_NAME, new SessionsMutator(server2Sessions).toPlaytime()).build();
    Map<String, Long> results = db().query(SessionQueries.playtimePerServer(Long.MIN_VALUE, Long.MAX_VALUE));
    assertEquals(expected, results);
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 14 with ServerUUID

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

the class SessionQueriesTest method playerSessionsAreFetchedByServerUUID.

@Test
default void playerSessionsAreFetchedByServerUUID() {
    prepareForSessionSave();
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    execute(DataStoreQueries.storeSession(session));
    forcePersistenceCheck();
    Map<ServerUUID, List<FinishedSession>> expected = Collections.singletonMap(serverUUID(), Collections.singletonList(session));
    Map<ServerUUID, List<FinishedSession>> fetched = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
    assertEquals(expected, fetched);
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 15 with ServerUUID

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

the class ShutdownSaveTest method storeNecessaryInformation.

private void storeNecessaryInformation() throws Exception {
    database.executeTransaction(new RemoveEverythingTransaction());
    ServerUUID serverUUID = TestConstants.SERVER_UUID;
    UUID playerUUID = TestConstants.PLAYER_ONE_UUID;
    String worldName = TestConstants.WORLD_ONE_NAME;
    database.executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID, "-", "")));
    database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> 0L, TestConstants.PLAYER_ONE_NAME));
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, worldName)).get();
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID)

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