Search in sources :

Example 1 with ChallengeAchievements

use of com.ebicep.warlords.achievements.types.ChallengeAchievements in project Warlords by ebicep.

the class AchievementsMenu method openChallengeAchievementHistoryMenu.

public static void openChallengeAchievementHistoryMenu(Player player, GameMode gameMode, ChallengeAchievements achievement) {
    if (DatabaseManager.playerService == null)
        return;
    DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
    List<ChallengeAchievements.ChallengeAchievementRecord> achievementRecords = databasePlayer.getAchievements().stream().filter(ChallengeAchievements.ChallengeAchievementRecord.class::isInstance).map(ChallengeAchievements.ChallengeAchievementRecord.class::cast).filter(t -> t.getAchievement() == achievement).collect(Collectors.toList());
    Menu menu = new Menu("Achievement History", 9 * 6);
    int x = 0;
    int y = 0;
    for (ChallengeAchievements.ChallengeAchievementRecord achievementRecord : achievementRecords) {
        menu.setItem(x, y, new ItemBuilder(Material.BOOK).name(ChatColor.GREEN + achievement.name).lore(ChatColor.GRAY + DATE_FORMAT.format(achievementRecord.getDate())).get(), (m, e) -> {
        });
        x++;
        if (x == 9) {
            x = 0;
            y++;
        }
    }
    menu.setItem(3, 5, MENU_BACK, (m, e) -> openChallengeAchievementsMenu(player, gameMode));
    menu.setItem(4, 5, MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.openForPlayer(player);
}
Also used : ItemFlag(org.bukkit.inventory.ItemFlag) TieredAchievements(com.ebicep.warlords.achievements.types.TieredAchievements) Menu(com.ebicep.warlords.menu.Menu) Arrays(java.util.Arrays) Enchantment(org.bukkit.enchantments.Enchantment) SimpleDateFormat(java.text.SimpleDateFormat) Warlords(com.ebicep.warlords.Warlords) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) WordWrap(com.ebicep.warlords.util.bukkit.WordWrap) Player(org.bukkit.entity.Player) UUID(java.util.UUID) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Collectors(java.util.stream.Collectors) ChallengeAchievements(com.ebicep.warlords.achievements.types.ChallengeAchievements) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) List(java.util.List) ChatColor(org.bukkit.ChatColor) GameMode(com.ebicep.warlords.game.GameMode) Material(org.bukkit.Material) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) ChallengeAchievements(com.ebicep.warlords.achievements.types.ChallengeAchievements) Menu(com.ebicep.warlords.menu.Menu) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)

Example 2 with ChallengeAchievements

use of com.ebicep.warlords.achievements.types.ChallengeAchievements in project Warlords by ebicep.

the class WarlordsPlayer method unlockAchievement.

public void unlockAchievement(ChallengeAchievements achievement) {
    achievementsUnlocked.add(new ChallengeAchievements.ChallengeAchievementRecord(achievement));
    if (entity instanceof Player) {
        DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(uuid);
        // only display achievement if they have never got it before
        if (!databasePlayer.hasAchievement(achievement)) {
            achievement.sendAchievementUnlockMessage((Player) entity);
            achievement.sendAchievementUnlockMessageToOthers(this);
        }
    }
    System.out.println(name + " unlocked achievement: " + achievement.name);
}
Also used : Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) ChallengeAchievements(com.ebicep.warlords.achievements.types.ChallengeAchievements) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)

Example 3 with ChallengeAchievements

use of com.ebicep.warlords.achievements.types.ChallengeAchievements in project Warlords by ebicep.

the class AchievementsMenu method openChallengeAchievementsMenu.

public static void openChallengeAchievementsMenu(Player player, GameMode gameMode) {
    if (DatabaseManager.playerService == null)
        return;
    DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
    List<ChallengeAchievements> achievementRecords = databasePlayer.getAchievements().stream().filter(abstractAchievementRecord -> abstractAchievementRecord.getAchievement() instanceof ChallengeAchievements).map(Achievement.AbstractAchievementRecord::getAchievement).map(ChallengeAchievements.class::cast).collect(Collectors.toList());
    List<ChallengeAchievements> challengeAchievements = Arrays.stream(ChallengeAchievements.values()).filter(achievements -> achievements.gameMode == gameMode).collect(Collectors.toList());
    Menu menu = new Menu("Challenge Achievements", 9 * 6);
    int x = 0;
    int y = 0;
    for (ChallengeAchievements achievement : challengeAchievements) {
        boolean hasAchievement = achievementRecords.stream().anyMatch(achievements -> achievements == achievement);
        ItemBuilder itemBuilder = new ItemBuilder(hasAchievement ? Warlords.getHead(UUID.fromString("9f2b2230-3b2c-4b0f-a141-d7b598e236c7")) : Warlords.getHead(UUID.fromString("70b6981a-6ae8-4e76-8aeb-0fcd510f4be7"))).name(ChatColor.GREEN + achievement.name + " - " + (achievement.spec == null ? "General" : achievement.spec.name)).lore(ChatColor.WHITE + WordWrap.wrapWithNewline(achievement.description, 200) + (hasAchievement ? "\n\n" + ChatColor.GREEN + "Unlocked!" : "")).flags(ItemFlag.HIDE_ENCHANTS);
        if (hasAchievement) {
            itemBuilder.enchant(Enchantment.OXYGEN, 1);
        }
        menu.setItem(x, y, itemBuilder.get(), (m, e) -> openChallengeAchievementHistoryMenu(player, gameMode, achievement));
        x++;
        if (x == 9) {
            x = 0;
            y++;
        }
    }
    menu.setItem(3, 5, MENU_BACK, (m, e) -> openAchievementsMenu(player));
    menu.setItem(4, 5, MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.openForPlayer(player);
}
Also used : ItemFlag(org.bukkit.inventory.ItemFlag) TieredAchievements(com.ebicep.warlords.achievements.types.TieredAchievements) Menu(com.ebicep.warlords.menu.Menu) Arrays(java.util.Arrays) Enchantment(org.bukkit.enchantments.Enchantment) SimpleDateFormat(java.text.SimpleDateFormat) Warlords(com.ebicep.warlords.Warlords) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) WordWrap(com.ebicep.warlords.util.bukkit.WordWrap) Player(org.bukkit.entity.Player) UUID(java.util.UUID) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Collectors(java.util.stream.Collectors) ChallengeAchievements(com.ebicep.warlords.achievements.types.ChallengeAchievements) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) List(java.util.List) ChatColor(org.bukkit.ChatColor) GameMode(com.ebicep.warlords.game.GameMode) Material(org.bukkit.Material) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) ChallengeAchievements(com.ebicep.warlords.achievements.types.ChallengeAchievements) Menu(com.ebicep.warlords.menu.Menu) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)

Aggregations

ChallengeAchievements (com.ebicep.warlords.achievements.types.ChallengeAchievements)3 DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)3 Player (org.bukkit.entity.Player)3 Warlords (com.ebicep.warlords.Warlords)2 TieredAchievements (com.ebicep.warlords.achievements.types.TieredAchievements)2 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)2 GameMode (com.ebicep.warlords.game.GameMode)2 Menu (com.ebicep.warlords.menu.Menu)2 ItemBuilder (com.ebicep.warlords.util.bukkit.ItemBuilder)2 WordWrap (com.ebicep.warlords.util.bukkit.WordWrap)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Arrays (java.util.Arrays)2 List (java.util.List)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 ChatColor (org.bukkit.ChatColor)2 Material (org.bukkit.Material)2 Enchantment (org.bukkit.enchantments.Enchantment)2 ItemFlag (org.bukkit.inventory.ItemFlag)2 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)1