Search in sources :

Example 21 with ChestMenu

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

the class SlimefunGuideSettings method addHeader.

@ParametersAreNonnullByDefault
private static void addHeader(Player p, ChestMenu menu, ItemStack guide) {
    LocalizationService locale = Slimefun.getLocalization();
    // @formatter:off
    menu.addItem(0, new CustomItemStack(SlimefunGuide.getItem(SlimefunGuideMode.SURVIVAL_MODE), "&e\u21E6 " + locale.getMessage(p, "guide.back.title"), "", "&7" + locale.getMessage(p, "guide.back.guide")));
    // @formatter:on
    menu.addMenuClickHandler(0, (pl, slot, item, action) -> {
        SlimefunGuide.openGuide(pl, guide);
        return false;
    });
    GitHubService github = Slimefun.getGitHubService();
    List<String> contributorsLore = new ArrayList<>();
    contributorsLore.add("");
    contributorsLore.addAll(locale.getMessages(p, "guide.credits.description", msg -> msg.replace("%contributors%", String.valueOf(github.getContributors().size()))));
    contributorsLore.add("");
    contributorsLore.add("&7\u21E8 &e" + locale.getMessage(p, "guide.credits.open"));
    // @formatter:off
    menu.addItem(2, new CustomItemStack(SlimefunUtils.getCustomHead("e952d2b3f351a6b0487cc59db31bf5f2641133e5ba0006b18576e996a0293e52"), "&c" + locale.getMessage(p, "guide.title.credits"), contributorsLore.toArray(new String[0])));
    // @formatter:on
    menu.addMenuClickHandler(2, (pl, slot, action, item) -> {
        ContributorsMenu.open(pl, 0);
        return false;
    });
    // @formatter:off
    menu.addItem(4, new CustomItemStack(Material.WRITABLE_BOOK, ChatColor.GREEN + locale.getMessage(p, "guide.title.versions"), "&7&o" + locale.getMessage(p, "guide.tooltips.versions-notice"), "", "&fMinecraft: &a" + Bukkit.getBukkitVersion(), "&fSlimefun: &a" + Slimefun.getVersion()), ChestMenuUtils.getEmptyClickHandler());
    // @formatter:on
    // @formatter:off
    menu.addItem(6, new CustomItemStack(Material.COMPARATOR, "&e" + locale.getMessage(p, "guide.title.source"), "", "&7Last Activity: &a" + NumberUtils.getElapsedTime(github.getLastUpdate()) + " ago", "&7Forks: &e" + github.getForks(), "&7Stars: &e" + github.getStars(), "", "&7&oSlimefun 4 is a community project,", "&7&othe source code is available on GitHub", "&7&oand if you want to keep this Plugin alive,", "&7&othen please consider contributing to it", "", "&7\u21E8 &eClick to go to GitHub"));
    // @formatter:on
    menu.addMenuClickHandler(6, (pl, slot, item, action) -> {
        pl.closeInventory();
        ChatUtils.sendURL(pl, "https://github.com/Slimefun/Slimefun4");
        return false;
    });
    // @formatter:off
    menu.addItem(8, new CustomItemStack(Material.KNOWLEDGE_BOOK, "&3" + locale.getMessage(p, "guide.title.wiki"), "", "&7Do you need help with an Item or machine?", "&7You cannot figure out what to do?", "&7Check out our community-maintained Wiki", "&7and become one of our Editors!", "", "&7\u21E8 &eClick to go to the official Slimefun Wiki"));
    // @formatter:on
    menu.addMenuClickHandler(8, (pl, slot, item, action) -> {
        pl.closeInventory();
        ChatUtils.sendURL(pl, "https://github.com/Slimefun/Slimefun4/wiki");
        return false;
    });
    // @formatter:off
    menu.addItem(47, new CustomItemStack(Material.BOOKSHELF, "&3" + locale.getMessage(p, "guide.title.addons"), "", "&7Slimefun is huge. But its addons are what makes", "&7this plugin truly shine. Go check them out, some", "&7of them may be exactly what you were missing out on!", "", "&7Installed on this Server: &b" + Slimefun.getInstalledAddons().size(), "", "&7\u21E8 &eClick to see all available addons for Slimefun4"));
    // @formatter:on
    menu.addMenuClickHandler(47, (pl, slot, item, action) -> {
        pl.closeInventory();
        ChatUtils.sendURL(pl, "https://github.com/Slimefun/Slimefun4/wiki/Addons");
        return false;
    });
    if (Slimefun.getUpdater().getBranch().isOfficial()) {
        // @formatter:off
        menu.addItem(49, new CustomItemStack(Material.REDSTONE_TORCH, "&4" + locale.getMessage(p, "guide.title.bugs"), "", "&7&oBug reports have to be made in English!", "", "&7Open Issues: &a" + github.getOpenIssues(), "&7Pending Pull Requests: &a" + github.getPendingPullRequests(), "", "&7\u21E8 &eClick to go to the Slimefun4 Bug Tracker"));
        // @formatter:on
        menu.addMenuClickHandler(49, (pl, slot, item, action) -> {
            pl.closeInventory();
            ChatUtils.sendURL(pl, "https://github.com/Slimefun/Slimefun4/issues");
            return false;
        });
    } else {
        menu.addItem(49, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    }
    menu.addItem(51, new CustomItemStack(Material.TOTEM_OF_UNDYING, ChatColor.RED + locale.getMessage(p, "guide.work-in-progress")), (pl, slot, item, action) -> {
        // Add something here
        return false;
    });
}
Also used : GitHubService(io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService) NumberUtils(io.github.thebusybiscuit.slimefun4.utils.NumberUtils) SlimefunUtils(io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils) ChestMenuUtils(io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils) GitHubService(io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) Research(io.github.thebusybiscuit.slimefun4.api.researches.Research) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) ChatUtils(io.github.thebusybiscuit.slimefun4.utils.ChatUtils) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) Language(io.github.thebusybiscuit.slimefun4.core.services.localization.Language) LocalizationService(io.github.thebusybiscuit.slimefun4.core.services.LocalizationService) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) SlimefunGuideMode(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode) Optional(java.util.Optional) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ChatColor(org.bukkit.ChatColor) SlimefunGuide(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide) Nonnull(javax.annotation.Nonnull) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) LocalizationService(io.github.thebusybiscuit.slimefun4.core.services.LocalizationService) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ArrayList(java.util.ArrayList) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 22 with ChestMenu

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

the class GPSNetwork method openWaypointControlPanel.

public void openWaypointControlPanel(@Nonnull Player p) {
    PlayerProfile.get(p, profile -> {
        ChestMenu menu = new ChestMenu(ChatColor.BLUE + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.title"));
        for (int slot : border) {
            menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
        }
        menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters"), "", ChatColor.GRAY + "\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup")));
        menu.addMenuClickHandler(2, (pl, slot, item, action) -> {
            openTransmitterControlPanel(pl);
            return false;
        });
        int complexity = getNetworkComplexity(p.getUniqueId());
        menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + (complexity > 0 ? "&2&lONLINE" : "&4&lOFFLINE"), "&8\u21E8 &7Complexity: &f" + complexity));
        menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler());
        menu.addItem(6, new CustomItemStack(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints")));
        menu.addMenuClickHandler(6, ChestMenuUtils.getEmptyClickHandler());
        int index = 0;
        for (Waypoint waypoint : profile.getWaypoints()) {
            if (index >= inventory.length) {
                break;
            }
            int slot = inventory[index];
            Location l = waypoint.getLocation();
            menu.addItem(slot, new CustomItemStack(waypoint.getIcon(), waypoint.getName().replace("player:death ", ""), "&8\u21E8 &7World: &f" + l.getWorld().getName(), "&8\u21E8 &7X: &f" + l.getX(), "&8\u21E8 &7Y: &f" + l.getY(), "&8\u21E8 &7Z: &f" + l.getZ(), "", "&8\u21E8 &cClick to delete"));
            menu.addMenuClickHandler(slot, (pl, s, item, action) -> {
                profile.removeWaypoint(waypoint);
                pl.playSound(pl.getLocation(), Sound.UI_BUTTON_CLICK, 1F, 1F);
                openWaypointControlPanel(pl);
                return false;
            });
            index++;
        }
        menu.open(p);
    });
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) Location(org.bukkit.Location)

Example 23 with ChestMenu

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

the class NestedItemGroup method openGuide.

@ParametersAreNonnullByDefault
private void openGuide(Player p, PlayerProfile profile, SlimefunGuideMode mode, int page) {
    GuideHistory history = profile.getGuideHistory();
    if (mode == SlimefunGuideMode.SURVIVAL_MODE) {
        history.add(this, page);
    }
    ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "guide.title.main"));
    SurvivalSlimefunGuide guide = (SurvivalSlimefunGuide) Slimefun.getRegistry().getSlimefunGuide(mode);
    menu.setEmptySlotsClickable(false);
    menu.addMenuOpeningHandler(pl -> pl.playSound(pl.getLocation(), guide.getSound(), 1, 1));
    guide.createHeader(p, profile, menu);
    menu.addItem(1, new CustomItemStack(ChestMenuUtils.getBackButton(p, "", ChatColor.GRAY + Slimefun.getLocalization().getMessage(p, "guide.back.guide"))));
    menu.addMenuClickHandler(1, (pl, s, is, action) -> {
        SlimefunGuide.openMainMenu(profile, mode, history.getMainMenuPage());
        return false;
    });
    int index = 9;
    int target = (GROUP_SIZE * (page - 1)) - 1;
    while (target < (subGroups.size() - 1) && index < GROUP_SIZE + 9) {
        target++;
        SubItemGroup itemGroup = subGroups.get(target);
        menu.addItem(index, itemGroup.getItem(p));
        menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
            SlimefunGuide.openItemGroup(profile, itemGroup, mode, 1);
            return false;
        });
        index++;
    }
    int pages = target == subGroups.size() - 1 ? page : (subGroups.size() - 1) / GROUP_SIZE + 1;
    menu.addItem(46, ChestMenuUtils.getPreviousButton(p, page, pages));
    menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
        int next = page - 1;
        if (next != page && next > 0) {
            openGuide(p, profile, mode, next);
        }
        return false;
    });
    menu.addItem(52, ChestMenuUtils.getNextButton(p, page, pages));
    menu.addMenuClickHandler(52, (pl, slot, item, action) -> {
        int next = page + 1;
        if (next != page && next <= pages) {
            openGuide(p, profile, mode, next);
        }
        return false;
    });
    menu.open(p);
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SurvivalSlimefunGuide(io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide) GuideHistory(io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 24 with ChestMenu

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

the class ProgrammableAndroid method editInstruction.

protected void editInstruction(Player p, Block b, String[] script, int index) {
    ChestMenu menu = new ChestMenu(ChatColor.DARK_AQUA + Slimefun.getLocalization().getMessage(p, "android.scripts.editor"));
    ChestMenuUtils.drawBackground(menu, 0, 1, 2, 3, 4, 5, 6, 7, 8);
    menu.setEmptySlotsClickable(false);
    menu.addItem(9, new CustomItemStack(HeadTexture.SCRIPT_PAUSE.getAsItemStack(), "&fDo nothing"), (pl, slot, item, action) -> {
        String code = deleteInstruction(script, index);
        setScript(b.getLocation(), code);
        openScript(p, b, code);
        return false;
    });
    int i = 10;
    for (Instruction instruction : getValidScriptInstructions()) {
        menu.addItem(i, new CustomItemStack(instruction.getItem(), Slimefun.getLocalization().getMessage(p, "android.scripts.instructions." + instruction.name())), (pl, slot, item, action) -> {
            String code = addInstruction(script, index, instruction);
            setScript(b.getLocation(), code);
            openScript(p, b, code);
            return false;
        });
        i++;
    }
    menu.open(p);
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)

Example 25 with ChestMenu

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

the class ProgrammableAndroid method openScript.

@ParametersAreNonnullByDefault
public void openScript(Player p, Block b, String sourceCode) {
    ChestMenu menu = new ChestMenu(ChatColor.DARK_AQUA + Slimefun.getLocalization().getMessage(p, "android.scripts.editor"));
    menu.setEmptySlotsClickable(false);
    menu.addItem(0, new CustomItemStack(Instruction.START.getItem(), Slimefun.getLocalization().getMessage(p, "android.scripts.instructions.START"), "", "&7\u21E8 &eLeft Click &7to return to the Android's interface"));
    menu.addMenuClickHandler(0, (pl, slot, item, action) -> {
        BlockMenu inv = BlockStorage.getInventory(b);
        // Fixes #2937
        if (inv != null) {
            inv.open(pl);
        } else {
            pl.closeInventory();
        }
        return false;
    });
    String[] script = CommonPatterns.DASH.split(sourceCode);
    for (int i = 1; i < script.length; i++) {
        int index = i;
        if (i == script.length - 1) {
            boolean hasFreeSlot = script.length < 54;
            if (hasFreeSlot) {
                menu.addItem(i, new CustomItemStack(HeadTexture.SCRIPT_NEW.getAsItemStack(), "&7> Add new Command"));
                menu.addMenuClickHandler(i, (pl, slot, item, action) -> {
                    editInstruction(pl, b, script, index);
                    return false;
                });
            }
            int slot = i + (hasFreeSlot ? 1 : 0);
            menu.addItem(slot, new CustomItemStack(Instruction.REPEAT.getItem(), Slimefun.getLocalization().getMessage(p, "android.scripts.instructions.REPEAT"), "", "&7\u21E8 &eLeft Click &7to return to the Android's interface"));
            menu.addMenuClickHandler(slot, (pl, s, item, action) -> {
                BlockMenu inv = BlockStorage.getInventory(b);
                // Fixes #2937
                if (inv != null) {
                    inv.open(pl);
                } else {
                    pl.closeInventory();
                }
                return false;
            });
        } else {
            Instruction instruction = Instruction.getInstruction(script[i]);
            if (instruction == null) {
                Slimefun.instance().getLogger().log(Level.WARNING, "Failed to parse Android instruction: {0}, maybe your server is out of date?", script[i]);
                return;
            }
            ItemStack stack = instruction.getItem();
            menu.addItem(i, new CustomItemStack(stack, Slimefun.getLocalization().getMessage(p, "android.scripts.instructions." + instruction.name()), "", "&7\u21E8 &eLeft Click &7to edit", "&7\u21E8 &eRight Click &7to delete", "&7\u21E8 &eShift + Right Click &7to duplicate"));
            menu.addMenuClickHandler(i, (pl, slot, item, action) -> {
                if (action.isRightClicked() && action.isShiftClicked()) {
                    if (script.length == 54) {
                        return false;
                    }
                    String code = duplicateInstruction(script, index);
                    setScript(b.getLocation(), code);
                    openScript(pl, b, code);
                } else if (action.isRightClicked()) {
                    String code = deleteInstruction(script, index);
                    setScript(b.getLocation(), code);
                    openScript(pl, b, code);
                } else {
                    editInstruction(pl, b, script, index);
                }
                return false;
            });
        }
    }
    menu.open(p);
}
Also used : BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) 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