Search in sources :

Example 1 with ExtensionPlayerDataQuery

use of com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery 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)

Example 2 with ExtensionPlayerDataQuery

use of com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionPlayerValuesAreStored.

@Test
default void extensionPlayerValuesAreStored() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register(new PlayerExtension());
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    Map<ServerUUID, List<ExtensionData>> playerDataByServerUUID = db().query(new ExtensionPlayerDataQuery(playerUUID));
    List<ExtensionData> ofServer = playerDataByServerUUID.get(serverUUID());
    assertNotNull(ofServer);
    assertFalse(ofServer.isEmpty());
    ExtensionData extensionPlayerData = ofServer.get(0);
    List<ExtensionTabData> tabs = extensionPlayerData.getTabs();
    // No tab defined, should contain 1 tab
    assertEquals(1, tabs.size());
    ExtensionTabData tabData = tabs.get(0);
    OptionalAssert.equals("5", tabData.getNumber("value").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("No", tabData.getBoolean("boolVal").map(ExtensionBooleanData::getFormattedValue));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("0.5", tabData.getPercentage("percentageVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("Something", tabData.getString("stringVal").map(ExtensionStringData::getFormattedValue));
    OptionalAssert.equals("Group", tabData.getString("groupVal").map(ExtensionStringData::getFormattedValue));
}
Also used : 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) 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) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 3 with ExtensionPlayerDataQuery

use of com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method removeEverythingRemovesPlayerExtensionData.

@Test
default void removeEverythingRemovesPlayerExtensionData() {
    extensionPlayerValuesAreStored();
    db().executeTransaction(new RemoveEverythingTransaction());
    assertTrue(db().query(new ExtensionPlayerDataQuery(playerUUID)).isEmpty());
}
Also used : ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) Test(org.junit.jupiter.api.Test)

Example 4 with ExtensionPlayerDataQuery

use of com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionPlayerTableValuesAreInserted.

@Test
default void extensionPlayerTableValuesAreInserted() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register(new TableExtension());
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    Map<ServerUUID, List<ExtensionData>> ofPlayer = db().query(new ExtensionPlayerDataQuery(playerUUID));
    assertFalse(ofPlayer.isEmpty());
    List<ExtensionData> ofServer = ofPlayer.get(serverUUID());
    assertEquals(1, ofServer.size());
    ExtensionData extensionServerData = ofServer.get(0);
    List<ExtensionTabData> tabs = extensionServerData.getTabs();
    // No tab defined, should contain 1 tab
    assertEquals(1, tabs.size());
    ExtensionTabData tabData = tabs.get(0);
    List<ExtensionTableData> tableData = tabData.getTableData();
    assertEquals(1, tableData.size());
    ExtensionTableData table = tableData.get(0);
    HtmlTable expected = HtmlTable.fromExtensionTable(Table.builder().columnOne("first", Icon.called("gavel").build()).columnTwo("second", Icon.called("what").build()).columnThree("third", Icon.called("question").build()).addRow("value", 3, 0.5, 400L).build(), com.djrapitops.plan.delivery.rendering.html.icon.Color.AMBER);
    assertEquals(expected.toHtml(), table.getHtmlTable().toHtml());
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

ExtensionPlayerDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery)4 ServerUUID (com.djrapitops.plan.identification.ServerUUID)3 Test (org.junit.jupiter.api.Test)3 HtmlTable (com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable)2 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)2 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)2 List (java.util.List)2 CallEvents (com.djrapitops.plan.extension.CallEvents)1 DataExtension (com.djrapitops.plan.extension.DataExtension)1 NotReadyException (com.djrapitops.plan.extension.NotReadyException)1 com.djrapitops.plan.extension.annotation (com.djrapitops.plan.extension.annotation)1 ExtensionDataBuilder (com.djrapitops.plan.extension.builder.ExtensionDataBuilder)1 Color (com.djrapitops.plan.extension.icon.Color)1 Icon (com.djrapitops.plan.extension.icon.Icon)1 com.djrapitops.plan.extension.implementation.results (com.djrapitops.plan.extension.implementation.results)1 ExtensionData (com.djrapitops.plan.extension.implementation.results.ExtensionData)1 ExtensionServerDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery)1 ExtensionServerTableDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery)1 RemoveUnsatisfiedConditionalPlayerResultsTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction)1 RemoveUnsatisfiedConditionalServerResultsTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction)1