Search in sources :

Example 31 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project InfinityExpansion by Mooy1.

the class InfinityGroup method open.

private static void open(@Nonnull Player player, @Nonnull BackEntry entry, boolean useHistory) {
    if (useHistory) {
        String id = HISTORY.get(player.getUniqueId());
        if (id != null) {
            openInfinityRecipe(player, id, entry);
            return;
        }
    }
    ChestMenu menu = new ChestMenu("&bInfinity Recipes");
    if (entry.bench != null) {
        menu.addMenuClickHandler(1, (player1, i, itemStack, clickAction) -> {
            entry.bench.open(player1);
            return false;
        });
    } else {
        menu.addMenuClickHandler(1, (player1, i, itemStack, clickAction) -> {
            entry.profile.getGuideHistory().goBack(entry.impl);
            return false;
        });
    }
    menu.addItem(0, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    menu.setEmptySlotsClickable(false);
    for (int i = 2; i < 9; i++) {
        menu.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    }
    menu.addItem(45, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    menu.addItem(46, ChestMenuUtils.getPreviousButton(player, 1, 1), ChestMenuUtils.getEmptyClickHandler());
    for (int i = 47; i < 52; i++) {
        menu.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    }
    menu.addItem(52, ChestMenuUtils.getNextButton(player, 1, 1), ChestMenuUtils.getEmptyClickHandler());
    menu.addItem(53, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    menu.addItem(1, new CustomItemStack(ChestMenuUtils.getBackButton(player, "", ChatColor.GRAY + Slimefun.getLocalization().getMessage(player, "guide.back.guide"))));
    int i = 9;
    for (Pair<SlimefunItemStack, ItemStack[]> item : ITEMS.values()) {
        if (i == 45) {
            break;
        }
        SlimefunItem sfItem = item.getFirstValue().getItem();
        if (sfItem == null) {
            return;
        }
        Research research = sfItem.getResearch();
        if (research != null && !entry.profile.hasUnlocked(research)) {
            ItemStack resItem = new CustomItemStack(ChestMenuUtils.getNotResearchedItem(), ChatColor.WHITE + ItemUtils.getItemName(sfItem.getItem()), "&4&l" + Slimefun.getLocalization().getMessage(player, "guide.locked"), "", "&a> Click to unlock", "", "&7Cost: &b" + research.getCost() + " Level(s)");
            menu.addItem(i, resItem, (p, slot, item1, action) -> {
                research.unlockFromGuide(GUIDE, p, entry.profile, sfItem, Groups.INFINITY, 0);
                return false;
            });
        } else {
            menu.addItem(i, item.getFirstValue(), (p, slot, item1, action) -> {
                openInfinityRecipe(p, item.getFirstValue().getItemId(), entry);
                return false;
            });
        }
        i++;
    }
    player.playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1, 1);
    HISTORY.put(player.getUniqueId(), null);
    menu.open(player);
}
Also used : CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Research(io.github.thebusybiscuit.slimefun4.api.researches.Research) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)

Example 32 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project InfinityExpansion by Mooy1.

the class InfinityGroup method openSlimefunRecipe.

@ParametersAreNonnullByDefault
private static void openSlimefunRecipe(Player player, BackEntry entry, String backID, LinkedList<SlimefunItem> slimefunHistory) {
    SlimefunItem slimefunItem = slimefunHistory.peekLast();
    if (slimefunItem == null) {
        return;
    }
    ItemStack output = slimefunItem.getRecipeOutput().clone();
    ChestMenu menu = new ChestMenu(ItemUtils.getItemName(output));
    menu.setEmptySlotsClickable(false);
    int length = slimefunHistory.size();
    menu.addItem(0, ChestMenuUtils.getBackButton(player, ""), (p, slot, item, action) -> {
        if (length == 1) {
            openInfinityRecipe(player, backID, entry);
        } else {
            slimefunHistory.removeLast();
            openSlimefunRecipe(player, entry, backID, slimefunHistory);
        }
        return false;
    });
    for (int i = 0; i < NORMAL_RECIPE_SLOTS.length; i++) {
        ItemStack recipeItem = slimefunItem.getRecipe()[i];
        if (recipeItem != null) {
            menu.addItem(NORMAL_RECIPE_SLOTS[i], recipeItem, (p, slot, item, action) -> {
                SlimefunItem recipeSlimefunItem = SlimefunItem.getByItem(recipeItem);
                if (recipeSlimefunItem != null) {
                    slimefunHistory.add(recipeSlimefunItem);
                    openSlimefunRecipe(player, entry, backID, slimefunHistory);
                }
                return false;
            });
        }
    }
    menu.addItem(NORMAL_RECIPE_TYPE, slimefunItem.getRecipeType().toItem(), ChestMenuUtils.getEmptyClickHandler());
    for (int slot : NORMAL_RECIPE_BACKGROUND) {
        menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    }
    menu.addItem(NORMAL_RECIPE_OUTPUT, output, ChestMenuUtils.getEmptyClickHandler());
    player.playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1, 1);
    menu.open(player);
}
Also used : SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 33 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project InfinityExpansion by Mooy1.

the class InfinityGroup method openInfinityRecipe.

@ParametersAreNonnullByDefault
private static void openInfinityRecipe(Player player, String id, BackEntry entry) {
    Pair<SlimefunItemStack, ItemStack[]> pair = ITEMS.get(id);
    if (pair == null) {
        return;
    }
    ChestMenu menu = new ChestMenu(Objects.requireNonNull(pair.getFirstValue().getDisplayName()));
    menu.setEmptySlotsClickable(false);
    menu.addItem(BACK, ChestMenuUtils.getBackButton(player, ""), (player12, i, itemStack, clickAction) -> {
        open(player12, entry, false);
        return false;
    });
    for (int i = 0; i < INFINITY_RECIPE_SLOTS.length; i++) {
        ItemStack recipeItem = pair.getSecondValue()[i];
        if (recipeItem != null) {
            menu.addItem(INFINITY_RECIPE_SLOTS[i], recipeItem, (p, slot, item, action) -> {
                SlimefunItem slimefunItem = SlimefunItem.getByItem(recipeItem);
                if (slimefunItem != null && !slimefunItem.isDisabled()) {
                    if (slimefunItem.getRecipeType() == InfinityWorkbench.TYPE) {
                        openInfinityRecipe(p, slimefunItem.getId(), entry);
                    } else {
                        LinkedList<SlimefunItem> list = new LinkedList<>();
                        list.add(slimefunItem);
                        openSlimefunRecipe(p, entry, id, list);
                    }
                }
                return false;
            });
        }
    }
    if (entry.bench == null) {
        menu.addItem(INFINITY_BENCH, Blocks.INFINITY_FORGE, (p, slot, item, action) -> {
            SlimefunItem slimefunItem = Blocks.INFINITY_FORGE.getItem();
            if (slimefunItem != null) {
                LinkedList<SlimefunItem> list = new LinkedList<>();
                list.add(slimefunItem);
                openSlimefunRecipe(p, entry, id, list);
            }
            return false;
        });
    } else {
        menu.addItem(INFINITY_BENCH, BENCH, (p, slot, item, action) -> {
            moveRecipe(p, entry.bench, pair, action.isRightClicked());
            return false;
        });
    }
    int page = IDS.indexOf(id);
    menu.addItem(PREV, ChestMenuUtils.getPreviousButton(player, page + 1, IDS.size()), (player1, i, itemStack, clickAction) -> {
        if (page > 0) {
            openInfinityRecipe(player1, IDS.get(page - 1), entry);
        }
        return false;
    });
    menu.addItem(NEXT, ChestMenuUtils.getNextButton(player, page + 1, IDS.size()), (player1, i, itemStack, clickAction) -> {
        if (page < IDS.size() - 1) {
            openInfinityRecipe(player1, IDS.get(page + 1), entry);
        }
        return false;
    });
    for (int slot : INFINITY_BACKGROUND) {
        menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    }
    for (int slot : INFINITY_OUTPUT_BORDER) {
        menu.addItem(slot, MenuBlock.OUTPUT_BORDER, ChestMenuUtils.getEmptyClickHandler());
    }
    menu.addItem(INFINITY_OUTPUT, pair.getFirstValue(), ChestMenuUtils.getEmptyClickHandler());
    for (int slot : WORKBENCH_BORDER) {
        menu.addItem(slot, INFO, ChestMenuUtils.getEmptyClickHandler());
    }
    player.playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1, 1);
    HISTORY.put(player.getUniqueId(), id);
    menu.open(player);
}
Also used : SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) LinkedList(java.util.LinkedList) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

ChestMenu (me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)33 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)23 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)18 ItemStack (org.bukkit.inventory.ItemStack)17 Player (org.bukkit.entity.Player)11 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)9 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)7 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)7 AsyncRecipeChoiceTask (io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask)7 ChestMenuUtils (io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils)7 Nonnull (javax.annotation.Nonnull)7 ChatColor (org.bukkit.ChatColor)7 CustomItemStack (io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)5 FlexItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup)5 ChatUtils (io.github.thebusybiscuit.slimefun4.utils.ChatUtils)5 Location (org.bukkit.Location)5 Sound (org.bukkit.Sound)5