Search in sources :

Example 41 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder in project Warlords by ebicep.

the class RegularGamesMenu method openMenuForPlayer.

public void openMenuForPlayer(Player player) {
    Optional<RegularGamePlayer> gamePlayerOptional = regularGamePlayers.stream().filter(p -> p.getUuid().equals(player.getUniqueId())).findFirst();
    if (!gamePlayerOptional.isPresent())
        return;
    RegularGamePlayer regularGamePlayer = gamePlayerOptional.get();
    Menu menu = new Menu("Team Builder", 9 * 6);
    Team team = regularGamePlayer.getTeam();
    // team wool surround
    for (int i = 0; i < 6; i++) {
        menu.setItem(0, i, new ItemBuilder(team.getItem()).name(team.coloredPrefix()).get(), (m, e) -> {
        });
        menu.setItem(8, i, new ItemBuilder(team.getItem()).name(team.coloredPrefix()).get(), (m, e) -> {
        });
    }
    for (int i = 1; i < 8; i++) {
        menu.setItem(i, 0, new ItemBuilder(team.getItem()).name(team.coloredPrefix()).get(), (m, e) -> {
        });
        if (i == 2) {
            i = 5;
        }
    }
    // two columns of class icons
    for (int i = 0; i < ClassesGroup.values().length; i++) {
        ClassesGroup classesGroup = ClassesGroup.values()[i];
        menu.setItem(2, i + 1, new ItemBuilder(classesGroup.item).name(ChatColor.GREEN + classesGroup.name).get(), (m, e) -> {
        });
        menu.setItem(6, i + 1, new ItemBuilder(classesGroup.item).name(ChatColor.GREEN + classesGroup.name).get(), (m, e) -> {
        });
    }
    // row of spec icons
    for (int i = 0; i < SpecType.values().length; i++) {
        SpecType specType = SpecType.values()[i];
        menu.setItem(i + 3, 0, new ItemBuilder(specType.itemStack).name(specType.chatColor + specType.name).get(), (m, e) -> {
        });
    }
    // bottom items
    List<RegularGamePlayer> teamPlayers = regularGamePlayers.stream().filter(p -> p.getTeam() == team).collect(Collectors.toList());
    // players with perms to interact with menu
    List<UUID> uuidsWithPerms = new ArrayList<>();
    for (RegularGamePlayer p : teamPlayers) {
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUuid());
        if (offlinePlayer.getPlayer() != null) {
            if (PermissionHandler.isGameStarter(offlinePlayer.getPlayer()) || offlinePlayer.getPlayer().isOp()) {
                uuidsWithPerms.add(p.getUuid());
            }
        }
    }
    List<String> editors = new ArrayList<>();
    for (UUID uuid : uuidsWithPerms) {
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
        if (offlinePlayer != null) {
            editors.add(ChatColor.GRAY + offlinePlayer.getName());
        }
    }
    menu.setItem(2, 5, new ItemBuilder(Material.BOOK_AND_QUILL).name(ChatColor.GREEN + "Editors").lore(editors).get(), (m, e) -> {
    });
    menu.setItem(3, 5, new ItemBuilder(Material.WOOL, 1, (short) 5).name(ChatColor.GREEN + "Confirm Team").get(), (m, e) -> {
        if (!uuidsWithPerms.contains(player.getUniqueId()))
            return;
        for (RegularGamePlayer teamPlayer : teamPlayers) {
            UUID uuid = teamPlayer.getUuid();
            Classes spec = teamPlayer.getSelectedClass();
            OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
            Warlords.getPlayerSettings(uuid).setSelectedClass(spec);
            DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(uuid);
            databasePlayer.setLastSpec(spec);
            DatabaseManager.updatePlayerAsync(databasePlayer);
            if (offlinePlayer.getPlayer() != null) {
                offlinePlayer.getPlayer().sendMessage(ChatColor.DARK_BLUE + "---------------------------------------");
                offlinePlayer.getPlayer().sendMessage(ChatColor.GREEN + "Your spec was automatically changed to " + ChatColor.YELLOW + spec.name + ChatColor.GREEN + "!");
                offlinePlayer.getPlayer().sendMessage(ChatColor.DARK_BLUE + "---------------------------------------");
            }
        }
        regularGamePlayers.forEach(p -> {
            OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUuid());
            if (offlinePlayer.getPlayer() != null) {
                offlinePlayer.getPlayer().sendMessage(ChatColor.GREEN + "The " + team.coloredPrefix() + ChatColor.GREEN + " team is ready!");
            }
        });
    });
    menu.setItem(4, 5, Menu.MENU_CLOSE, Menu.ACTION_CLOSE_MENU);
    // showing general list of spec and respective players
    List<String> playerOnSpecs = new ArrayList<>();
    for (Classes value : Classes.values()) {
        Optional<RegularGamePlayer> playerOptional = teamPlayers.stream().filter(p -> p.getSelectedClass() == value).findFirst();
        if (playerOptional.isPresent()) {
            playerOnSpecs.add(ChatColor.GOLD + value.name + ChatColor.GRAY + " - " + ChatColor.AQUA + Bukkit.getOfflinePlayer(playerOptional.get().getUuid()).getName());
        } else {
            playerOnSpecs.add(ChatColor.GOLD + value.name + ChatColor.GRAY + " - " + ChatColor.AQUA);
        }
    }
    menu.setItem(5, 5, new ItemBuilder(Material.SIGN).name(ChatColor.GREEN + "General Information").lore(playerOnSpecs).get(), (m, e) -> {
    });
    if (checkPlayers.get(team)) {
        checkPlayers.put(team, false);
        // removing all duplicate specs
        List<Classes> assignedClasses = new ArrayList<>();
        List<RegularGamePlayer> playersToReassign = new ArrayList<>();
        for (RegularGamePlayer p : teamPlayers) {
            Classes selectedClass = p.getSelectedClass();
            if (assignedClasses.contains(selectedClass)) {
                playersToReassign.add(p);
            } else {
                assignedClasses.add(selectedClass);
            }
        }
        for (RegularGamePlayer p : playersToReassign) {
            for (Classes value : Classes.values()) {
                if (!assignedClasses.contains(value)) {
                    p.setSelectedClass(value);
                    assignedClasses.add(value);
                    break;
                }
            }
        }
    }
    // player skulls with their spec
    List<Classes> assignedClasses = new ArrayList<>();
    for (RegularGamePlayer p : teamPlayers) {
        UUID uuid = p.getUuid();
        Classes selectedClass = p.getSelectedClass();
        ClassesGroup classesGroup = Classes.getClassesGroup(selectedClass);
        int x = selectedClass.specType == SpecType.DAMAGE ? 3 : selectedClass.specType == SpecType.TANK ? 4 : selectedClass.specType == SpecType.HEALER ? 5 : -1;
        int y = classesGroup == ClassesGroup.MAGE ? 1 : classesGroup == ClassesGroup.WARRIOR ? 2 : classesGroup == ClassesGroup.PALADIN ? 3 : classesGroup == ClassesGroup.SHAMAN ? 4 : -1;
        if (x == -1 || y == -1) {
            System.out.println("ERROR trying to get players spec position for regular game menu");
            continue;
        }
        assignedClasses.add(selectedClass);
        ItemBuilder itemBuilder;
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
        String name = offlinePlayer != null ? offlinePlayer.getName() : "UNKNOWN";
        if (selectedPlayersToSwap.get(team).contains(uuid)) {
            itemBuilder = new ItemBuilder(new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.CREEPER.ordinal())).name(ChatColor.AQUA + name + ChatColor.GREEN + " SELECTED").lore(ChatColor.GOLD + p.getSelectedClass().name);
        } else {
            itemBuilder = new ItemBuilder(Warlords.getHead(uuid)).name(ChatColor.AQUA + name).lore(ChatColor.GOLD + p.getSelectedClass().name);
        }
        menu.setItem(x, y, itemBuilder.get(), (m, e) -> {
            if (!uuidsWithPerms.contains(player.getUniqueId()))
                return;
            List<UUID> uuids = selectedPlayersToSwap.get(team);
            // unselect player
            if (uuids.contains(uuid)) {
                uuids.remove(uuid);
            } else {
                uuids.add(uuid);
                // check swap
                if (uuids.size() == 2) {
                    swapPlayers(team);
                }
            }
            menu.openForPlayer(player);
        });
    }
    // fillers
    Arrays.stream(Classes.values()).filter(classes -> !assignedClasses.contains(classes)).collect(Collectors.toList()).forEach(selectedClass -> {
        ClassesGroup classesGroup = Classes.getClassesGroup(selectedClass);
        int x = selectedClass.specType == SpecType.DAMAGE ? 3 : selectedClass.specType == SpecType.TANK ? 4 : selectedClass.specType == SpecType.HEALER ? 5 : -1;
        int y = classesGroup == ClassesGroup.MAGE ? 1 : classesGroup == ClassesGroup.WARRIOR ? 2 : classesGroup == ClassesGroup.PALADIN ? 3 : classesGroup == ClassesGroup.SHAMAN ? 4 : -1;
        menu.setItem(x, y, new ItemBuilder(Material.STAINED_GLASS_PANE, 1, (short) 7).name(ChatColor.GRAY + "Available Spec").get(), (m, e) -> {
            if (!uuidsWithPerms.contains(player.getUniqueId()))
                return;
            // give new spec
            List<UUID> uuids = selectedPlayersToSwap.get(team);
            if (uuids.size() == 1) {
                regularGamePlayers.stream().filter(p -> p.getUuid().equals(selectedPlayersToSwap.get(team).get(0))).findFirst().ifPresent(p -> {
                    p.setSelectedClass(selectedClass);
                    selectedPlayersToSwap.get(team).clear();
                });
            }
            menu.openForPlayer(player);
        });
    });
    menu.openForPlayer(player);
}
Also used : ClassesGroup(com.ebicep.warlords.player.ClassesGroup) Menu(com.ebicep.warlords.menu.Menu) PermissionHandler(com.ebicep.warlords.permissions.PermissionHandler) java.util(java.util) Team(com.ebicep.warlords.game.Team) Warlords(com.ebicep.warlords.Warlords) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) SpecType(com.ebicep.warlords.player.SpecType) Collectors(java.util.stream.Collectors) org.bukkit(org.bukkit) ItemStack(org.bukkit.inventory.ItemStack) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Classes(com.ebicep.warlords.player.Classes) SpecType(com.ebicep.warlords.player.SpecType) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Team(com.ebicep.warlords.game.Team) ClassesGroup(com.ebicep.warlords.player.ClassesGroup) Menu(com.ebicep.warlords.menu.Menu) ItemStack(org.bukkit.inventory.ItemStack) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Classes(com.ebicep.warlords.player.Classes)

Example 42 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder in project Warlords by ebicep.

the class ItemBuilderTest method testNameSetable.

@Test
public void testNameSetable() {
    ItemBuilder builder = new ItemBuilder(Material.STONE);
    builder.name("test");
    ItemStack item = builder.get();
    assertEquals("test", item.getItemMeta().getDisplayName());
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test)

Example 43 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder in project Warlords by ebicep.

the class AchievementsMenu method openTieredAchievementsMenu.

public static void openTieredAchievementsMenu(Player player, GameMode gameMode) {
    if (DatabaseManager.playerService == null)
        return;
    DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
    List<TieredAchievements> achievementRecords = databasePlayer.getAchievements().stream().filter(abstractAchievementRecord -> abstractAchievementRecord.getAchievement() instanceof TieredAchievements).map(Achievement.AbstractAchievementRecord::getAchievement).map(TieredAchievements.class::cast).collect(Collectors.toList());
    List<TieredAchievements> tieredAchievements = Arrays.stream(TieredAchievements.values()).filter(achievements -> achievements.gameMode == gameMode).collect(Collectors.toList());
    Menu menu = new Menu("Challenge Achievements - " + gameMode.name, 9 * 6);
    int x = 0;
    int y = 0;
    for (TieredAchievements achievement : tieredAchievements) {
        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(// + " - " + (achievement.spec.name == null ? "General" : achievement.spec.name))
        ChatColor.GREEN + achievement.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) -> openTieredAchievementHistoryMenu(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) TieredAchievements(com.ebicep.warlords.achievements.types.TieredAchievements) Menu(com.ebicep.warlords.menu.Menu) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)

Example 44 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder in project Warlords by ebicep.

the class AchievementsMenu method openAchievementTypeMenu.

public static void openAchievementTypeMenu(Player player, GameMode gameMode) {
    Menu menu = new Menu("Achievements - " + (gameMode == null ? "General" : gameMode.name), 9 * 4);
    menu.setItem(2, 1, new ItemBuilder(Material.DIAMOND).name(ChatColor.GREEN + "Challenge Achievements").get(), (m, e) -> openChallengeAchievementsMenu(player, gameMode));
    menu.setItem(6, 1, new ItemBuilder(Material.DIAMOND_BLOCK).name(ChatColor.GREEN + "Tiered Achievements").get(), (m, e) -> {
        openTieredAchievementsMenu(player, gameMode);
    });
    menu.setItem(3, 3, MENU_BACK, (m, e) -> openAchievementsMenu(player));
    menu.setItem(4, 3, MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.openForPlayer(player);
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Menu(com.ebicep.warlords.menu.Menu)

Example 45 with ItemBuilder

use of com.ebicep.warlords.util.bukkit.ItemBuilder 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

ItemBuilder (com.ebicep.warlords.util.bukkit.ItemBuilder)49 Menu (com.ebicep.warlords.menu.Menu)31 ItemStack (org.bukkit.inventory.ItemStack)22 Warlords (com.ebicep.warlords.Warlords)12 Player (org.bukkit.entity.Player)12 Classes (com.ebicep.warlords.player.Classes)11 DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)10 Collectors (java.util.stream.Collectors)10 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)8 Team (com.ebicep.warlords.game.Team)8 ChatColor (org.bukkit.ChatColor)8 AbstractPlayerClass (com.ebicep.warlords.classes.AbstractPlayerClass)7 List (java.util.List)7 Material (org.bukkit.Material)7 Enchantment (org.bukkit.enchantments.Enchantment)7 ItemFlag (org.bukkit.inventory.ItemFlag)7 ArrayList (java.util.ArrayList)6 Arrays (java.util.Arrays)6 UUID (java.util.UUID)6 Game (com.ebicep.warlords.game.Game)5