Search in sources :

Example 6 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer in project Plan by plan-player-analytics.

the class DataUtilityCommands method onInGame.

public void onInGame(CMDSender sender, Arguments arguments) {
    String identifier = arguments.concatenate(" ");
    UUID playerUUID = identifiers.getPlayerUUID(identifier);
    UUID senderUUID = sender.getUUID().orElse(null);
    if (playerUUID == null)
        playerUUID = senderUUID;
    if (playerUUID == null) {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_PLAYER_NOT_FOUND, identifier));
    }
    PlayerContainer player = dbSystem.getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
    if (!player.getValue(PlayerKeys.REGISTERED).isPresent()) {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_PLAYER_NOT_FOUND_REGISTER, identifier));
    }
    if (sender.hasPermission(Permissions.INGAME_OTHER) || playerUUID.equals(senderUUID)) {
        sendInGameMessages(sender, player);
    } else {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_NO_PERMISSION) + " (" + Permissions.INGAME_OTHER.get() + ')');
    }
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer)

Example 7 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer in project Plan by plan-player-analytics.

the class PageFactory method playerPage.

public Page playerPage(UUID playerUUID) throws IOException {
    Database db = dbSystem.get().getDatabase();
    PlayerContainer player = db.query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
    if (config.get().isTrue(PluginSettings.FRONTEND_BETA)) {
        String reactHtml = getResource("index.html");
        return () -> reactHtml;
    }
    return new PlayerPage(getResource("player.html"), player, versionChecker.get(), config.get(), this, theme.get(), formatters.get(), serverInfo.get(), locale.get());
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) Database(com.djrapitops.plan.storage.database.Database)

Example 8 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer in project Plan by plan-player-analytics.

the class PlayerContainerQuery method executeQuery.

@Override
public PlayerContainer executeQuery(SQLDB db) {
    PlayerContainer container = new PlayerContainer();
    container.putRawData(PlayerKeys.UUID, uuid);
    Key<BaseUser> baseUserKey = new Key<>(BaseUser.class, "BASE_USER");
    container.putSupplier(baseUserKey, () -> db.query(BaseUserQueries.fetchBaseUserOfPlayer(uuid)).orElse(null));
    container.putSupplier(PlayerKeys.REGISTERED, () -> container.getValue(baseUserKey).map(BaseUser::getRegistered).orElse(null));
    container.putSupplier(PlayerKeys.NAME, () -> container.getValue(baseUserKey).map(BaseUser::getName).orElse(null));
    container.putSupplier(PlayerKeys.KICK_COUNT, () -> container.getValue(baseUserKey).map(BaseUser::getTimesKicked).orElse(null));
    container.putCachingSupplier(PlayerKeys.GEO_INFO, () -> db.query(GeoInfoQueries.fetchPlayerGeoInformation(uuid)));
    container.putCachingSupplier(PlayerKeys.PING, () -> db.query(PingQueries.fetchPingDataOfPlayer(uuid)));
    container.putCachingSupplier(PlayerKeys.NICKNAMES, () -> db.query(NicknameQueries.fetchNicknameDataOfPlayer(uuid)));
    container.putCachingSupplier(PlayerKeys.PER_SERVER, () -> db.query(new PerServerContainerQuery(uuid)));
    container.putSupplier(PlayerKeys.BANNED, () -> new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).isBanned());
    container.putSupplier(PlayerKeys.OPERATOR, () -> new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).isOperator());
    container.putCachingSupplier(PlayerKeys.SESSIONS, () -> {
        List<FinishedSession> sessions = new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).flatMapSessions();
        container.getValue(PlayerKeys.ACTIVE_SESSION).map(ActiveSession::toFinishedSessionFromStillActive).ifPresent(sessions::add);
        return sessions;
    });
    container.putCachingSupplier(PlayerKeys.WORLD_TIMES, () -> {
        WorldTimes worldTimes = db.query(WorldTimesQueries.fetchPlayerTotalWorldTimes(uuid));
        container.getValue(PlayerKeys.ACTIVE_SESSION).ifPresent(session -> worldTimes.add(session.getExtraData(WorldTimes.class).orElseGet(WorldTimes::new)));
        return worldTimes;
    });
    container.putSupplier(PlayerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen());
    container.putSupplier(PlayerKeys.PLAYER_KILLS, () -> db.query(KillQueries.fetchPlayerKillsOfPlayer(uuid)));
    container.putSupplier(PlayerKeys.PLAYER_DEATHS_KILLS, () -> db.query(KillQueries.fetchPlayerDeathsOfPlayer(uuid)));
    container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, () -> container.getValue(PlayerKeys.PLAYER_KILLS).map(Collection::size).orElse(0));
    container.putSupplier(PlayerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount());
    container.putSupplier(PlayerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount());
    SessionCache.getCachedSession(uuid).ifPresent(session -> container.putRawData(PlayerKeys.ACTIVE_SESSION, session));
    return container;
}
Also used : PerServerContainer(com.djrapitops.plan.delivery.domain.container.PerServerContainer) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) PerServerMutator(com.djrapitops.plan.delivery.domain.mutators.PerServerMutator) Collection(java.util.Collection) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) Key(com.djrapitops.plan.delivery.domain.keys.Key)

Example 9 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer in project Plan by plan-player-analytics.

the class NukkitPlaceholderRegistrar method getPlayer.

private PlayerContainer getPlayer(Player player) {
    UUID uuid = player.getUniqueId();
    PlayerContainer container = system.getDatabaseSystem().getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid));
    SessionCache.getCachedSession(uuid).ifPresent(session -> container.putRawData(PlayerKeys.ACTIVE_SESSION, session));
    return container;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) UUID(java.util.UUID)

Example 10 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer in project Plan by plan-player-analytics.

the class PlayerJSONCreator method createJSONAsMap.

public Map<String, Object> createJSONAsMap(UUID playerUUID) {
    Database db = dbSystem.getDatabase();
    Map<ServerUUID, String> serverNames = db.query(ServerQueries.fetchServerNames());
    String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
    PlayerContainer player = db.query(new PlayerContainerQuery(playerUUID));
    SessionsMutator sessionsMutator = SessionsMutator.forContainer(player);
    Map<ServerUUID, WorldTimes> worldTimesPerServer = PerServerMutator.forContainer(player).worldTimesPerServer();
    List<Map<String, Object>> serverAccordion = new ServerAccordion(player, serverNames, graphs, year, timeAmount, locale.getString(GenericLang.UNKNOWN)).asMaps();
    List<PlayerKill> kills = player.getValue(PlayerKeys.PLAYER_KILLS).orElse(Collections.emptyList());
    List<PlayerKill> deaths = player.getValue(PlayerKeys.PLAYER_DEATHS_KILLS).orElse(Collections.emptyList());
    PingMutator.forContainer(player).addPingToSessions(sessionsMutator.all());
    Map<String, Object> data = new HashMap<>();
    long now = System.currentTimeMillis();
    data.put("timestamp", now);
    data.put("timestamp_f", year.apply(now));
    data.put("info", createInfoJSONMap(player, serverNames));
    data.put("online_activity", createOnlineActivityJSONMap(sessionsMutator));
    data.put("kill_data", createPvPPvEMap(player));
    data.put("nicknames", player.getValue(PlayerKeys.NICKNAMES).map(nicks -> Nickname.fromDataNicknames(nicks, serverNames, year)).orElse(Collections.emptyList()));
    data.put("connections", player.getValue(PlayerKeys.GEO_INFO).map(geoInfo -> ConnectionInfo.fromGeoInfo(geoInfo, year)).orElse(Collections.emptyList()));
    data.put("player_kills", new PlayerKillMutator(kills).filterNonSelfKills().toJSONAsMap(formatters));
    data.put("player_deaths", new PlayerKillMutator(deaths).toJSONAsMap(formatters));
    data.put("sessions", sessionsMutator.sort(new DateHolderRecentComparator()).toServerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters));
    data.put("sessions_per_page", config.get(DisplaySettings.SESSIONS_PER_PAGE));
    data.put("servers", serverAccordion);
    data.put("punchcard_series", graphs.special().punchCard(sessionsMutator).getDots());
    WorldPie worldPie = graphs.pie().worldPie(player.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes()));
    data.put("world_pie_series", worldPie.getSlices());
    data.put("gm_series", worldPie.toHighChartsDrillDownMaps());
    data.put("calendar_series", graphs.calendar().playerCalendar(player).getEntries());
    data.put("server_pie_series", graphs.pie().serverPreferencePie(serverNames, worldTimesPerServer).getSlices());
    data.put("server_pie_colors", pieColors);
    data.put("ping_graph", createPingGraphJson(player));
    // Monday
    data.put("first_day", 1);
    data.put("extensions", playerExtensionData(playerUUID));
    return data;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PlayerContainerQuery(com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) Database(com.djrapitops.plan.storage.database.Database) DateHolderRecentComparator(com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator) WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)

Aggregations

PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)16 ServerUUID (com.djrapitops.plan.identification.ServerUUID)5 GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)4 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)3 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)3 PlayerContainerQuery (com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery)3 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)3 PerServerContainer (com.djrapitops.plan.delivery.domain.container.PerServerContainer)2 Key (com.djrapitops.plan.delivery.domain.keys.Key)2 PlayerKeys (com.djrapitops.plan.delivery.domain.keys.PlayerKeys)2 PerServerMutator (com.djrapitops.plan.delivery.domain.mutators.PerServerMutator)2 BaseUser (com.djrapitops.plan.gathering.domain.BaseUser)2 Ping (com.djrapitops.plan.gathering.domain.Ping)2 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)2 Database (com.djrapitops.plan.storage.database.Database)2 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)2 Patch (com.djrapitops.plan.storage.database.transactions.patches.Patch)2 java.util (java.util)2 Test (org.junit.jupiter.api.Test)2 Arguments (com.djrapitops.plan.commands.use.Arguments)1