Search in sources :

Example 11 with ChestMenu

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

the class VanillaAutoCrafter method updateRecipe.

@Override
protected void updateRecipe(@Nonnull Block b, @Nonnull Player p) {
    ItemStack item = p.getInventory().getItemInMainHand();
    List<Recipe> recipes = getRecipesFor(item);
    if (recipes.isEmpty()) {
        Slimefun.getLocalization().sendMessage(p, "messages.auto-crafting.no-recipes");
    } else {
        ChestMenu menu = new ChestMenu(getItemName());
        menu.setPlayerInventoryClickable(false);
        menu.setEmptySlotsClickable(false);
        ChestMenuUtils.drawBackground(menu, background);
        ChestMenuUtils.drawBackground(menu, 45, 47, 48, 50, 51, 53);
        AsyncRecipeChoiceTask task = new AsyncRecipeChoiceTask();
        offerRecipe(p, b, recipes, 0, menu, task);
        menu.open(p);
        task.start(menu.toInventory());
        p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
    }
}
Also used : ShapelessRecipe(org.bukkit.inventory.ShapelessRecipe) ShapedRecipe(org.bukkit.inventory.ShapedRecipe) Recipe(org.bukkit.inventory.Recipe) 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)

Example 12 with ChestMenu

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

the class PlayerLanguageOption method openLanguageSelection.

private void openLanguageSelection(Player p, ItemStack guide) {
    ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "guide.title.languages"));
    menu.setEmptySlotsClickable(false);
    menu.addMenuOpeningHandler(pl -> pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_HARP, 0.7F, 0.7F));
    for (int i = 0; i < 9; i++) {
        if (i == 1) {
            menu.addItem(1, ChestMenuUtils.getBackButton(p, "", "&7" + Slimefun.getLocalization().getMessage(p, "guide.back.settings")), (pl, slot, item, action) -> {
                SlimefunGuideSettings.openSettings(pl, guide);
                return false;
            });
        } else if (i == 7) {
            menu.addItem(7, new CustomItemStack(SlimefunUtils.getCustomHead(HeadTexture.ADD_NEW_LANGUAGE.getTexture()), Slimefun.getLocalization().getMessage(p, "guide.languages.translations.name"), "", "&7\u21E8 &e" + Slimefun.getLocalization().getMessage(p, "guide.languages.translations.lore")), (pl, slot, item, action) -> {
                ChatUtils.sendURL(pl, "https://github.com/Slimefun/Slimefun4/wiki/Translating-Slimefun");
                pl.closeInventory();
                return false;
            });
        } else {
            menu.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
        }
    }
    Language defaultLanguage = Slimefun.getLocalization().getDefaultLanguage();
    String defaultLanguageString = Slimefun.getLocalization().getMessage(p, "languages.default");
    menu.addItem(9, new CustomItemStack(defaultLanguage.getItem(), ChatColor.GRAY + defaultLanguageString + ChatColor.DARK_GRAY + " (" + defaultLanguage.getName(p) + ")", "", "&7\u21E8 &e" + Slimefun.getLocalization().getMessage(p, "guide.languages.select-default")), (pl, i, item, action) -> {
        Slimefun.instance().getServer().getPluginManager().callEvent(new PlayerLanguageChangeEvent(pl, Slimefun.getLocalization().getLanguage(pl), defaultLanguage));
        setSelectedOption(pl, guide, null);
        Slimefun.getLocalization().sendMessage(pl, "guide.languages.updated", msg -> msg.replace("%lang%", defaultLanguageString));
        SlimefunGuideSettings.openSettings(pl, guide);
        return false;
    });
    int slot = 10;
    for (Language language : Slimefun.getLocalization().getLanguages()) {
        menu.addItem(slot, new CustomItemStack(language.getItem(), ChatColor.GREEN + language.getName(p), "&b" + language.getTranslationProgress() + '%', "", "&7\u21E8 &e" + Slimefun.getLocalization().getMessage(p, "guide.languages.select")), (pl, i, item, action) -> {
            Slimefun.instance().getServer().getPluginManager().callEvent(new PlayerLanguageChangeEvent(pl, Slimefun.getLocalization().getLanguage(pl), language));
            setSelectedOption(pl, guide, language.getId());
            String name = language.getName(pl);
            Slimefun.getLocalization().sendMessage(pl, "guide.languages.updated", msg -> msg.replace("%lang%", name));
            SlimefunGuideSettings.openSettings(pl, guide);
            return false;
        });
        slot++;
    }
    menu.open(p);
}
Also used : SlimefunUtils(io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils) NamespacedKey(org.bukkit.NamespacedKey) ChestMenuUtils(io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils) PersistentDataAPI(io.github.bakedlibs.dough.data.persistent.PersistentDataAPI) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) SlimefunAddon(io.github.thebusybiscuit.slimefun4.api.SlimefunAddon) ChatUtils(io.github.thebusybiscuit.slimefun4.utils.ChatUtils) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) PlayerLanguageChangeEvent(io.github.thebusybiscuit.slimefun4.api.events.PlayerLanguageChangeEvent) List(java.util.List) Language(io.github.thebusybiscuit.slimefun4.core.services.localization.Language) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) Optional(java.util.Optional) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ChatColor(org.bukkit.ChatColor) HeadTexture(io.github.thebusybiscuit.slimefun4.utils.HeadTexture) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) PlayerLanguageChangeEvent(io.github.thebusybiscuit.slimefun4.api.events.PlayerLanguageChangeEvent) Language(io.github.thebusybiscuit.slimefun4.core.services.localization.Language) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)

Example 13 with ChestMenu

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

the class SlimefunGuideSettings method openSettings.

@ParametersAreNonnullByDefault
public static void openSettings(Player p, ItemStack guide) {
    ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "guide.title.settings"));
    menu.setEmptySlotsClickable(false);
    menu.addMenuOpeningHandler(pl -> pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_HARP, 0.7F, 0.7F));
    ChestMenuUtils.drawBackground(menu, BACKGROUND_SLOTS);
    addHeader(p, menu, guide);
    addConfigurableOptions(p, menu, guide);
    menu.open(p);
}
Also used : ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 14 with ChestMenu

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

the class ElevatorPlate method openEditor.

@ParametersAreNonnullByDefault
public void openEditor(Player p, Block b) {
    ChestMenu menu = new ChestMenu("Elevator Settings");
    menu.addItem(4, new CustomItemStack(Material.NAME_TAG, "&7Floor Name &e(Click to edit)", "", ChatColor.WHITE + ChatColors.color(BlockStorage.getLocationInfo(b.getLocation(), DATA_KEY))));
    menu.addMenuClickHandler(4, (pl, slot, item, action) -> {
        pl.closeInventory();
        pl.sendMessage("");
        Slimefun.getLocalization().sendMessage(p, "machines.ELEVATOR.enter-name");
        pl.sendMessage("");
        ChatUtils.awaitInput(pl, message -> {
            BlockStorage.addBlockInfo(b, DATA_KEY, message.replace(ChatColor.COLOR_CHAR, '&'));
            pl.sendMessage("");
            Slimefun.getLocalization().sendMessage(p, "machines.ELEVATOR.named", msg -> msg.replace("%floor%", message));
            pl.sendMessage("");
            openEditor(pl, b);
        });
        return false;
    });
    menu.open(p);
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 15 with ChestMenu

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

the class ElevatorPlate method openFloorSelector.

@ParametersAreNonnullByDefault
private void openFloorSelector(Block b, List<ElevatorFloor> floors, Player p, int page) {
    ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "machines.ELEVATOR.pick-a-floor"));
    menu.setEmptySlotsClickable(false);
    int index = GUI_SIZE * (page - 1);
    for (int i = 0; i < Math.min(GUI_SIZE, floors.size() - index); i++) {
        ElevatorFloor floor = floors.get(index + i);
        // @formatter:off
        if (floor.getAltitude() == b.getY()) {
            menu.addItem(i, new CustomItemStack(Material.COMPASS, ChatColor.GRAY.toString() + floor.getNumber() + ". " + ChatColor.BLACK + floor.getName(), Slimefun.getLocalization().getMessage(p, "machines.ELEVATOR.current-floor") + ' ' + ChatColor.WHITE + floor.getName()), ChestMenuUtils.getEmptyClickHandler());
        } else {
            menu.addItem(i, new CustomItemStack(Material.PAPER, ChatColor.GRAY.toString() + floor.getNumber() + ". " + ChatColor.BLACK + floor.getName(), Slimefun.getLocalization().getMessage(p, "machines.ELEVATOR.click-to-teleport") + ' ' + ChatColor.WHITE + floor.getName()), (player, slot, itemStack, clickAction) -> {
                teleport(player, floor);
                return false;
            });
        }
    // @formatter:on
    }
    int pages = 1 + (floors.size() / GUI_SIZE);
    // 0 index so size is the first slot of the last row.
    for (int i = GUI_SIZE; i < GUI_SIZE + 9; i++) {
        if (i == GUI_SIZE + 2 && pages > 1 && page != 1) {
            menu.addItem(i, ChestMenuUtils.getPreviousButton(p, page, pages), (player, i1, itemStack, clickAction) -> {
                openFloorSelector(b, floors, p, page - 1);
                return false;
            });
        } else if (i == GUI_SIZE + 6 && pages > 1 && page != pages) {
            menu.addItem(i, ChestMenuUtils.getNextButton(p, page, pages), (player, i1, itemStack, clickAction) -> {
                openFloorSelector(b, floors, p, page + 1);
                return false;
            });
        } else {
            menu.addItem(i, ChestMenuUtils.getBackground(), (player, i1, itemStack, clickAction) -> false);
        }
    }
    menu.open(p);
}
Also used : BlockUseHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler) BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) Player(org.bukkit.entity.Player) PaperLib(io.papermc.lib.PaperLib) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) Inventory(org.bukkit.inventory.Inventory) HashSet(java.util.HashSet) ChatColors(io.github.bakedlibs.dough.common.ChatColors) Block(org.bukkit.block.Block) SimpleSlimefunItem(io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem) Location(org.bukkit.Location) WorldUtils(io.github.thebusybiscuit.slimefun4.utils.WorldUtils) RecipeType(io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) Material(org.bukkit.Material) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) BlockPlaceHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler) ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) ChestMenuUtils(io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils) Set(java.util.Set) UUID(java.util.UUID) ChatUtils(io.github.thebusybiscuit.slimefun4.utils.ChatUtils) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ChatColor(org.bukkit.ChatColor) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) CustomItemStack(io.github.bakedlibs.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