Search in sources :

Example 6 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project buildinggame by stefvanschie.

the class ArenaSelection method show.

/**
 * {@inheritDoc}
 *
 * @since 5.6.0
 */
@Override
public void show(@NotNull HumanEntity humanEntity) {
    var outlinePane = new OutlinePane(0, 0, 9, 6);
    for (Arena arena : ArenaManager.getInstance().getArenas()) {
        if (arena.canJoin()) {
            continue;
        }
        var item = new ItemStack(Material.LIME_WOOL);
        ItemMeta itemMeta = item.getItemMeta();
        itemMeta.setDisplayName(ChatColor.GREEN + arena.getName());
        item.setItemMeta(itemMeta);
        outlinePane.addItem(new GuiItem(item, event -> {
            arena.join((Player) humanEntity);
            event.setCancelled(true);
        }));
    }
    addPane(outlinePane);
    super.show(humanEntity);
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) Main(com.gmail.stefvanschiedev.buildinggame.Main) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) ChatColor(org.bukkit.ChatColor) NotNull(org.jetbrains.annotations.NotNull) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) Material(org.bukkit.Material) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) Player(org.bukkit.entity.Player) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) ItemStack(org.bukkit.inventory.ItemStack) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 7 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project buildinggame by stefvanschie.

the class SubjectMenu method initializePages.

/**
 * Initializes the pages for this gui
 *
 * @param gui the gui for which to initialize pages
 * @param paginatedPane the paginated pane
 * @since 5.6.0
 */
private void initializePages(@NotNull ChestGui gui, @NotNull PaginatedPane paginatedPane) {
    paginatedPane.clear();
    for (var page = 0; page < Math.ceil((float) subjects.size() / (paginatedPane.getHeight() * paginatedPane.getLength())); page++) {
        var pane = new OutlinePane(0, 0, paginatedPane.getLength(), paginatedPane.getHeight());
        pane.setOrientation(Orientable.Orientation.valueOf(CONFIG.getString("subject-gui.vote-items.orientation").toUpperCase(Locale.getDefault())));
        for (var index = 0; index < paginatedPane.getLength() * paginatedPane.getHeight(); index++) {
            if (subjects.size() - 1 < index + (page * paginatedPane.getLength() * paginatedPane.getHeight()))
                break;
            final String subject = ChatColor.stripColor(subjects.get(index + (page * paginatedPane.getLength() * paginatedPane.getHeight())));
            if (getSubjectVote(subject) == null)
                votes.add(new SubjectVote(subject, 0));
            Material material = SettingsManager.getInstance().getMaterial("subject-gui.vote-items.item.id", Material.BARRIER);
            var item = new ItemStack(material);
            var meta = item.getItemMeta();
            meta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.subject.name").replace("%subject%", subject)));
            var lores = new ArrayList<String>();
            MESSAGES.getStringList("subject-gui.subject.lores").forEach(lore -> lores.add(MessageManager.translate(lore.replace("%votes%", getSubjectVote(subject).getVotes() + ""))));
            meta.setLore(lores);
            item.setItemMeta(meta);
            pane.addItem(new GuiItem(item, event -> {
                addVote((Player) event.getWhoClicked(), subject);
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        initializePages(gui, paginatedPane);
                        update();
                    }
                }.runTaskLater(Main.getInstance(), 1L);
                event.setCancelled(true);
            }));
            if (CONFIG.getBoolean("subject-gui.percentage-bars.enable")) {
                int x;
                int y;
                if (pane.getOrientation() == Orientable.Orientation.HORIZONTAL) {
                    x = index % pane.getLength();
                    y = (int) Math.floor((double) index / pane.getLength());
                } else if (pane.getOrientation() == Orientable.Orientation.VERTICAL) {
                    x = (int) Math.floor((double) index / pane.getHeight());
                    y = index % pane.getHeight();
                } else {
                    throw new UnsupportedOperationException("Unknown orientation found");
                }
                int xOffset = CONFIG.getInt("subject-gui.percentage-bars.offset.x");
                int yOffset = CONFIG.getInt("subject-gui.percentage-bars.offset.y");
                int totalVotes = votes.stream().mapToInt(SubjectVote::getVotes).sum();
                int userVotes = getSubjectVote(subject).getVotes();
                var percentageBar = new PercentageBar(x + xOffset, y + yOffset, 7, 1);
                percentageBar.setPercentage(totalVotes == 0 ? 0 : (float) userVotes / totalVotes);
                gui.addPane(percentageBar);
            }
        }
        paginatedPane.addPane(page, pane);
    }
}
Also used : SubjectVote(com.gmail.stefvanschiedev.buildinggame.utils.SubjectVote) HumanEntity(org.bukkit.entity.HumanEntity) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) java.util(java.util) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) Orientable(com.github.stefvanschie.inventoryframework.pane.Orientable) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Player(org.bukkit.entity.Player) SubjectVote(com.gmail.stefvanschiedev.buildinggame.utils.SubjectVote) ItemStack(org.bukkit.inventory.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) Main(com.gmail.stefvanschiedev.buildinggame.Main) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) PercentageBar(com.github.stefvanschie.inventoryframework.pane.component.PercentageBar) ChatColor(org.bukkit.ChatColor) NotNull(org.jetbrains.annotations.NotNull) Material(org.bukkit.Material) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) Player(org.bukkit.entity.Player) PercentageBar(com.github.stefvanschie.inventoryframework.pane.component.PercentageBar) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Material(org.bukkit.Material) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) ItemStack(org.bukkit.inventory.ItemStack)

Example 8 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project buildinggame by stefvanschie.

the class TeamSelection method show.

/**
 * {@inheritDoc}
 *
 * @since 5.6.0
 */
@Override
public void show(@NotNull HumanEntity humanEntity) {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    int iteration = 0;
    var outlinePane = new OutlinePane(0, 0, 9, (int) Math.max(Math.ceil(arena.getPlots().size() / 9.0), 6));
    for (final var plot : arena.getPlots()) {
        Material material = SettingsManager.getInstance().getMaterial("team-selection.team." + (iteration + 1) + ".id", Material.BARRIER);
        var item = new ItemStack(material);
        var itemMeta = item.getItemMeta();
        itemMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("team-gui.team.name").replace("%plot%", plot.getId() + "").replace("%plot_players%", plot.getPlayers() + "").replace("%plot_max_players%", plot.getMaxPlayers() + ""), (Player) humanEntity));
        List<String> lores = config.getBoolean("team-selection.show-names-as-lore") ? plot.getGamePlayers().stream().map(gamePlayer -> gamePlayer.getPlayer().getName()).collect(Collectors.toList()) : MESSAGES.getStringList("team-gui.team.lores").stream().map(lore -> MessageManager.translate(lore, (Player) humanEntity)).collect(Collectors.toList());
        itemMeta.setLore(lores);
        item.setItemMeta(itemMeta);
        outlinePane.addItem(new GuiItem(item, event -> {
            Player p = (Player) event.getWhoClicked();
            var previousPlot = arena.getPlot(p);
            var gamePlayer = previousPlot.getGamePlayer(p);
            if (plot.join(gamePlayer))
                previousPlot.leave(gamePlayer);
            p.closeInventory();
            update();
            event.setCancelled(true);
        }));
        iteration++;
    }
    addPane(outlinePane);
    super.show(humanEntity);
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) NotNull(org.jetbrains.annotations.NotNull) Material(org.bukkit.Material) Player(org.bukkit.entity.Player) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) Material(org.bukkit.Material) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ItemStack(org.bukkit.inventory.ItemStack)

Example 9 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project EmployMe by DavidTheExplorer.

the class ItemPaletteGUI method createControlPane.

/*
	 * Panes
	 */
private Pane createControlPane() {
    OutlinePane pane = new OutlinePane(0, 5, 9, 1, Priority.LOW);
    pane.setOrientation(HORIZONTAL);
    pane.setGap(3);
    pane.addItem(createController("MHF_ArrowLeft", this.messageService.getMessage(INVENTORY_ITEM_PALETTE_BACK_ITEM_NAME).first(), currentPage -> currentPage > 0, currentPage -> --currentPage));
    pane.addItem(createEnglishSearchItem());
    pane.addItem(createController("MHF_ArrowRight", this.messageService.getMessage(INVENTORY_ITEM_PALETTE_NEXT_ITEM_NAME).first(), currentPage -> currentPage < (this.itemsPane.getPages() - 1), currentPage -> ++currentPage));
    return pane;
}
Also used : Arrays(java.util.Arrays) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) IntUnaryOperator(java.util.function.IntUnaryOperator) RewardService(dte.employme.job.rewards.service.RewardService) INVENTORY_ITEM_PALETTE_ENGLISH_SEARCH_ITEM_NAME(dte.employme.messages.MessageKey.INVENTORY_ITEM_PALETTE_ENGLISH_SEARCH_ITEM_NAME) Player(org.bukkit.entity.Player) Deque(java.util.Deque) IntPredicate(java.util.function.IntPredicate) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Conversation(org.bukkit.conversations.Conversation) Collectors.toCollection(java.util.stream.Collectors.toCollection) Reward(dte.employme.job.rewards.Reward) INVENTORY_ITEM_PALETTE_NEXT_ITEM_NAME(dte.employme.messages.MessageKey.INVENTORY_ITEM_PALETTE_NEXT_ITEM_NAME) ConversationFactory(org.bukkit.conversations.ConversationFactory) HORIZONTAL(com.github.stefvanschie.inventoryframework.pane.Orientable.Orientation.HORIZONTAL) LinkedList(java.util.LinkedList) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) InventoryFrameworkUtils.createRectangle(dte.employme.utils.InventoryFrameworkUtils.createRectangle) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) InventoryUtils.createWall(dte.employme.utils.InventoryUtils.createWall) Priority(com.github.stefvanschie.inventoryframework.pane.Pane.Priority) ItemStack(org.bukkit.inventory.ItemStack) MessageService(dte.employme.messages.service.MessageService) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) JobGoalPrompt(dte.employme.job.prompts.JobGoalPrompt) ItemBuilder(dte.employme.utils.items.ItemBuilder) INVENTORY_ITEM_PALETTE_TITLE(dte.employme.messages.MessageKey.INVENTORY_ITEM_PALETTE_TITLE) Conversations(dte.employme.utils.Conversations) MaterialUtils(dte.employme.utils.MaterialUtils) MapBuilder(dte.employme.utils.java.MapBuilder) INVENTORY_ITEM_PALETTE_BACK_ITEM_NAME(dte.employme.messages.MessageKey.INVENTORY_ITEM_PALETTE_BACK_ITEM_NAME) Pane(com.github.stefvanschie.inventoryframework.pane.Pane) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane)

Example 10 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project EmployMe by DavidTheExplorer.

the class ItemsRewardPreviewGUI method createItemsPane.

private Pane createItemsPane() {
    OutlinePane pane = new OutlinePane(0, 0, 9, 6, Priority.LOWEST);
    this.itemsReward.getItems().stream().map(item -> new GuiItem(new ItemStack(item))).forEach(pane::addItem);
    return pane;
}
Also used : OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) MessageService(dte.employme.messages.service.MessageService) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) ItemsReward(dte.employme.job.rewards.ItemsReward) INVENTORY_ITEMS_REWARD_PREVIEW_TITLE(dte.employme.messages.MessageKey.INVENTORY_ITEMS_REWARD_PREVIEW_TITLE) Pane(com.github.stefvanschie.inventoryframework.pane.Pane) Priority(com.github.stefvanschie.inventoryframework.pane.Pane.Priority) ItemStack(org.bukkit.inventory.ItemStack) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

OutlinePane (com.github.stefvanschie.inventoryframework.pane.OutlinePane)23 GuiItem (com.github.stefvanschie.inventoryframework.gui.GuiItem)17 ChestGui (com.github.stefvanschie.inventoryframework.gui.type.ChestGui)17 ItemStack (org.bukkit.inventory.ItemStack)16 PaginatedPane (com.github.stefvanschie.inventoryframework.pane.PaginatedPane)9 StaticPane (com.github.stefvanschie.inventoryframework.pane.StaticPane)9 Material (org.bukkit.Material)7 Player (org.bukkit.entity.Player)7 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)5 HumanEntity (org.bukkit.entity.HumanEntity)5 NotNull (org.jetbrains.annotations.NotNull)5 Main (com.gmail.stefvanschiedev.buildinggame.Main)4 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)4 ChatColor (org.bukkit.ChatColor)4 Pane (com.github.stefvanschie.inventoryframework.pane.Pane)3 Priority (com.github.stefvanschie.inventoryframework.pane.Pane.Priority)3 SettingsManager (com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager)3 MessageService (dte.employme.messages.service.MessageService)3 IOException (java.io.IOException)3 List (java.util.List)3