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));
}
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);
}
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));
}
Aggregations