Search in sources :

Example 1 with MenuClickHandler

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.MenuClickHandler in project Slimefun4 by Slimefun.

the class SurvivalSlimefunGuide method displayItem.

private void displayItem(ChestMenu menu, PlayerProfile profile, Player p, Object item, ItemStack output, RecipeType recipeType, ItemStack[] recipe, AsyncRecipeChoiceTask task) {
    addBackButton(menu, 0, p, profile);
    MenuClickHandler clickHandler = (pl, slot, itemstack, action) -> {
        try {
            if (itemstack != null && itemstack.getType() != Material.BARRIER) {
                displayItem(profile, itemstack, 0, true);
            }
        } catch (Exception | LinkageError x) {
            printErrorMessage(pl, x);
        }
        return false;
    };
    boolean isSlimefunRecipe = item instanceof SlimefunItem;
    for (int i = 0; i < 9; i++) {
        ItemStack recipeItem = getDisplayItem(p, isSlimefunRecipe, recipe[i]);
        menu.addItem(recipeSlots[i], recipeItem, clickHandler);
        if (recipeItem != null && item instanceof MultiBlockMachine) {
            for (Tag<Material> tag : MultiBlock.getSupportedTags()) {
                if (tag.isTagged(recipeItem.getType())) {
                    task.add(recipeSlots[i], tag);
                    break;
                }
            }
        }
    }
    menu.addItem(10, recipeType.getItem(p), ChestMenuUtils.getEmptyClickHandler());
    menu.addItem(16, output, ChestMenuUtils.getEmptyClickHandler());
}
Also used : ItemFlag(org.bukkit.inventory.ItemFlag) MaterialChoice(org.bukkit.inventory.RecipeChoice.MaterialChoice) Arrays(java.util.Arrays) SlimefunGuideSettings(io.github.thebusybiscuit.slimefun4.core.guide.options.SlimefunGuideSettings) Player(org.bukkit.entity.Player) ItemUtils(io.github.bakedlibs.dough.items.ItemUtils) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) Inventory(org.bukkit.inventory.Inventory) PlayerProfile(io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile) RecipeType(io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType) Locale(java.util.Locale) SlimefunGuideMode(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode) MinecraftRecipe(io.github.bakedlibs.dough.recipes.MinecraftRecipe) Recipe(org.bukkit.inventory.Recipe) Material(org.bukkit.Material) ChatInput(io.github.bakedlibs.dough.chat.ChatInput) SlimefunGuideImplementation(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation) ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) ChestMenuUtils(io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils) Sound(org.bukkit.Sound) SlimefunAddon(io.github.thebusybiscuit.slimefun4.api.SlimefunAddon) Research(io.github.thebusybiscuit.slimefun4.api.researches.Research) ChatUtils(io.github.thebusybiscuit.slimefun4.utils.ChatUtils) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) Optional(java.util.Optional) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) Validate(org.apache.commons.lang.Validate) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) LockedItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup) SlimefunGuideItem(io.github.thebusybiscuit.slimefun4.utils.itemstack.SlimefunGuideItem) Tag(org.bukkit.Tag) RecipeChoice(org.bukkit.inventory.RecipeChoice) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) AsyncRecipeChoiceTask(io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask) MenuClickHandler(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.MenuClickHandler) RecipeDisplayItem(io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem) MultiBlock(io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) FlexItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) MultiBlockMachine(io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine) SubItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.SubItemGroup) ChatColor(org.bukkit.ChatColor) GuideHistory(io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory) SlimefunGuide(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide) MenuClickHandler(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.MenuClickHandler) Material(org.bukkit.Material) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) MultiBlockMachine(io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine)

Aggregations

ChatInput (io.github.bakedlibs.dough.chat.ChatInput)1 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)1 ItemUtils (io.github.bakedlibs.dough.items.ItemUtils)1 MinecraftRecipe (io.github.bakedlibs.dough.recipes.MinecraftRecipe)1 SlimefunAddon (io.github.thebusybiscuit.slimefun4.api.SlimefunAddon)1 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)1 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)1 FlexItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup)1 LockedItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup)1 SubItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.SubItemGroup)1 PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)1 RecipeType (io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType)1 Research (io.github.thebusybiscuit.slimefun4.api.researches.Research)1 RecipeDisplayItem (io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem)1 GuideHistory (io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory)1 SlimefunGuide (io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide)1 SlimefunGuideImplementation (io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation)1 SlimefunGuideMode (io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode)1 SlimefunGuideSettings (io.github.thebusybiscuit.slimefun4.core.guide.options.SlimefunGuideSettings)1 MultiBlock (io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock)1