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