Search in sources :

Example 26 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu 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)

Example 27 with ChestMenu

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

the class SurvivalSlimefunGuide method showMinecraftRecipe.

private void showMinecraftRecipe(Recipe[] recipes, int index, ItemStack item, PlayerProfile profile, Player p, boolean addToHistory) {
    Recipe recipe = recipes[index];
    ItemStack[] recipeItems = new ItemStack[9];
    RecipeType recipeType = RecipeType.NULL;
    ItemStack result = null;
    Optional<MinecraftRecipe<? super Recipe>> optional = MinecraftRecipe.of(recipe);
    AsyncRecipeChoiceTask task = new AsyncRecipeChoiceTask();
    if (optional.isPresent()) {
        showRecipeChoices(recipe, recipeItems, task);
        recipeType = new RecipeType(optional.get());
        result = recipe.getResult();
    } else {
        recipeItems = new ItemStack[] { null, null, null, null, new CustomItemStack(Material.BARRIER, "&4We are somehow unable to show you this Recipe :/"), null, null, null, null };
    }
    ChestMenu menu = create(p);
    if (addToHistory) {
        profile.getGuideHistory().add(item, index);
    }
    displayItem(menu, profile, p, item, result, recipeType, recipeItems, task);
    if (recipes.length > 1) {
        for (int i = 27; i < 36; i++) {
            menu.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
        }
        menu.addItem(28, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
            if (index > 0) {
                showMinecraftRecipe(recipes, index - 1, item, profile, p, true);
            }
            return false;
        });
        menu.addItem(34, ChestMenuUtils.getNextButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
            if (index < recipes.length - 1) {
                showMinecraftRecipe(recipes, index + 1, item, profile, p, true);
            }
            return false;
        });
    }
    menu.open(p);
    if (!task.isEmpty()) {
        task.start(menu.toInventory());
    }
}
Also used : MinecraftRecipe(io.github.bakedlibs.dough.recipes.MinecraftRecipe) Recipe(org.bukkit.inventory.Recipe) RecipeType(io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType) MinecraftRecipe(io.github.bakedlibs.dough.recipes.MinecraftRecipe) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) AsyncRecipeChoiceTask(io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask)

Example 28 with ChestMenu

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

the class SurvivalSlimefunGuide method displayItem.

@Override
@ParametersAreNonnullByDefault
public void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory) {
    Player p = profile.getPlayer();
    if (p == null) {
        return;
    }
    ChestMenu menu = create(p);
    Optional<String> wiki = item.getWikipage();
    if (wiki.isPresent()) {
        menu.addItem(8, new CustomItemStack(Material.KNOWLEDGE_BOOK, ChatColor.WHITE + Slimefun.getLocalization().getMessage(p, "guide.tooltips.wiki"), "", ChatColor.GRAY + "\u21E8 " + ChatColor.GREEN + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup")));
        menu.addMenuClickHandler(8, (pl, slot, itemstack, action) -> {
            pl.closeInventory();
            ChatUtils.sendURL(pl, wiki.get());
            return false;
        });
    }
    AsyncRecipeChoiceTask task = new AsyncRecipeChoiceTask();
    if (addToHistory) {
        profile.getGuideHistory().add(item);
    }
    ItemStack result = item.getRecipeOutput();
    RecipeType recipeType = item.getRecipeType();
    ItemStack[] recipe = item.getRecipe();
    displayItem(menu, profile, p, item, result, recipeType, recipe, task);
    if (item instanceof RecipeDisplayItem) {
        displayRecipes(p, profile, menu, (RecipeDisplayItem) item, 0);
    }
    menu.open(p);
    if (!task.isEmpty()) {
        task.start(menu.toInventory());
    }
}
Also used : Player(org.bukkit.entity.Player) RecipeDisplayItem(io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem) RecipeType(io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) AsyncRecipeChoiceTask(io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 29 with ChestMenu

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

the class SurvivalSlimefunGuide method displaySlimefunItem.

private void displaySlimefunItem(ChestMenu menu, ItemGroup itemGroup, Player p, PlayerProfile profile, SlimefunItem sfitem, int page, int index) {
    Research research = sfitem.getResearch();
    if (isSurvivalMode() && !hasPermission(p, sfitem)) {
        List<String> message = Slimefun.getPermissionsService().getLore(sfitem);
        menu.addItem(index, new CustomItemStack(ChestMenuUtils.getNoPermissionItem(), sfitem.getItemName(), message.toArray(new String[0])));
        menu.addMenuClickHandler(index, ChestMenuUtils.getEmptyClickHandler());
    } else if (isSurvivalMode() && research != null && !profile.hasUnlocked(research)) {
        menu.addItem(index, new CustomItemStack(ChestMenuUtils.getNotResearchedItem(), ChatColor.WHITE + ItemUtils.getItemName(sfitem.getItem()), "&4&l" + Slimefun.getLocalization().getMessage(p, "guide.locked"), "", "&a> Click to unlock", "", "&7Cost: &b" + research.getCost() + " Level(s)"));
        menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
            research.unlockFromGuide(this, p, profile, sfitem, itemGroup, page);
            return false;
        });
    } else {
        menu.addItem(index, sfitem.getItem());
        menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
            try {
                if (isSurvivalMode()) {
                    displayItem(profile, sfitem, true);
                } else {
                    if (sfitem instanceof MultiBlockMachine) {
                        Slimefun.getLocalization().sendMessage(pl, "guide.cheat.no-multiblocks");
                    } else {
                        ItemStack clonedItem = sfitem.getItem().clone();
                        if (action.isShiftClicked()) {
                            clonedItem.setAmount(clonedItem.getMaxStackSize());
                        }
                        pl.getInventory().addItem(clonedItem);
                    }
                }
            } catch (Exception | LinkageError x) {
                printErrorMessage(pl, x);
            }
            return false;
        });
    }
}
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) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) Research(io.github.thebusybiscuit.slimefun4.api.researches.Research) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) MultiBlockMachine(io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine)

Example 30 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project SupremeExpansion by RelativoBR.

the class AbstractQuarry method showMachine.

@ParametersAreNonnullByDefault
protected void showMachine(Player p, Block b) {
    Validate.notNull(p, "The Player should not be null");
    Validate.notNull(b, "The Block should not be null");
    ChestMenu menu = new ChestMenu(getItemName());
    menu.setPlayerInventoryClickable(false);
    menu.setEmptySlotsClickable(false);
    ChestMenuUtils.drawBackground(menu, InventoryRecipe.QUARRY_BORDER);
    ChestMenuUtils.drawBackground(menu, InventoryRecipe.QUARRY_OUTPUT);
    ChestMenuUtils.drawBackground(menu, InventoryRecipe.QUARRY_OUTPUT_BORDER);
    for (int i = 0; i < InventoryRecipe.QUARRY_INPUT_BORDER.length; ++i) {
        int slot = InventoryRecipe.QUARRY_INPUT_BORDER[i];
        menu.addItem(slot, ChestMenuUtils.getInputSlotTexture(), ChestMenuUtils.getEmptyClickHandler());
    }
    final String powerPerSecond = LoreBuilder.powerPerSecond(getEnergyConsumption());
    final String powerCharged = LoreBuilder.powerCharged(energyCharge, getCapacity());
    final String infoSpeed = UtilEnergy.timePerItem((TICK_DELAY * delaySpeed) / 2);
    if (energyCharge < getEnergyConsumption() || !this.enabled) {
        menu.addItem(InventoryRecipe.QUARRY_STATUS, new CustomItemStack(Material.OBSIDIAN, ChatColor.RED + "NOT-ACTIVE", powerPerSecond, powerCharged, infoSpeed));
        menu.addMenuClickHandler(InventoryRecipe.QUARRY_STATUS, ChestMenuUtils.getEmptyClickHandler());
    } else {
        menu.addItem(InventoryRecipe.QUARRY_STATUS, new CustomItemStack(Material.GLOWSTONE, ChatColor.GREEN + "ACTIVE", powerPerSecond, powerCharged, infoSpeed));
        menu.addMenuClickHandler(InventoryRecipe.QUARRY_STATUS, ChestMenuUtils.getEmptyClickHandler());
    }
    if (enabled) {
        menu.addItem(InventoryRecipe.QUARRY_BUTTON, new CustomItemStack(Material.EMERALD_BLOCK, Slimefun.getLocalization().getMessages(p, "messages.auto-crafting.tooltips.enabled")));
        menu.addMenuClickHandler(InventoryRecipe.QUARRY_BUTTON, (pl, item, slot, action) -> {
            enabled = false;
            showMachine(p, b);
            return false;
        });
    } else {
        menu.addItem(InventoryRecipe.QUARRY_BUTTON, new CustomItemStack(Material.REDSTONE_BLOCK, Slimefun.getLocalization().getMessages(p, "messages.auto-crafting.tooltips.disabled")));
        menu.addMenuClickHandler(InventoryRecipe.QUARRY_BUTTON, (pl, item, slot, action) -> {
            enabled = true;
            showMachine(p, b);
            return false;
        });
    }
    p.playSound(p.getLocation(), Sound.BLOCK_BARREL_OPEN, 1, 1);
    menu.open(p);
}
Also used : CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) 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