Search in sources :

Example 1 with PlayersCollections

use of com.ebicep.warlords.database.repositories.player.PlayersCollections in project Warlords by ebicep.

the class MultipleCacheResolver method resolveCaches.

@Nonnull
@Override
public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) {
    Collection<Cache> caches = new ArrayList<>();
    List<Object> list = Arrays.asList(context.getArgs());
    for (PlayersCollections value : values()) {
        if (list.contains(value)) {
            caches.add(playersCacheManager.getCache(value.cacheName));
            break;
        }
    }
    if (caches.isEmpty()) {
        caches.add(playersCacheManager.getCache(LIFETIME.cacheName));
    }
    return caches;
}
Also used : ArrayList(java.util.ArrayList) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) Cache(org.springframework.cache.Cache) Nonnull(javax.annotation.Nonnull)

Example 2 with PlayersCollections

use of com.ebicep.warlords.database.repositories.player.PlayersCollections in project Warlords by ebicep.

the class LeaderboardManager method addHologramLeaderboards.

public static void addHologramLeaderboards(String sharedChainName, boolean init) {
    if (!Warlords.holographicDisplaysEnabled)
        return;
    if (!DatabaseManager.enabled)
        return;
    if (DatabaseManager.playerService == null || DatabaseManager.gameService == null)
        return;
    HolographicDisplaysAPI.get(Warlords.getInstance()).getHolograms().forEach(hologram -> {
        Location hologramLocation = hologram.getPosition().toLocation();
        if (!DatabaseGameBase.lastGameStatsLocation.equals(hologramLocation) && !DatabaseGameBase.topDamageLocation.equals(hologramLocation) && !DatabaseGameBase.topHealingLocation.equals(hologramLocation) && !DatabaseGameBase.topAbsorbedLocation.equals(hologramLocation) && !DatabaseGameBase.topDHPPerMinuteLocation.equals(hologramLocation) && !DatabaseGameBase.topDamageOnCarrierLocation.equals(hologramLocation) && !DatabaseGameBase.topHealingOnCarrierLocation.equals(hologramLocation)) {
            hologram.delete();
        }
    });
    putLeaderboards();
    if (enabled) {
        loaded = false;
        Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[Warlords] Adding Holograms");
        // caching all sorted players for each lifetime and weekly
        AtomicInteger loadedBoards = new AtomicInteger();
        long startTime = System.nanoTime();
        for (PlayersCollections value : PlayersCollections.values()) {
            // newSharedChain(sharedChainName)
            Warlords.newChain().asyncFirst(() -> DatabaseManager.playerService.findAll(value)).syncLast((collection) -> {
                addHologramsToGameType(value, collection, leaderboardGeneral.getGeneral(), "All Modes - " + value.name);
                addHologramsToGameType(value, collection, leaderboardGeneral.getComps(), "All Modes - Comps - " + value.name);
                addHologramsToGameType(value, collection, leaderboardGeneral.getPubs(), "All Modes - Pubs - " + value.name);
                addHologramsToGameType(value, collection, leaderboardCTF.getGeneral(), "CTF - All Queues - " + value.name);
                addHologramsToGameType(value, collection, leaderboardCTF.getComps(), "CTF - Comps - " + value.name);
                addHologramsToGameType(value, collection, leaderboardCTF.getPubs(), "CTF - Pubs - " + value.name);
                System.out.println("Loaded " + value.name + " leaderboards");
                loadedBoards.getAndIncrement();
                if (value == PlayersCollections.SEASON_5 && init) {
                    SRCalculator.databasePlayerCache = collection;
                    SRCalculator.recalculateSR();
                }
            }).execute();
        }
        // depending on what player has selected, set visibility
        new BukkitRunnable() {

            int counter = 0;

            @Override
            public void run() {
                if (loadedBoards.get() == 5) {
                    loaded = true;
                    long endTime = System.nanoTime();
                    long timeToLoad = (endTime - startTime) / 1000000;
                    System.out.println("Time it took for LB to load (ms): " + timeToLoad);
                    LeaderboardManager.playerGameHolograms.forEach((uuid, integer) -> {
                        LeaderboardManager.playerGameHolograms.put(uuid, DatabaseGameBase.previousGames.size() - 1);
                    });
                    Bukkit.getOnlinePlayers().forEach(player -> {
                        setLeaderboardHologramVisibility(player);
                        DatabaseGameBase.setGameHologramVisibility(player);
                        Warlords.playerScoreboards.get(player.getUniqueId()).giveMainLobbyScoreboard();
                    });
                    System.out.println("Set Hologram Visibility");
                    if (init) {
                        NPCManager.createGameNPC();
                    }
                    this.cancel();
                } else if (counter++ > 2 * 300) {
                    // holograms should all load within 5 minutes or ???
                    this.cancel();
                }
            }
        }.runTaskTimer(Warlords.getInstance(), 20, 10);
    }
}
Also used : Document(org.bson.Document) java.util(java.util) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) LeaderboardCategory(com.ebicep.warlords.database.leaderboards.sections.LeaderboardCategory) DatabaseGameBase(com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) LeaderboardCTF(com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardCTF) Location(org.bukkit.Location) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) World(org.bukkit.World) HolographicDisplaysAPI(me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI) Bukkit(org.bukkit.Bukkit) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Warlords(com.ebicep.warlords.Warlords) Hologram(me.filoghost.holographicdisplays.api.beta.hologram.Hologram) SRCalculator(com.ebicep.warlords.sr.SRCalculator) VisibilitySettings(me.filoghost.holographicdisplays.api.beta.hologram.VisibilitySettings) Collectors(java.util.stream.Collectors) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) LeaderboardGeneral(com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardGeneral) Stream(java.util.stream.Stream) NPCManager(com.ebicep.customentities.npc.NPCManager) LocationBuilder(com.ebicep.warlords.util.bukkit.LocationBuilder) ChatColor(org.bukkit.ChatColor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Location(org.bukkit.Location)

Example 3 with PlayersCollections

use of com.ebicep.warlords.database.repositories.player.PlayersCollections in project Warlords by ebicep.

the class CustomScoreboard method giveMainLobbyScoreboard.

public void giveMainLobbyScoreboard() {
    if (scoreboard.getObjective("health") != null) {
        scoreboard.getObjective("health").unregister();
        health = null;
    }
    for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
        for (Team team : scoreboard.getTeams()) {
            if (team.getName().equals(onlinePlayer.getName())) {
                team.unregister();
                break;
            }
        }
    }
    if (loaded) {
        LeaderboardCategory<?> leaderboardCategory = getLeaderboardCategoryFromPlayer(player);
        if (leaderboardCategory == null)
            return;
        Leaderboard leaderboard = leaderboardCategory.leaderboards.get(0);
        List<DatabasePlayer> databasePlayerList;
        switch(playerLeaderboardTime.getOrDefault(player.getUniqueId(), PlayersCollections.LIFETIME)) {
            case LIFETIME:
                databasePlayerList = leaderboard.getSortedAllTime();
                break;
            case SEASON_5:
                databasePlayerList = leaderboard.getSortedSeason5();
                break;
            case SEASON_4:
                databasePlayerList = leaderboard.getSortedSeason4();
                break;
            case WEEKLY:
                databasePlayerList = leaderboard.getSortedWeekly();
                break;
            case DAILY:
                databasePlayerList = leaderboard.getSortedDaily();
                break;
            default:
                databasePlayerList = leaderboard.getSortedAllTime();
                break;
        }
        LeaderboardManager.GameType selectedType = playerLeaderboardGameType.get(player.getUniqueId());
        LeaderboardManager.Category selectedCategory = playerLeaderboardCategory.get(player.getUniqueId());
        PlayersCollections selectedCollection = playerLeaderboardTime.get(player.getUniqueId());
        if (selectedType == null)
            selectedType = GameType.ALL;
        if (selectedCollection == null)
            selectedCategory = Category.ALL;
        if (selectedCollection == null)
            selectedCollection = PlayersCollections.LIFETIME;
        String scoreboardSelection = "";
        if (!selectedType.shortName.isEmpty()) {
            scoreboardSelection += selectedType.shortName + "/";
        }
        if (!selectedCategory.shortName.isEmpty()) {
            scoreboardSelection += selectedCategory.shortName + "/";
        }
        scoreboardSelection += selectedCollection.name;
        Optional<DatabasePlayer> optionalDatabasePlayer = databasePlayerList.stream().filter(databasePlayer -> databasePlayer.getUuid().equalsIgnoreCase(player.getUniqueId().toString())).findAny();
        if (optionalDatabasePlayer.isPresent()) {
            DatabasePlayer databasePlayer = optionalDatabasePlayer.get();
            AbstractDatabaseStatInformation playerInformation = leaderboardCategory.statFunction.apply(databasePlayer);
            giveNewSideBar(true, ChatColor.GRAY + scoreboardSelection, "", "Kills: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(playerInformation.getKills()), "Assists: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(playerInformation.getAssists()), "Deaths: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(playerInformation.getDeaths()), " " + "", "Wins: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(playerInformation.getWins()), "Losses: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(playerInformation.getLosses()), "  " + "", "Damage: " + ChatColor.RED + NumberFormat.addCommaAndRound(playerInformation.getDamage()), "Healing: " + ChatColor.DARK_GREEN + NumberFormat.addCommaAndRound(playerInformation.getHealing()), "Absorbed: " + ChatColor.GOLD + NumberFormat.addCommaAndRound(playerInformation.getAbsorbed()), "    ", "            " + ChatColor.YELLOW + ChatColor.BOLD + "Update", "     " + ChatColor.GOLD + ChatColor.BOLD + Warlords.VERSION);
        }
        return;
    }
    if (DatabaseManager.playerService == null) {
        clearSideBar();
        return;
    }
    DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
    giveNewSideBar(true, ChatColor.GRAY + "Lifetime", " ", "Kills: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(databasePlayer.getKills()), "Assists: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(databasePlayer.getAssists()), "Deaths: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(databasePlayer.getDeaths()), " " + "", "Wins: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(databasePlayer.getWins()), "Losses: " + ChatColor.GREEN + NumberFormat.addCommaAndRound(databasePlayer.getLosses()), "  " + "", "Damage: " + ChatColor.RED + NumberFormat.addCommaAndRound(databasePlayer.getDamage()), "Healing: " + ChatColor.DARK_GREEN + NumberFormat.addCommaAndRound(databasePlayer.getHealing()), "Absorbed: " + ChatColor.GOLD + NumberFormat.addCommaAndRound(databasePlayer.getAbsorbed()), "    ", "            " + ChatColor.YELLOW + ChatColor.BOLD + "Update", "     " + ChatColor.GOLD + ChatColor.BOLD + Warlords.VERSION);
}
Also used : Warlords(com.ebicep.warlords.Warlords) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) LeaderboardCategory(com.ebicep.warlords.database.leaderboards.sections.LeaderboardCategory) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) NumberFormat(com.ebicep.warlords.util.java.NumberFormat) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) List(java.util.List) AbstractDatabaseStatInformation(com.ebicep.warlords.database.repositories.player.pojos.AbstractDatabaseStatInformation) LeaderboardManager(com.ebicep.warlords.database.leaderboards.LeaderboardManager) Optional(java.util.Optional) ChatColor(org.bukkit.ChatColor) org.bukkit.scoreboard(org.bukkit.scoreboard) Leaderboard(com.ebicep.warlords.database.leaderboards.Leaderboard) Bukkit(org.bukkit.Bukkit) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Leaderboard(com.ebicep.warlords.database.leaderboards.Leaderboard) LeaderboardManager(com.ebicep.warlords.database.leaderboards.LeaderboardManager) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) AbstractDatabaseStatInformation(com.ebicep.warlords.database.repositories.player.pojos.AbstractDatabaseStatInformation) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)

Example 4 with PlayersCollections

use of com.ebicep.warlords.database.repositories.player.PlayersCollections in project Warlords by ebicep.

the class LeaderboardManager method addPlayerPositionLeaderboards.

public static void addPlayerPositionLeaderboards(Player player) {
    if (!Warlords.holographicDisplaysEnabled)
        return;
    if (enabled) {
        // leaderboards
        removeLeaderboardPlayerSpecificHolograms(player);
        PlayersCollections selectedTime = playerLeaderboardTime.get(player.getUniqueId());
        LeaderboardCategory<?> leaderboardCategory = getLeaderboardCategoryFromPlayer(player);
        if (leaderboardCategory == null)
            return;
        List<Hologram> playerHolograms = new ArrayList<>();
        for (Leaderboard leaderboard : leaderboardCategory.leaderboards) {
            Location location = leaderboard.getLocation().clone().add(0, -3.5, 0);
            Hologram hologram = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(location);
            List<DatabasePlayer> databasePlayers;
            switch(selectedTime) {
                case LIFETIME:
                    databasePlayers = leaderboard.getSortedAllTime();
                    break;
                case SEASON_5:
                    databasePlayers = leaderboard.getSortedSeason5();
                    break;
                case SEASON_4:
                    databasePlayers = leaderboard.getSortedSeason4();
                    break;
                case WEEKLY:
                    databasePlayers = leaderboard.getSortedWeekly();
                    break;
                case DAILY:
                    databasePlayers = leaderboard.getSortedDaily();
                    break;
                default:
                    return;
            }
            for (int i = 0; i < databasePlayers.size(); i++) {
                DatabasePlayer databasePlayer = databasePlayers.get(i);
                if (databasePlayer.getUuid().equals(player.getUniqueId().toString())) {
                    hologram.getLines().appendText(ChatColor.YELLOW.toString() + ChatColor.BOLD + (i + 1) + ". " + ChatColor.DARK_AQUA + ChatColor.BOLD + databasePlayer.getName() + ChatColor.GRAY + ChatColor.BOLD + " - " + ChatColor.YELLOW + ChatColor.BOLD + leaderboard.getStringFunction().apply(databasePlayer));
                    break;
                }
            }
            hologram.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.HIDDEN);
            hologram.getVisibilitySettings().setIndividualVisibility(player, VisibilitySettings.Visibility.VISIBLE);
            playerHolograms.add(hologram);
        }
        playerSpecificHolograms.put(player.getUniqueId(), playerHolograms);
    }
}
Also used : Hologram(me.filoghost.holographicdisplays.api.beta.hologram.Hologram) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Location(org.bukkit.Location)

Example 5 with PlayersCollections

use of com.ebicep.warlords.database.repositories.player.PlayersCollections in project Warlords by ebicep.

the class LeaderboardManager method setLeaderboardHologramVisibility.

public static void setLeaderboardHologramVisibility(Player player) {
    if (!Warlords.holographicDisplaysEnabled)
        return;
    if (!playerLeaderboardTime.containsKey(player.getUniqueId()) || playerLeaderboardTime.get(player.getUniqueId()) == null) {
        playerLeaderboardTime.put(player.getUniqueId(), PlayersCollections.LIFETIME);
    }
    PlayersCollections selectedTime = playerLeaderboardTime.get(player.getUniqueId());
    LeaderboardCategory<?> leaderboardCategory = getLeaderboardCategoryFromPlayer(player);
    getAllLeaderboardCategories().forEach(category -> {
        category.getAllHolograms().forEach(hologram -> hologram.getVisibilitySettings().setIndividualVisibility(player, VisibilitySettings.Visibility.HIDDEN));
    });
    assert leaderboardCategory != null;
    if (selectedTime == PlayersCollections.LIFETIME) {
        leaderboardCategory.getLifeTimeHolograms().forEach(hologram -> hologram.getVisibilitySettings().setIndividualVisibility(player, VisibilitySettings.Visibility.VISIBLE));
    } else if (selectedTime == PlayersCollections.SEASON_5) {
        leaderboardCategory.getSeason5Holograms().forEach(hologram -> hologram.getVisibilitySettings().setIndividualVisibility(player, VisibilitySettings.Visibility.VISIBLE));
    } else if (selectedTime == PlayersCollections.SEASON_4) {
        leaderboardCategory.getSeason4Holograms().forEach(hologram -> hologram.getVisibilitySettings().setIndividualVisibility(player, VisibilitySettings.Visibility.VISIBLE));
    } else if (selectedTime == PlayersCollections.WEEKLY) {
        leaderboardCategory.getWeeklyHolograms().forEach(hologram -> hologram.getVisibilitySettings().setIndividualVisibility(player, VisibilitySettings.Visibility.VISIBLE));
    } else {
        leaderboardCategory.getDailyHolograms().forEach(hologram -> hologram.getVisibilitySettings().setIndividualVisibility(player, VisibilitySettings.Visibility.VISIBLE));
    }
    if (Warlords.playerScoreboards.containsKey(player.getUniqueId())) {
        Warlords.playerScoreboards.get(player.getUniqueId()).giveMainLobbyScoreboard();
    }
    createLeaderboardSwitcherHologram(player);
    addPlayerPositionLeaderboards(player);
}
Also used : Document(org.bson.Document) java.util(java.util) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) LeaderboardCategory(com.ebicep.warlords.database.leaderboards.sections.LeaderboardCategory) DatabaseGameBase(com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) LeaderboardCTF(com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardCTF) Location(org.bukkit.Location) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) World(org.bukkit.World) HolographicDisplaysAPI(me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI) Bukkit(org.bukkit.Bukkit) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Warlords(com.ebicep.warlords.Warlords) Hologram(me.filoghost.holographicdisplays.api.beta.hologram.Hologram) SRCalculator(com.ebicep.warlords.sr.SRCalculator) VisibilitySettings(me.filoghost.holographicdisplays.api.beta.hologram.VisibilitySettings) Collectors(java.util.stream.Collectors) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) LeaderboardGeneral(com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardGeneral) Stream(java.util.stream.Stream) NPCManager(com.ebicep.customentities.npc.NPCManager) LocationBuilder(com.ebicep.warlords.util.bukkit.LocationBuilder) ChatColor(org.bukkit.ChatColor) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections)

Aggregations

PlayersCollections (com.ebicep.warlords.database.repositories.player.PlayersCollections)6 DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)5 Warlords (com.ebicep.warlords.Warlords)4 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)4 LeaderboardCategory (com.ebicep.warlords.database.leaderboards.sections.LeaderboardCategory)4 Hologram (me.filoghost.holographicdisplays.api.beta.hologram.Hologram)4 Bukkit (org.bukkit.Bukkit)4 ChatColor (org.bukkit.ChatColor)4 Location (org.bukkit.Location)4 Player (org.bukkit.entity.Player)4 NPCManager (com.ebicep.customentities.npc.NPCManager)3 LeaderboardCTF (com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardCTF)3 LeaderboardGeneral (com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardGeneral)3 DatabaseGameBase (com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase)3 SRCalculator (com.ebicep.warlords.sr.SRCalculator)3 LocationBuilder (com.ebicep.warlords.util.bukkit.LocationBuilder)3 java.util (java.util)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3