Search in sources :

Example 6 with Classes

use of com.ebicep.warlords.player.Classes in project Warlords by ebicep.

the class GameMenu method openLobbyAbilityMenu.

public static void openLobbyAbilityMenu(Player player) {
    Menu menu = new Menu("Class Information", 9);
    PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
    Classes selectedClass = playerSettings.getSelectedClass();
    AbstractPlayerClass apc = selectedClass.create.get();
    ItemBuilder icon = new ItemBuilder(selectedClass.specType.itemStack);
    icon.name(ChatColor.GREEN + selectedClass.name);
    icon.lore(selectedClass.description, "", "§6Specialization Stats:", "", "§7Health: §a" + apc.getMaxHealth(), "§7Energy: §a" + apc.getMaxEnergy() + " §7/ §a+" + apc.getEnergyPerSec() + " §7per sec §7/ §a+" + apc.getEnergyOnHit() + " §7per hit", "", selectedClass == APOTHECARY ? "§7Speed: §e10%" : null, apc.getDamageResistance() == 0 ? "§7Damage Reduction: §cNone" : "§7Damage Reduction: §e" + apc.getDamageResistance() + "%");
    ClassesSkillBoosts selectedBoost = playerSettings.getSkillBoostForClass();
    if (selectedBoost != null) {
        if (apc.getWeapon().getClass() == selectedBoost.ability) {
            apc.getWeapon().boostSkill(selectedBoost, apc);
        } else if (apc.getRed().getClass() == selectedBoost.ability) {
            apc.getRed().boostSkill(selectedBoost, apc);
        } else if (apc.getPurple().getClass() == selectedBoost.ability) {
            apc.getPurple().boostSkill(selectedBoost, apc);
        } else if (apc.getBlue().getClass() == selectedBoost.ability) {
            apc.getBlue().boostSkill(selectedBoost, apc);
        } else if (apc.getOrange().getClass() == selectedBoost.ability) {
            apc.getOrange().boostSkill(selectedBoost, apc);
        }
    }
    apc.getWeapon().updateDescription(player);
    apc.getRed().updateDescription(player);
    apc.getPurple().updateDescription(player);
    apc.getBlue().updateDescription(player);
    apc.getOrange().updateDescription(player);
    menu.setItem(0, icon.get(), ACTION_DO_NOTHING);
    menu.setItem(2, apc.getWeapon().getItem(playerSettings.getWeaponSkins().getOrDefault(selectedClass, Weapons.FELFLAME_BLADE).item), ACTION_DO_NOTHING);
    menu.setItem(3, apc.getRed().getItem(new ItemStack(Material.INK_SACK, 1, (byte) 1)), ACTION_DO_NOTHING);
    menu.setItem(4, apc.getPurple().getItem(new ItemStack(Material.GLOWSTONE_DUST)), ACTION_DO_NOTHING);
    menu.setItem(5, apc.getBlue().getItem(new ItemStack(Material.INK_SACK, 1, (byte) 10)), ACTION_DO_NOTHING);
    menu.setItem(6, apc.getOrange().getItem(new ItemStack(Material.INK_SACK, 1, (byte) 14)), ACTION_DO_NOTHING);
    menu.setItem(8, MENU_BACK_PREGAME, (m, e) -> openMainMenu(player));
    menu.openForPlayer(player);
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) AbstractPlayerClass(com.ebicep.warlords.classes.AbstractPlayerClass) ItemStack(org.bukkit.inventory.ItemStack) Classes(com.ebicep.warlords.player.Classes)

Example 7 with Classes

use of com.ebicep.warlords.player.Classes in project Warlords by ebicep.

the class GameMenu method openWeaponMenu.

public static void openWeaponMenu(Player player, int pageNumber) {
    Classes selectedClass = getSelected(player);
    Weapons selectedWeapon = Weapons.getSelected(player, selectedClass);
    Menu menu = new Menu("Weapon Skin Selector", 9 * 6);
    List<Weapons> values = new ArrayList<>(Arrays.asList(Weapons.values()));
    for (int i = (pageNumber - 1) * 21; i < pageNumber * 21 && i < values.size(); i++) {
        Weapons weapon = values.get(i);
        ItemBuilder builder;
        if (weapon.isUnlocked) {
            builder = new ItemBuilder(weapon.item).name(ChatColor.GREEN + weapon.name).flags(ItemFlag.HIDE_ENCHANTS);
            List<String> lore = new ArrayList<>();
            if (weapon == selectedWeapon) {
                lore.add(ChatColor.GREEN + "Currently selected!");
                builder.enchant(Enchantment.OXYGEN, 1);
            } else {
                lore.add(ChatColor.YELLOW + "Click to select!");
            }
            builder.lore(lore);
        } else {
            builder = new ItemBuilder(Material.BARRIER).name(ChatColor.RED + "Locked Weapon Skin");
        }
        menu.setItem((i - (pageNumber - 1) * 21) % 7 + 1, (i - (pageNumber - 1) * 21) / 7 + 1, builder.get(), (m, e) -> {
            if (weapon.isUnlocked) {
                player.sendMessage(ChatColor.GREEN + "You have changed your " + ChatColor.AQUA + selectedClass.name + ChatColor.GREEN + "'s weapon skin to: §b" + weapon.name + "!");
                Weapons.setSelected(player, selectedClass, weapon);
                openWeaponMenu(player, pageNumber);
                PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
                AbstractPlayerClass apc = selectedClass.create.get();
                player.getInventory().setItem(1, new ItemBuilder(apc.getWeapon().getItem(playerSettings.getWeaponSkins().getOrDefault(selectedClass, Weapons.FELFLAME_BLADE).item)).name("§aWeapon Skin Preview").lore("").get());
                if (DatabaseManager.playerService == null)
                    return;
                DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
                databasePlayer.getSpec(selectedClass).setWeapon(weapon);
                DatabaseManager.updatePlayerAsync(databasePlayer);
            } else {
                player.sendMessage(ChatColor.RED + "This weapon skin has not been unlocked yet!");
            }
        });
    }
    if (pageNumber == 1) {
        menu.setItem(8, 5, new ItemBuilder(Material.ARROW).name(ChatColor.GREEN + "Next Page").lore(ChatColor.YELLOW + "Page " + (pageNumber + 1)).get(), (m, e) -> openWeaponMenu(player, pageNumber + 1));
    } else if (pageNumber == 2) {
        menu.setItem(0, 5, new ItemBuilder(Material.ARROW).name(ChatColor.GREEN + "Previous Page").lore(ChatColor.YELLOW + "Page " + (pageNumber - 1)).get(), (m, e) -> openWeaponMenu(player, pageNumber - 1));
        menu.setItem(8, 5, new ItemBuilder(Material.ARROW).name(ChatColor.GREEN + "Next Page").lore(ChatColor.YELLOW + "Page " + (pageNumber + 1)).get(), (m, e) -> openWeaponMenu(player, pageNumber + 1));
    } else if (pageNumber == 3) {
        menu.setItem(0, 5, new ItemBuilder(Material.ARROW).name(ChatColor.GREEN + "Previous Page").lore(ChatColor.YELLOW + "Page " + (pageNumber - 1)).get(), (m, e) -> openWeaponMenu(player, pageNumber - 1));
        menu.setItem(8, 5, new ItemBuilder(Material.ARROW).name(ChatColor.GREEN + "Next Page").lore(ChatColor.YELLOW + "Page " + (pageNumber + 1)).get(), (m, e) -> openWeaponMenu(player, pageNumber + 1));
    } else if (pageNumber == 4) {
        menu.setItem(0, 5, new ItemBuilder(Material.ARROW).name(ChatColor.GREEN + "Previous Page").lore(ChatColor.YELLOW + "Page " + (pageNumber - 1)).get(), (m, e) -> openWeaponMenu(player, pageNumber - 1));
    }
    menu.setItem(4, 5, MENU_BACK_PREGAME, (m, e) -> openMainMenu(player));
    menu.openForPlayer(player);
}
Also used : ItemFlag(org.bukkit.inventory.ItemFlag) Utils(com.ebicep.warlords.util.warlords.Utils) java.util(java.util) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Settings(com.ebicep.warlords.player.Settings) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) MapSymmetryMarker(com.ebicep.warlords.game.option.marker.MapSymmetryMarker) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) org.bukkit(org.bukkit) AbstractPlayerClass(com.ebicep.warlords.classes.AbstractPlayerClass) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Classes(com.ebicep.warlords.player.Classes) ACTION_DO_NOTHING(com.ebicep.warlords.menu.Menu.ACTION_DO_NOTHING) Math.round(java.lang.Math.round) LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) Team(com.ebicep.warlords.game.Team) Warlords(com.ebicep.warlords.Warlords) NumberFormat(com.ebicep.warlords.util.java.NumberFormat) Collectors(java.util.stream.Collectors) ItemStack(org.bukkit.inventory.ItemStack) com.ebicep.warlords.player(com.ebicep.warlords.player) Stream(java.util.stream.Stream) Game(com.ebicep.warlords.game.Game) ArmorManager(com.ebicep.warlords.player.ArmorManager) ACTION_CLOSE_MENU(com.ebicep.warlords.menu.Menu.ACTION_CLOSE_MENU) AbstractPlayerClass(com.ebicep.warlords.classes.AbstractPlayerClass) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Classes(com.ebicep.warlords.player.Classes)

Example 8 with Classes

use of com.ebicep.warlords.player.Classes in project Warlords by ebicep.

the class GameMenu method openArcadeMenu.

public static void openArcadeMenu(Player player) {
    Menu menu = new Menu("Mini Games", 9 * 4);
    ItemBuilder icon = new ItemBuilder(Material.GOLD_INGOT);
    icon.name(ChatColor.GREEN + "Weapon Roller");
    icon.lore("§7Is RNG with you today?");
    menu.setItem(3, 1, icon.get(), (m, e) -> {
        double difficulty = 1;
        double base = random.nextDouble() * (1 - difficulty);
        double meleeDamageMin = random.nextDouble() * difficulty + base;
        double meleeDamageMax = random.nextDouble() * difficulty + base;
        double critChance = random.nextDouble() * difficulty + base;
        double critMultiplier = random.nextDouble() * difficulty + base;
        double skillBoost = random.nextDouble() * difficulty + base;
        double health = random.nextDouble() * difficulty + base;
        double energy = random.nextDouble() * difficulty + base;
        double cooldown = random.nextDouble() * difficulty + base;
        double speed = random.nextDouble() * difficulty + base;
        double score = (meleeDamageMin + meleeDamageMax + critChance + critMultiplier + skillBoost + health + energy + cooldown + speed) / 9;
        meleeDamageMin = map(meleeDamageMin, 122, 132);
        meleeDamageMax = map(meleeDamageMax, 166, 179);
        critChance = map(critChance, 15, 25);
        critMultiplier = map(critMultiplier, 180, 200);
        skillBoost = map(skillBoost, 13, 20);
        health = map(health, 500, 800);
        energy = map(energy, 30, 35);
        cooldown = map(cooldown, 7, 13);
        speed = map(speed, 7, 13);
        if (meleeDamageMin > meleeDamageMax) {
            double temp = meleeDamageMin;
            meleeDamageMin = meleeDamageMax;
            meleeDamageMax = temp;
        }
        String displayScore = "§7Your weapon score is §a" + NumberFormat.formatOptionalTenths(score * 100);
        PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
        Classes selectedClass = playerSettings.getSelectedClass();
        AbstractPlayerClass apc = selectedClass.create.get();
        ItemStack weapon = new ItemStack(Weapons.FELFLAME_BLADE.item);
        ItemMeta weaponMeta = weapon.getItemMeta();
        weaponMeta.setDisplayName("§6Warlord's Felflame of the " + apc.getWeapon().getName());
        ArrayList<String> weaponLore = new ArrayList<>();
        weaponLore.add("§7Damage: §c" + round(meleeDamageMin) + "§7-§c" + round(meleeDamageMax));
        weaponLore.add("§7Crit Chance: §c" + round(critChance) + "%");
        weaponLore.add("§7Crit Multiplier: §c" + round(critMultiplier) + "%");
        weaponLore.add("");
        String classNamePath = apc.getClass().getGenericSuperclass().getTypeName();
        weaponLore.add("§a" + classNamePath.substring(classNamePath.indexOf("Abstract") + 8) + " (" + apc.getClass().getSimpleName() + "):");
        weaponLore.add("§aIncreases the damage you");
        weaponLore.add("§adeal with " + apc.getWeapon().getName() + " by §c" + round(skillBoost) + "%");
        weaponLore.add("");
        weaponLore.add("§7Health: §a+" + round(health));
        weaponLore.add("§7Max Energy: §a+" + round(energy));
        weaponLore.add("§7Cooldown Reduction: §a+" + round(cooldown) + "%");
        weaponLore.add("§7Speed: §a+" + round(speed) + "%");
        weaponLore.add("");
        weaponLore.add("§3CRAFTED");
        weaponLore.add("");
        weaponLore.add(displayScore);
        weaponLore.add("");
        weaponLore.add("§7Left-click to roll again!");
        weaponMeta.setLore(weaponLore);
        weapon.setItemMeta(weaponMeta);
        m.getInventory().setItem(e.getRawSlot(), weapon);
        if (score > 0.85) {
            Bukkit.broadcastMessage("§6" + player.getDisplayName() + " §frolled a weapon with a total score of §6" + NumberFormat.formatOptionalTenths(score * 100) + "§f!");
        }
        if (score < 0.15) {
            Bukkit.broadcastMessage("§6" + player.getDisplayName() + " §frolled a weapon with a total score of §c" + NumberFormat.formatOptionalTenths(score * 100) + "§f!");
        }
    });
    ItemBuilder icon2 = new ItemBuilder(Material.SULPHUR);
    icon2.name(ChatColor.GREEN + "Skin Shard Roller");
    icon2.lore("§7Is RNG with you to give everyone a new awesome skin?", "", "§7Left-click to roll 10 skin shards!");
    menu.setItem(5, 1, icon2.get(), (m, e) -> {
        Long weaponCooldown = openWeaponCooldown.get(player.getUniqueId());
        Map<WeaponsRarity, Integer> foundWeaponCount = new EnumMap<>(WeaponsRarity.class);
        for (WeaponsRarity rarity : WeaponsRarity.values()) {
            foundWeaponCount.put(rarity, 0);
        }
        if (Bukkit.getOnlinePlayers().size() >= 16) {
            if (weaponCooldown == null || weaponCooldown < System.currentTimeMillis()) {
                openWeaponCooldown.put(player.getUniqueId(), System.currentTimeMillis() + 8 * 60 * 1000);
                player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 2);
                for (int i = 0; i < 10; i++) {
                    String legendaryName = legendaryNames[random.nextInt(legendaryNames.length)];
                    String mythicName = mythicNames[random.nextInt(mythicNames.length)];
                    double chance = random.nextDouble() * 100;
                    WeaponsRarity rarity;
                    PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
                    Classes selectedClass = playerSettings.getSelectedClass();
                    if (chance < 96.38) {
                        rarity = WeaponsRarity.RARE;
                    } else if (chance < 96.38 + 3) {
                        rarity = WeaponsRarity.EPIC;
                    } else if (chance < 96.38 + 3 + 0.6) {
                        rarity = WeaponsRarity.LEGENDARY;
                    } else {
                        rarity = WeaponsRarity.MYTHIC;
                    }
                    foundWeaponCount.compute(rarity, (key, value) -> value == null ? 1 : value + 1);
                    List<Weapons> weapons = weaponByRarity.get(rarity);
                    Weapons weapon = weapons.get(random.nextInt(weapons.size()));
                    String message = rarity.getWeaponChatColor() + legendaryName + "'s " + weapon.getName() + " of the " + selectedClass.name;
                    String mythicMessage = rarity.getWeaponChatColor() + "§l" + mythicName + " " + weapon.getName() + " of the " + selectedClass.name;
                    if (rarity == WeaponsRarity.EPIC) {
                        Bukkit.broadcastMessage(ChatColor.AQUA + player.getDisplayName() + " §fgot lucky and found " + message);
                    }
                    if (rarity == WeaponsRarity.LEGENDARY) {
                        Utils.playGlobalSound(player.getLocation(), "legendaryfind", 1, 1);
                        Bukkit.broadcastMessage(ChatColor.AQUA + player.getDisplayName() + " §fgot lucky and found " + message);
                        player.getWorld().spigot().strikeLightningEffect(player.getLocation(), false);
                    }
                    if (rarity == WeaponsRarity.MYTHIC) {
                        Utils.playGlobalSound(player.getLocation(), "legendaryfind", 500, 0.8f);
                        Utils.playGlobalSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 500, 0.8f);
                        Bukkit.broadcastMessage(ChatColor.AQUA + player.getDisplayName() + " §fgot lucky and found " + mythicMessage);
                        for (int j = 0; j < 10; j++) {
                            player.getWorld().spigot().strikeLightningEffect(player.getLocation(), false);
                        }
                    }
                    if (!weapon.isUnlocked) {
                        weapon.isUnlocked = true;
                        Warlords.getInstance().saveWeaponConfig();
                        Bukkit.broadcastMessage("");
                        Bukkit.broadcastMessage("§l" + rarity.getWeaponChatColor() + weapon.getName() + " §l§fis now unlocked for everyone!");
                        Bukkit.broadcastMessage("");
                    } else {
                        if (rarity == WeaponsRarity.MYTHIC) {
                            Bukkit.broadcastMessage("");
                            Bukkit.broadcastMessage("§l" + rarity.getWeaponChatColor() + weapon.getName() + " §fwas already found! Unlucky!");
                            Bukkit.broadcastMessage("");
                        }
                    }
                }
                player.sendMessage("");
                player.sendMessage("§7You found:");
                player.sendMessage("§7Rare: §9" + foundWeaponCount.get(WeaponsRarity.RARE));
                player.sendMessage("§7Epic: §5" + foundWeaponCount.get(WeaponsRarity.EPIC));
                player.sendMessage("§7Legendary: §6" + foundWeaponCount.get(WeaponsRarity.LEGENDARY));
                player.sendMessage("§7Mythic: §c" + foundWeaponCount.get(WeaponsRarity.MYTHIC));
            } else {
                long remainingTime = (weaponCooldown - System.currentTimeMillis()) / 1000;
                long remainingTimeinMinutes = remainingTime / 60;
                player.sendMessage(ChatColor.RED + "Please wait " + (remainingTime > 60 ? remainingTimeinMinutes + " minutes" : remainingTime + " seconds") + " before opening skin shards again!");
            }
        } else {
            player.sendMessage(ChatColor.RED + "There must be at least 16 players online to roll skin shards!");
        }
    });
    menu.setItem(4, 3, MENU_BACK_PREGAME, (m, e) -> openMainMenu(player));
    menu.openForPlayer(player);
}
Also used : AbstractPlayerClass(com.ebicep.warlords.classes.AbstractPlayerClass) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Classes(com.ebicep.warlords.player.Classes)

Example 9 with Classes

use of com.ebicep.warlords.player.Classes in project Warlords by ebicep.

the class GameMenu method openMainMenu.

public static void openMainMenu(Player player) {
    Classes selectedClass = getSelected(player);
    Menu menu = new Menu("Warlords Shop", 9 * 6);
    ClassesGroup[] values = ClassesGroup.values();
    for (int i = 0; i < values.length; i++) {
        ClassesGroup group = values[i];
        List<String> lore = new ArrayList<>();
        lore.add(group.description);
        lore.add("");
        lore.add(ChatColor.GOLD + "Specializations:");
        for (Classes subClass : group.subclasses) {
            lore.add((subClass == selectedClass ? ChatColor.GREEN : ChatColor.GRAY) + subClass.name);
        }
        lore.add("");
        long experience = ExperienceManager.getExperienceForClass(player.getUniqueId(), group);
        int level = (int) ExperienceManager.calculateLevelFromExp(experience);
        lore.add(ExperienceManager.getProgressString(experience, level + 1));
        lore.add("");
        lore.add(ChatColor.YELLOW + "Click here to select a " + group.name + "\n" + ChatColor.YELLOW + "specialization");
        ItemStack item = new ItemBuilder(group.item).name(ChatColor.GOLD + group.name + ChatColor.DARK_GRAY + " [" + ChatColor.GRAY + "Lv" + ExperienceManager.getLevelString(level) + ChatColor.DARK_GRAY + "]").lore(lore).get();
        menu.setItem(9 / 2 - values.length / 2 + i * 2 - 2, 1, item, (m, e) -> {
            openClassMenu(player, group);
        });
    }
    menu.setItem(1, 3, MENU_SKINS, (m, e) -> openWeaponMenu(player, 1));
    menu.setItem(3, 3, MENU_ARMOR_SETS, (m, e) -> openArmorMenu(player, 1));
    menu.setItem(5, 3, MENU_BOOSTS, (m, e) -> openSkillBoostMenu(player, selectedClass));
    menu.setItem(7, 3, MENU_SETTINGS, (m, e) -> openSettingsMenu(player));
    menu.setItem(4, 5, Menu.MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.setItem(4, 2, MENU_ABILITY_DESCRIPTION, (m, e) -> openLobbyAbilityMenu(player));
    menu.setItem(4, 4, MENU_ARCADE, (m, e) -> openArcadeMenu(player));
    menu.openForPlayer(player);
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) ItemStack(org.bukkit.inventory.ItemStack) Classes(com.ebicep.warlords.player.Classes)

Example 10 with Classes

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

Classes (com.ebicep.warlords.player.Classes)11 ItemBuilder (com.ebicep.warlords.util.bukkit.ItemBuilder)10 ItemStack (org.bukkit.inventory.ItemStack)9 Player (org.bukkit.entity.Player)6 Warlords (com.ebicep.warlords.Warlords)5 AbstractPlayerClass (com.ebicep.warlords.classes.AbstractPlayerClass)5 DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)5 Team (com.ebicep.warlords.game.Team)5 Collectors (java.util.stream.Collectors)5 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)3 java.util (java.util)3 org.bukkit (org.bukkit)3 Menu (com.ebicep.warlords.menu.Menu)2 PermissionHandler (com.ebicep.warlords.permissions.PermissionHandler)2 ClassesGroup (com.ebicep.warlords.player.ClassesGroup)2 SpecType (com.ebicep.warlords.player.SpecType)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 UUID (java.util.UUID)2