Search in sources :

Example 6 with ItemBuilder

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

the class GameMenu method openArmorMenu.

public static void openArmorMenu(Player player, int pageNumber) {
    boolean onBlueTeam = Warlords.getGameManager().getPlayerGame(player.getUniqueId()).map(g -> g.getPlayerTeam(player.getUniqueId())).orElse(Team.BLUE) == Team.BLUE;
    List<Helmets> selectedHelmet = Helmets.getSelected(player);
    List<ArmorSets> selectedArmorSet = ArmorSets.getSelected(player);
    Menu menu = new Menu("Armor Sets & Helmets", 9 * 6);
    List<Helmets> helmets = Arrays.asList(Helmets.values());
    for (int i = (pageNumber - 1) * 8; i < pageNumber * 8 && i < helmets.size(); i++) {
        Helmets helmet = helmets.get(i);
        ItemBuilder builder = new ItemBuilder(onBlueTeam ? helmet.itemBlue : helmet.itemRed).name(onBlueTeam ? ChatColor.BLUE + helmet.name : ChatColor.RED + helmet.name).flags(ItemFlag.HIDE_ENCHANTS);
        List<String> lore = new ArrayList<>();
        lore.add(helmetDescription);
        lore.add("");
        if (selectedHelmet.contains(helmet)) {
            lore.add(ChatColor.GREEN + ">>> ACTIVE <<<");
            builder.enchant(Enchantment.OXYGEN, 1);
        } else {
            lore.add(ChatColor.YELLOW + "> Click to activate! <");
        }
        builder.lore(lore);
        menu.setItem((i - (pageNumber - 1) * 8) + 1, 2, builder.get(), (m, e) -> {
            player.sendMessage(ChatColor.YELLOW + "Selected: " + ChatColor.GREEN + helmet.name);
            if (helmet == Helmets.SIMPLE_MAGE_HELMET || helmet == Helmets.GREATER_MAGE_HELMET || helmet == Helmets.MASTERWORK_MAGE_HELMET || helmet == Helmets.LEGENDARY_MAGE_HELMET) {
                Helmets.setSelectedMage(player, helmet);
            } else if (helmet == Helmets.SIMPLE_WARRIOR_HELMET || helmet == Helmets.GREATER_WARRIOR_HELMET || helmet == Helmets.MASTERWORK_WARRIOR_HELMET || helmet == Helmets.LEGENDARY_WARRIOR_HELMET) {
                Helmets.setSelectedWarrior(player, helmet);
            } else if (helmet == Helmets.SIMPLE_PALADIN_HELMET || helmet == Helmets.GREATER_PALADIN_HELMET || helmet == Helmets.MASTERWORK_PALADIN_HELMET || helmet == Helmets.LEGENDARY_PALADIN_HELMET) {
                Helmets.setSelectedPaladin(player, helmet);
            } else if (helmet == Helmets.SIMPLE_SHAMAN_HELMET || helmet == Helmets.GREATER_SHAMAN_HELMET || helmet == Helmets.MASTERWORK_SHAMAN_HELMET || helmet == Helmets.LEGENDARY_SHAMAN_HELMET) {
                Helmets.setSelectedShaman(player, helmet);
            } else if (helmet == Helmets.SIMPLE_ROGUE_HELMET || helmet == Helmets.GREATER_ROGUE_HELMET || helmet == Helmets.MASTERWORK_ROGUE_HELMET || helmet == Helmets.LEGENDARY_ROGUE_HELMET) {
                Helmets.setSelectedRogue(player, helmet);
            }
            ArmorManager.resetArmor(player, Warlords.getPlayerSettings(player.getUniqueId()).getSelectedClass(), Warlords.getPlayerSettings(player.getUniqueId()).getWantedTeam());
            openArmorMenu(player, pageNumber);
            if (DatabaseManager.playerService == null)
                return;
            List<Helmets> selectedHelmets = Helmets.getSelected(player);
            DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
            databasePlayer.getMage().setHelmet(selectedHelmets.get(0));
            databasePlayer.getWarrior().setHelmet(selectedHelmets.get(1));
            databasePlayer.getPaladin().setHelmet(selectedHelmets.get(2));
            databasePlayer.getShaman().setHelmet(selectedHelmets.get(3));
            databasePlayer.getRogue().setHelmet(selectedHelmets.get(4));
            DatabaseManager.updatePlayerAsync(databasePlayer);
        });
    }
    List<ArmorSets> armorSets = Arrays.asList(ArmorSets.values());
    int xPosition = 1;
    for (int i = (pageNumber - 1) * 6; i < pageNumber * 6; i++) {
        if (pageNumber == 3 && i == 15) {
            break;
        }
        ArmorSets armorSet = armorSets.get(i);
        ItemBuilder builder = new ItemBuilder(i % 3 == 0 ? ArmorSets.applyColor(armorSet.itemBlue, onBlueTeam) : armorSet.itemBlue).name(onBlueTeam ? ChatColor.BLUE + armorSet.name : ChatColor.RED + armorSet.name).flags(ItemFlag.HIDE_ENCHANTS);
        List<String> lore = new ArrayList<>();
        lore.add(armorDescription);
        lore.add("");
        if (selectedArmorSet.contains(armorSet)) {
            lore.add(ChatColor.GREEN + ">>> ACTIVE <<<");
            builder.enchant(Enchantment.OXYGEN, 1);
        } else {
            lore.add(ChatColor.YELLOW + "> Click to activate! <");
        }
        builder.lore(lore);
        menu.setItem(xPosition, 3, builder.get(), (m, e) -> {
            player.sendMessage(ChatColor.YELLOW + "Selected: " + ChatColor.GREEN + armorSet.name);
            if (armorSet == ArmorSets.SIMPLE_CHESTPLATE_MAGE || armorSet == ArmorSets.GREATER_CHESTPLATE_MAGE || armorSet == ArmorSets.MASTERWORK_CHESTPLATE_MAGE) {
                ArmorSets.setSelectedMage(player, armorSet);
            } else if (armorSet == ArmorSets.SIMPLE_CHESTPLATE_WARRIOR || armorSet == ArmorSets.GREATER_CHESTPLATE_WARRIOR || armorSet == ArmorSets.MASTERWORK_CHESTPLATE_WARRIOR) {
                ArmorSets.setSelectedWarrior(player, armorSet);
            } else if (armorSet == ArmorSets.SIMPLE_CHESTPLATE_PALADIN || armorSet == ArmorSets.GREATER_CHESTPLATE_PALADIN || armorSet == ArmorSets.MASTERWORK_CHESTPLATE_PALADIN) {
                ArmorSets.setSelectedPaladin(player, armorSet);
            } else if (armorSet == ArmorSets.SIMPLE_CHESTPLATE_SHAMAN || armorSet == ArmorSets.GREATER_CHESTPLATE_SHAMAN || armorSet == ArmorSets.MASTERWORK_CHESTPLATE_SHAMAN) {
                ArmorSets.setSelectedShaman(player, armorSet);
            } else if (armorSet == ArmorSets.SIMPLE_CHESTPLATE_ROGUE || armorSet == ArmorSets.GREATER_CHESTPLATE_ROGUE || armorSet == ArmorSets.MASTERWORK_CHESTPLATE_ROGUE) {
                ArmorSets.setSelectedRogue(player, armorSet);
            }
            openArmorMenu(player, pageNumber);
            if (DatabaseManager.playerService == null)
                return;
            List<ArmorSets> armorSetsList = ArmorSets.getSelected(player);
            DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
            databasePlayer.getMage().setArmor(armorSetsList.get(0));
            databasePlayer.getWarrior().setArmor(armorSetsList.get(1));
            databasePlayer.getPaladin().setArmor(armorSetsList.get(2));
            databasePlayer.getShaman().setArmor(armorSetsList.get(3));
            databasePlayer.getRogue().setArmor(armorSetsList.get(4));
            DatabaseManager.updatePlayerAsync(databasePlayer);
        });
        if (xPosition == 3) {
            xPosition += 2;
        } else {
            xPosition++;
        }
    }
    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) -> openArmorMenu(player, pageNumber + 1));
    } else if (pageNumber == 2) {
        menu.setItem(8, 5, new ItemBuilder(Material.ARROW).name(ChatColor.GREEN + "Next Page").lore(ChatColor.YELLOW + "Page " + (pageNumber + 1)).get(), (m, e) -> openArmorMenu(player, pageNumber + 1));
        menu.setItem(0, 5, new ItemBuilder(Material.ARROW).name(ChatColor.GREEN + "Previous Page").lore(ChatColor.YELLOW + "Page " + (pageNumber - 1)).get(), (m, e) -> openArmorMenu(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) -> openArmorMenu(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) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)

Example 7 with ItemBuilder

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

the class DebugMenu method openDebugMenu.

public static void openDebugMenu(Player player) {
    Menu menu = new Menu("Debug Options", 9 * 4);
    LinkedHashMap<ItemStack, BiConsumer<Menu, InventoryClickEvent>> items = new LinkedHashMap<>();
    items.put(new ItemBuilder(Material.ENDER_PORTAL_FRAME).name(ChatColor.GREEN + "Game Options").get(), (m, e) -> DebugMenuGameOptions.openGameMenu(player));
    items.put(new ItemBuilder(Warlords.getHead(player)).name(ChatColor.GREEN + "Player Options").get(), (m, e) -> DebugMenuPlayerOptions.openPlayerMenu(player, Warlords.getPlayer(player)));
    items.put(new ItemBuilder(Material.NOTE_BLOCK).name(ChatColor.GREEN + "Team Options").get(), (m, e) -> {
        DebugMenuPlayerOptions.openTeamMenu(player);
        new BukkitRunnable() {

            @Override
            public void run() {
                if (player.getOpenInventory().getTopInventory().getName().equals("Team Options")) {
                    DebugMenuPlayerOptions.openTeamMenu(player);
                } else {
                    this.cancel();
                }
            }
        }.runTaskTimer(Warlords.getInstance(), 20, 20);
    });
    List<ItemStack> itemsArray = new ArrayList<>(items.keySet());
    for (int i = 0; i < items.size(); i++) {
        menu.setItem(i + 1, 1, itemsArray.get(i), items.get(itemsArray.get(i)));
    }
    menu.setItem(4, 3, MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.openForPlayer(player);
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Menu(com.ebicep.warlords.menu.Menu) ItemStack(org.bukkit.inventory.ItemStack) BiConsumer(java.util.function.BiConsumer) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with ItemBuilder

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

the class DebugMenuGameOptions method openMapsAddonsMenu.

public static void openMapsAddonsMenu(Player player, GameMap selectedGameMap, GameMode selectedGameMode, List<GameAddon> addons) {
    int menuHeight = (4 + GameAddon.values().length / 7);
    Menu menu = new Menu(selectedGameMap.getMapName() + " - " + selectedGameMode.name, 9 * menuHeight);
    for (int i = 0; i < GameAddon.values().length; i++) {
        GameAddon gameAddon = GameAddon.values()[i];
        boolean isASelectedAddon = addons.contains(gameAddon);
        ItemBuilder itemBuilder = new ItemBuilder(woolSortedByColor[i + 5]).name(ChatColor.GREEN + gameAddon.getName()).lore(ChatColor.GOLD + WordWrap.wrapWithNewline(gameAddon.getDescription(), 150));
        if (isASelectedAddon) {
            itemBuilder.enchant(Enchantment.OXYGEN, 1);
            itemBuilder.flags(ItemFlag.HIDE_ENCHANTS);
        }
        menu.setItem(i % 7 + 1, 1 + i / 7, itemBuilder.get(), (m, e) -> {
            if (isASelectedAddon) {
                if (!player.hasPermission("warlords.game.customtoggle") && gameAddon.equals(GameAddon.CUSTOM_GAME)) {
                    player.sendMessage(ChatColor.RED + "Only players with the Game Starter rank or higher can modify this addon!");
                } else if (gameAddon.equals(GameAddon.PRIVATE_GAME) && !player.isOp()) {
                    player.sendMessage(ChatColor.RED + "Games started from the start menu are automatically private!");
                } else {
                    addons.remove(gameAddon);
                }
            } else {
                if (!player.hasPermission("warlords.game.freezetoggle") && gameAddon.equals(GameAddon.FREEZE_GAME)) {
                    player.sendMessage(ChatColor.RED + "Only players with the Game Starter rank or higher can modify this addon!");
                } else {
                    addons.add(gameAddon);
                }
            }
            openMapsAddonsMenu(player, selectedGameMap, selectedGameMode, addons);
        });
    }
    menu.setItem(3, menuHeight - 1, MENU_BACK, (m, e) -> openMapsCategoryMenu(player, selectedGameMap));
    menu.setItem(4, menuHeight - 1, MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.setItem(5, menuHeight - 1, new ItemBuilder(Material.WOOL, 1, (short) 5).name(ChatColor.GREEN + "Start").get(), (m, e) -> {
        StringBuilder stringAddons = new StringBuilder();
        if (addons.isEmpty()) {
            stringAddons.append("addon:NULL");
        } else {
            addons.forEach(gameAddon -> {
                stringAddons.append("addon:").append(gameAddon.name()).append(" ");
            });
        }
        System.out.println("start map:" + selectedGameMap.getMapName() + " category:" + selectedGameMode.name() + " " + stringAddons);
        Bukkit.getServer().dispatchCommand(player, "start map:" + selectedGameMap.name() + " category:" + selectedGameMode.name() + " " + stringAddons);
    });
    menu.openForPlayer(player);
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Menu(com.ebicep.warlords.menu.Menu)

Example 9 with ItemBuilder

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

the class DebugMenuGameOptions method openTimerSetMenu.

public static void openTimerSetMenu(Player player, Game game, int minutes, int seconds) {
    Menu menu = new Menu("Timer", 9 * 6);
    if (seconds >= 60) {
        int min = seconds / 60;
        minutes += min;
        seconds = seconds % 60;
    }
    menu.setItem(4, 0, new ItemBuilder(Material.SIGN).name(ChatColor.GREEN.toString() + minutes + ":" + seconds).get(), (m, e) -> {
    });
    int finalMinutes = minutes;
    int finalSeconds = seconds;
    // MINUTES
    menu.setItem(1, 2, new ItemBuilder(Material.REDSTONE_BLOCK).name(ChatColor.GREEN + "Minutes - " + minutes).lore(ChatColor.YELLOW + "Left-Click to ADD" + "\n" + "Right-Click to SUBTRACT").get(), (m, e) -> {
    });
    menu.setItem(2, 2, new ItemBuilder(Material.LEVER).name(ChatColor.GREEN + "1").get(), (m, e) -> openTimerSetMenu(player, game, finalMinutes + (e.isLeftClick() ? 1 : -1), finalSeconds));
    menu.setItem(3, 2, new ItemBuilder(Material.LEVER).name(ChatColor.GREEN + "5").get(), (m, e) -> openTimerSetMenu(player, game, finalMinutes + (e.isLeftClick() ? 5 : -5), finalSeconds));
    // SECONDS
    menu.setItem(1, 3, new ItemBuilder(Material.REDSTONE).name(ChatColor.GREEN + "Seconds - " + seconds).lore(ChatColor.YELLOW + "Left-Click to ADD" + "\n" + "Right-Click to SUBTRACT").get(), (m, e) -> {
    });
    menu.setItem(2, 3, new ItemBuilder(Material.LEVER).name(ChatColor.GREEN + "1").get(), (m, e) -> openTimerSetMenu(player, game, finalMinutes, finalSeconds + (e.isLeftClick() ? 1 : -1)));
    menu.setItem(3, 3, new ItemBuilder(Material.LEVER).name(ChatColor.GREEN + "5").get(), (m, e) -> openTimerSetMenu(player, game, finalMinutes, finalSeconds + (e.isLeftClick() ? 5 : -5)));
    menu.setItem(4, 3, new ItemBuilder(Material.LEVER).name(ChatColor.GREEN + "10").get(), (m, e) -> openTimerSetMenu(player, game, finalMinutes, finalSeconds + (e.isLeftClick() ? 10 : -10)));
    menu.setItem(5, 3, new ItemBuilder(Material.LEVER).name(ChatColor.GREEN + "15").get(), (m, e) -> openTimerSetMenu(player, game, finalMinutes, finalSeconds + (e.isLeftClick() ? 15 : -15)));
    menu.setItem(6, 3, new ItemBuilder(Material.LEVER).name(ChatColor.GREEN + "30").get(), (m, e) -> openTimerSetMenu(player, game, finalMinutes, finalSeconds + (e.isLeftClick() ? 30 : -30)));
    menu.setItem(3, 5, MENU_BACK, (m, e) -> openTimerMenu(player, game));
    menu.setItem(4, 5, MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.setItem(5, 5, new ItemBuilder(Material.WOOL, 1, (byte) 5).name(ChatColor.GREEN + "Set Time - " + minutes + ":" + seconds).get(), (m, e) -> {
        for (Option option : game.getOptions()) {
            if (option instanceof WinAfterTimeoutOption) {
                ((WinAfterTimeoutOption) option).setTimeRemaining(finalMinutes * 60 + finalSeconds);
                openTimerSetMenu(player, game, finalMinutes, finalSeconds);
                break;
            }
        }
    });
    menu.openForPlayer(player);
}
Also used : ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) WinAfterTimeoutOption(com.ebicep.warlords.game.option.WinAfterTimeoutOption) WinAfterTimeoutOption(com.ebicep.warlords.game.option.WinAfterTimeoutOption) Option(com.ebicep.warlords.game.option.Option) Menu(com.ebicep.warlords.menu.Menu)

Example 10 with ItemBuilder

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

the class DebugMenuGameOptions method openTeamScoreEditorMenu.

public static void openTeamScoreEditorMenu(Player player, Game game) {
    Menu menu = new Menu("Select Team", 9 * 4);
    int x = 1;
    for (Team team : TeamMarker.getTeams(game)) {
        menu.setItem(x, 1, new ItemBuilder(team.item).name(team.teamColor + team.name).get(), (m, e) -> openScoreEditorMenu(player, game, team, game.getPoints(team)));
        x++;
    }
    menu.setItem(3, 3, MENU_BACK, (m, e) -> openGameEditorMenu(player, game));
    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)

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