Search in sources :

Example 6 with ChestMenu

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

the class SurvivalSlimefunGuide method openSearch.

@Override
@ParametersAreNonnullByDefault
public void openSearch(PlayerProfile profile, String input, boolean addToHistory) {
    Player p = profile.getPlayer();
    if (p == null) {
        return;
    }
    ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "guide.search.inventory").replace("%item%", ChatUtils.crop(ChatColor.WHITE, input)));
    String searchTerm = input.toLowerCase(Locale.ROOT);
    if (addToHistory) {
        profile.getGuideHistory().add(searchTerm);
    }
    menu.setEmptySlotsClickable(false);
    createHeader(p, profile, menu);
    addBackButton(menu, 1, p, profile);
    int index = 9;
    // Find items and add them
    for (SlimefunItem slimefunItem : Slimefun.getRegistry().getEnabledSlimefunItems()) {
        if (index == 44) {
            break;
        }
        if (!slimefunItem.isHidden() && !isItemGroupHidden(p, slimefunItem) && isSearchFilterApplicable(slimefunItem, searchTerm)) {
            ItemStack itemstack = new CustomItemStack(slimefunItem.getItem(), meta -> {
                ItemGroup itemGroup = slimefunItem.getItemGroup();
                meta.setLore(Arrays.asList("", ChatColor.DARK_GRAY + "\u21E8 " + ChatColor.WHITE + itemGroup.getDisplayName(p)));
                meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS);
            });
            menu.addItem(index, itemstack);
            menu.addMenuClickHandler(index, (pl, slot, itm, action) -> {
                try {
                    if (!isSurvivalMode()) {
                        pl.getInventory().addItem(slimefunItem.getItem().clone());
                    } else {
                        displayItem(profile, slimefunItem, true);
                    }
                } catch (Exception | LinkageError x) {
                    printErrorMessage(pl, x);
                }
                return false;
            });
            index++;
        }
    }
    menu.open(p);
}
Also used : Player(org.bukkit.entity.Player) ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) LockedItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup) FlexItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup) SubItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.SubItemGroup) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 7 with ChestMenu

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

the class ProgrammableAndroid method openScriptEditor.

public void openScriptEditor(Player p, Block b) {
    ChestMenu menu = new ChestMenu(ChatColor.DARK_AQUA + Slimefun.getLocalization().getMessage(p, "android.scripts.editor"));
    menu.setEmptySlotsClickable(false);
    menu.addItem(1, new CustomItemStack(HeadTexture.SCRIPT_FORWARD.getAsItemStack(), "&2> Edit Script", "", "&aEdits your current Script"));
    menu.addMenuClickHandler(1, (pl, slot, item, action) -> {
        String script = BlockStorage.getLocationInfo(b.getLocation()).getString("script");
        // Fixes #2937
        if (script != null) {
            if (CommonPatterns.DASH.split(script).length <= MAX_SCRIPT_LENGTH) {
                openScript(pl, b, getScript(b.getLocation()));
            } else {
                pl.closeInventory();
                Slimefun.getLocalization().sendMessage(pl, "android.scripts.too-long");
            }
        } else {
            pl.closeInventory();
        }
        return false;
    });
    menu.addItem(3, new CustomItemStack(HeadTexture.SCRIPT_NEW.getAsItemStack(), "&4> Create new Script", "", "&cDeletes your current Script", "&cand creates a blank one"));
    menu.addMenuClickHandler(3, (pl, slot, item, action) -> {
        openScript(pl, b, DEFAULT_SCRIPT);
        return false;
    });
    menu.addItem(5, new CustomItemStack(HeadTexture.SCRIPT_DOWN.getAsItemStack(), "&6> Download a Script", "", "&eDownload a Script from the Server", "&eYou can edit or simply use it"));
    menu.addMenuClickHandler(5, (pl, slot, item, action) -> {
        openScriptDownloader(pl, b, 1);
        return false;
    });
    menu.addItem(8, new CustomItemStack(HeadTexture.SCRIPT_LEFT.getAsItemStack(), "&6> Back", "", "&7Return to the Android's interface"));
    menu.addMenuClickHandler(8, (pl, slot, item, action) -> {
        BlockMenu inv = BlockStorage.getInventory(b);
        // Fixes #2937
        if (inv != null) {
            inv.open(pl);
        } else {
            pl.closeInventory();
        }
        return false;
    });
    menu.open(p);
}
Also used : BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)

Example 8 with ChestMenu

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

the class ProgrammableAndroid method openScriptDownloader.

protected void openScriptDownloader(Player p, Block b, int page) {
    ChestMenu menu = new ChestMenu("Android Scripts");
    menu.setEmptySlotsClickable(false);
    menu.addMenuOpeningHandler(pl -> pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_HAT, 0.7F, 0.7F));
    List<Script> scripts = Script.getUploadedScripts(getAndroidType());
    int pages = (scripts.size() / 45) + 1;
    for (int i = 45; i < 54; i++) {
        menu.addItem(i, ChestMenuUtils.getBackground());
        menu.addMenuClickHandler(i, ChestMenuUtils.getEmptyClickHandler());
    }
    menu.addItem(46, ChestMenuUtils.getPreviousButton(p, page, pages));
    menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
        int next = page - 1;
        if (next < 1) {
            next = pages;
        }
        if (next != page) {
            openScriptDownloader(pl, b, next);
        }
        return false;
    });
    menu.addItem(48, new CustomItemStack(HeadTexture.SCRIPT_UP.getAsItemStack(), "&eUpload a Script", "", "&6Click &7to upload your Android's Script", "&7to the Server's database"));
    menu.addMenuClickHandler(48, (pl, slot, item, action) -> {
        uploadScript(pl, b, page);
        return false;
    });
    menu.addItem(50, ChestMenuUtils.getNextButton(p, page, pages));
    menu.addMenuClickHandler(50, (pl, slot, item, action) -> {
        int next = page + 1;
        if (next > pages) {
            next = 1;
        }
        if (next != page) {
            openScriptDownloader(pl, b, next);
        }
        return false;
    });
    menu.addItem(53, new CustomItemStack(HeadTexture.SCRIPT_LEFT.getAsItemStack(), "&6> Back", "", "&7Return to the Android's interface"));
    menu.addMenuClickHandler(53, (pl, slot, item, action) -> {
        openScriptEditor(pl, b);
        return false;
    });
    int index = 0;
    int categoryIndex = 45 * (page - 1);
    for (int i = 0; i < 45; i++) {
        int target = categoryIndex + i;
        if (target >= scripts.size()) {
            break;
        } else {
            Script script = scripts.get(target);
            menu.addItem(index, script.getAsItemStack(this, p), (player, slot, stack, action) -> {
                try {
                    if (action.isShiftClicked()) {
                        if (script.isAuthor(player)) {
                            Slimefun.getLocalization().sendMessage(player, "android.scripts.rating.own", true);
                        } else if (script.canRate(player)) {
                            script.rate(player, !action.isRightClicked());
                            openScriptDownloader(player, b, page);
                        } else {
                            Slimefun.getLocalization().sendMessage(player, "android.scripts.rating.already", true);
                        }
                    } else if (!action.isRightClicked()) {
                        script.download();
                        setScript(b.getLocation(), script.getSourceCode());
                        openScriptEditor(player, b);
                    }
                } catch (Exception x) {
                    Slimefun.logger().log(Level.SEVERE, "An Exception was thrown when a User tried to download a Script!", x);
                }
                return false;
            });
            index++;
        }
    }
    menu.open(p);
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)

Example 9 with ChestMenu

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

the class AbstractAutoCrafter method showRecipe.

/**
 * This shows the given {@link AbstractRecipe} to the {@link Player} in a preview window.
 *
 * @param p
 *            The {@link Player}
 * @param b
 *            The {@link Block} of the {@link AbstractAutoCrafter}
 * @param recipe
 *            The {@link AbstractRecipe} to show them
 */
@ParametersAreNonnullByDefault
protected void showRecipe(Player p, Block b, AbstractRecipe recipe) {
    Validate.notNull(p, "The Player should not be null");
    Validate.notNull(b, "The Block should not be null");
    Validate.notNull(recipe, "The Recipe should not be null");
    ChestMenu menu = new ChestMenu(getItemName());
    menu.setPlayerInventoryClickable(false);
    menu.setEmptySlotsClickable(false);
    ChestMenuUtils.drawBackground(menu, background);
    ChestMenuUtils.drawBackground(menu, 45, 46, 47, 48, 50, 51, 52, 53);
    if (recipe.isEnabled()) {
        menu.addItem(49, new CustomItemStack(Material.BARRIER, Slimefun.getLocalization().getMessages(p, "messages.auto-crafting.tooltips.enabled")));
        menu.addMenuClickHandler(49, (pl, item, slot, action) -> {
            if (action.isRightClicked()) {
                deleteRecipe(pl, b);
            } else {
                setRecipeEnabled(pl, b, false);
            }
            return false;
        });
    } else {
        menu.addItem(49, new CustomItemStack(HeadTexture.EXCLAMATION_MARK.getAsItemStack(), Slimefun.getLocalization().getMessages(p, "messages.auto-crafting.tooltips.disabled")));
        menu.addMenuClickHandler(49, (pl, item, slot, action) -> {
            if (action.isRightClicked()) {
                deleteRecipe(pl, b);
            } else {
                setRecipeEnabled(pl, b, true);
            }
            return false;
        });
    }
    // This makes the slots cycle through different ingredients
    AsyncRecipeChoiceTask task = new AsyncRecipeChoiceTask();
    recipe.show(menu, task);
    menu.open(p);
    p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
    // Only schedule the task if necessary
    if (!task.isEmpty()) {
        task.start(menu.toInventory());
    }
}
Also used : 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 10 with ChestMenu

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

the class SlimefunAutoCrafter method updateRecipe.

@Override
protected void updateRecipe(@Nonnull Block b, @Nonnull Player p) {
    ItemStack itemInHand = p.getInventory().getItemInMainHand();
    SlimefunItem item = SlimefunItem.getByItem(itemInHand);
    if (item != null && item.getRecipeType().equals(targetRecipeType)) {
        // Fixes #1161
        if (item.canUse(p, true)) {
            AbstractRecipe recipe = AbstractRecipe.of(item, targetRecipeType);
            if (recipe != null) {
                ChestMenu menu = new ChestMenu(getItemName());
                menu.setPlayerInventoryClickable(false);
                menu.setEmptySlotsClickable(false);
                ChestMenuUtils.drawBackground(menu, background);
                ChestMenuUtils.drawBackground(menu, 45, 46, 47, 48, 50, 51, 52, 53);
                menu.addItem(49, new CustomItemStack(Material.CRAFTING_TABLE, ChatColor.GREEN + Slimefun.getLocalization().getMessage(p, "messages.auto-crafting.select")));
                menu.addMenuClickHandler(49, (pl, stack, slot, action) -> {
                    setSelectedRecipe(b, recipe);
                    p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
                    Slimefun.getLocalization().sendMessage(p, "messages.auto-crafting.recipe-set");
                    showRecipe(p, b, recipe);
                    return false;
                });
                AsyncRecipeChoiceTask task = new AsyncRecipeChoiceTask();
                recipe.show(menu, task);
                menu.open(p);
                p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
                if (!task.isEmpty()) {
                    task.start(menu.toInventory());
                }
            } else {
                Slimefun.getLocalization().sendMessage(p, "messages.auto-crafting.no-recipes");
            }
        }
    } else {
        Slimefun.getLocalization().sendMessage(p, "messages.auto-crafting.no-recipes");
    }
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) AsyncRecipeChoiceTask(io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask)

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