Search in sources :

Example 16 with WorldNameStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionPlayerValuesCanBeQueriedAsTableData.

@Test
default void extensionPlayerValuesCanBeQueriedAsTableData() {
    extensionPlayerValuesAreStored();
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
    // Store a session to check against issue https://github.com/plan-player-analytics/Plan/issues/1039
    ActiveSession session = new ActiveSession(playerUUID, serverUUID(), 32345L, worlds[0], "SURVIVAL");
    session.getExtraData().put(WorldTimes.class, RandomData.randomWorldTimes(worlds));
    db().executeTransaction(new StoreSessionTransaction(session.toFinishedSession(42345L)));
    Map<UUID, ExtensionTabData> result = db().query(new ExtensionServerTableDataQuery(serverUUID(), 50));
    assertEquals(1, result.size());
    ExtensionTabData playerData = result.get(playerUUID);
    assertNotNull(playerData);
    OptionalAssert.equals("5", playerData.getNumber("value").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("No", playerData.getBoolean("boolVal").map(ExtensionBooleanData::getFormattedValue));
    OptionalAssert.equals("0.5", playerData.getDouble("doubleVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("0.5", playerData.getPercentage("percentageVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("Something", playerData.getString("stringVal").map(ExtensionStringData::getFormattedValue));
}
Also used : StoreSessionTransaction(com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach) com.djrapitops.plan.extension.annotation(com.djrapitops.plan.extension.annotation) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Map(java.util.Map) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) TestConstants(utilities.TestConstants) NotReadyException(com.djrapitops.plan.extension.NotReadyException) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Table(com.djrapitops.plan.extension.table.Table) ExtensionDataBuilder(com.djrapitops.plan.extension.builder.ExtensionDataBuilder) TestErrorLogger(utilities.TestErrorLogger) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) DataExtension(com.djrapitops.plan.extension.DataExtension) OptionalAssert(utilities.OptionalAssert) Color(com.djrapitops.plan.extension.icon.Color) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) Icon(com.djrapitops.plan.extension.icon.Icon) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) UUID(java.util.UUID) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) CallEvents(com.djrapitops.plan.extension.CallEvents) RandomData(utilities.RandomData) com.djrapitops.plan.extension.implementation.results(com.djrapitops.plan.extension.implementation.results) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) StoreSessionTransaction(com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 17 with WorldNameStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction in project Plan by plan-player-analytics.

the class JoinAddressQueriesTest method joinAddressUpdateIsUniquePerServer.

@Test
default void joinAddressUpdateIsUniquePerServer() {
    joinAddressCanBeUnknown();
    db().executeTransaction(TestData.storeServers());
    db().executeTransaction(new WorldNameStoreTransaction(TestConstants.SERVER_TWO_UUID, worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(TestConstants.SERVER_TWO_UUID, worlds[1]));
    FinishedSession session = RandomData.randomSession(TestConstants.SERVER_TWO_UUID, worlds, playerUUID, player2UUID);
    String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get();
    session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress));
    db().executeTransaction(new StoreSessionTransaction(session));
    Map<String, Integer> expected1 = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1);
    Map<String, Integer> result1 = db().query(JoinAddressQueries.latestJoinAddresses(serverUUID()));
    assertEquals(expected1, result1);
    Map<String, Integer> expected2 = Map.of(expectedAddress, 1);
    Map<String, Integer> result2 = db().query(JoinAddressQueries.latestJoinAddresses(TestConstants.SERVER_TWO_UUID));
    assertEquals(expected2, result2);
}
Also used : StoreSessionTransaction(com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) Test(org.junit.jupiter.api.Test)

Example 18 with WorldNameStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction in project Plan by plan-player-analytics.

the class GameModeChangeListener method actOnEvent.

private void actOnEvent(ServerPlayerEntity player, GameMode newGameMode) {
    UUID uuid = player.getUuid();
    long time = System.currentTimeMillis();
    String gameMode = newGameMode.name();
    String worldName = player.getServerWorld().getRegistryKey().getValue().toString();
    dbSystem.getDatabase().executeTransaction(new WorldNameStoreTransaction(serverInfo.getServerUUID(), worldName));
    worldAliasSettings.addWorld(worldName);
    Optional<ActiveSession> cachedSession = SessionCache.getCachedSession(uuid);
    cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) UUID(java.util.UUID)

Aggregations

WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)18 UUID (java.util.UUID)10 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)9 StoreSessionTransaction (com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction)7 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)5 PlayerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction)5 ServerUUID (com.djrapitops.plan.identification.ServerUUID)4 Test (org.junit.jupiter.api.Test)4 Database (com.djrapitops.plan.storage.database.Database)3 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)3 Player (cn.nukkit.Player)2 DataMap (com.djrapitops.plan.gathering.domain.DataMap)2 DBSystem (com.djrapitops.plan.storage.database.DBSystem)2 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)2 Player (org.bukkit.entity.Player)2 HtmlTable (com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable)1 CallEvents (com.djrapitops.plan.extension.CallEvents)1 DataExtension (com.djrapitops.plan.extension.DataExtension)1 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)1 NotReadyException (com.djrapitops.plan.extension.NotReadyException)1