Search in sources :

Example 1 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class SurvivalSlimefunGuide method displayRecipes.

@ParametersAreNonnullByDefault
private void displayRecipes(Player p, PlayerProfile profile, ChestMenu menu, RecipeDisplayItem sfItem, int page) {
    List<ItemStack> recipes = sfItem.getDisplayRecipes();
    if (!recipes.isEmpty()) {
        menu.addItem(53, null);
        if (page == 0) {
            for (int i = 27; i < 36; i++) {
                menu.replaceExistingItem(i, new CustomItemStack(ChestMenuUtils.getBackground(), sfItem.getRecipeSectionLabel(p)));
                menu.addMenuClickHandler(i, ChestMenuUtils.getEmptyClickHandler());
            }
        }
        int pages = (recipes.size() - 1) / 18 + 1;
        menu.replaceExistingItem(28, ChestMenuUtils.getPreviousButton(p, page + 1, pages));
        menu.addMenuClickHandler(28, (pl, slot, itemstack, action) -> {
            if (page > 0) {
                displayRecipes(pl, profile, menu, sfItem, page - 1);
                pl.playSound(pl.getLocation(), sound, 1, 1);
            }
            return false;
        });
        menu.replaceExistingItem(34, ChestMenuUtils.getNextButton(p, page + 1, pages));
        menu.addMenuClickHandler(34, (pl, slot, itemstack, action) -> {
            if (recipes.size() > (18 * (page + 1))) {
                displayRecipes(pl, profile, menu, sfItem, page + 1);
                pl.playSound(pl.getLocation(), sound, 1, 1);
            }
            return false;
        });
        int inputs = 36;
        int outputs = 45;
        for (int i = 0; i < 18; i++) {
            int slot;
            if (i % 2 == 0) {
                slot = inputs;
                inputs++;
            } else {
                slot = outputs;
                outputs++;
            }
            addDisplayRecipe(menu, profile, recipes, slot, i, page);
        }
    }
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 2 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class SurvivalSlimefunGuide method showItemGroup.

private void showItemGroup(ChestMenu menu, Player p, PlayerProfile profile, ItemGroup group, int index) {
    if (!(group instanceof LockedItemGroup) || !isSurvivalMode() || ((LockedItemGroup) group).hasUnlocked(p, profile)) {
        menu.addItem(index, group.getItem(p));
        menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
            openItemGroup(profile, group, 1);
            return false;
        });
    } else {
        List<String> lore = new ArrayList<>();
        lore.add("");
        for (String line : Slimefun.getLocalization().getMessages(p, "guide.locked-itemgroup")) {
            lore.add(ChatColor.WHITE + line);
        }
        lore.add("");
        for (ItemGroup parent : ((LockedItemGroup) group).getParents()) {
            lore.add(parent.getItem(p).getItemMeta().getDisplayName());
        }
        menu.addItem(index, new CustomItemStack(Material.BARRIER, "&4" + Slimefun.getLocalization().getMessage(p, "guide.locked") + " &7- &f" + group.getItem(p).getItemMeta().getDisplayName(), lore.toArray(new String[0])));
        menu.addMenuClickHandler(index, ChestMenuUtils.getEmptyClickHandler());
    }
}
Also used : LockedItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup) 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) ArrayList(java.util.ArrayList) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack)

Example 3 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack 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 4 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack 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 5 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack 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)

Aggregations

CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)172 Test (org.junit.jupiter.api.Test)100 DisplayName (org.junit.jupiter.api.DisplayName)90 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)83 ItemStack (org.bukkit.inventory.ItemStack)70 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)43 NamespacedKey (org.bukkit.NamespacedKey)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Player (org.bukkit.entity.Player)25 ChestMenu (me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)22 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)20 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)18 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)12 PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)11 FlexItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup)10 ArrayList (java.util.ArrayList)10 Nonnull (javax.annotation.Nonnull)10 Material (org.bukkit.Material)10 LockedItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup)9 Location (org.bukkit.Location)9