Search in sources :

Example 1 with ClassesGroup

use of com.ebicep.warlords.player.ClassesGroup 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)

Aggregations

Warlords (com.ebicep.warlords.Warlords)1 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)1 DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)1 Team (com.ebicep.warlords.game.Team)1 Menu (com.ebicep.warlords.menu.Menu)1 PermissionHandler (com.ebicep.warlords.permissions.PermissionHandler)1 Classes (com.ebicep.warlords.player.Classes)1 ClassesGroup (com.ebicep.warlords.player.ClassesGroup)1 SpecType (com.ebicep.warlords.player.SpecType)1 ItemBuilder (com.ebicep.warlords.util.bukkit.ItemBuilder)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 org.bukkit (org.bukkit)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1