Search in sources :

Example 1 with InventoryContents

use of gg.projecteden.nexus.features.menus.api.content.InventoryContents in project Nexus by ProjectEdenGG.

the class SmartInventory method open.

public Inventory open(Player player, int page, Map<String, Object> properties) {
    Optional<SmartInventory> oldInv = this.manager.getInventory(player);
    oldInv.ifPresent(inv -> {
        inv.getListeners().stream().filter(listener -> listener.getType() == InventoryCloseEvent.class).forEach(listener -> ((InventoryListener<InventoryCloseEvent>) listener).accept(new InventoryCloseEvent(player.getOpenInventory())));
        this.manager.setInventory(player, null);
    });
    InventoryContents contents = new InventoryContents.Impl(this, player);
    contents.pagination().page(page);
    properties.forEach(contents::setProperty);
    this.manager.setContents(player, contents);
    try {
        this.provider.setContents(contents);
        this.provider.init();
    } catch (Exception ex) {
        ex.printStackTrace();
        player.closeInventory();
        player.sendMessage(ChatColor.RED + "An unknown error occurred while trying to open the menu");
        return null;
    }
    InventoryOpener opener = this.manager.findOpener(type).orElseThrow(() -> new IllegalStateException("No opener found for the inventory type " + type.name()));
    Inventory handle = opener.open(this, player);
    this.manager.setInventory(player, this);
    this.manager.scheduleUpdateTask(player, this);
    return handle;
}
Also used : InventoryOpener(gg.projecteden.nexus.features.menus.api.opener.InventoryOpener) Setter(lombok.Setter) Getter(lombok.Getter) InventoryType(org.bukkit.event.inventory.InventoryType) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) Event(org.bukkit.event.Event) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Player(org.bukkit.entity.Player) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) ComponentLike(net.kyori.adventure.text.ComponentLike) Inventory(org.bukkit.inventory.Inventory) ArrayList(java.util.ArrayList) List(java.util.List) SlotPos(gg.projecteden.nexus.features.menus.api.content.SlotPos) Component(net.kyori.adventure.text.Component) Map(java.util.Map) InventoryProvider(gg.projecteden.nexus.features.menus.api.content.InventoryProvider) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) ChatColor(net.md_5.bungee.api.ChatColor) InventoryOpener(gg.projecteden.nexus.features.menus.api.opener.InventoryOpener) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Inventory(org.bukkit.inventory.Inventory)

Example 2 with InventoryContents

use of gg.projecteden.nexus.features.menus.api.content.InventoryContents in project Nexus by ProjectEdenGG.

the class ExchangeConfigProvider method addExchangeControl.

private void addExchangeControl(Player player, InventoryContents contents) {
    ItemBuilder item = new ItemBuilder(Material.PAPER).name("&6Action: ").lore("&7⬇ " + camelCase(exchangeType.previousWithLoop().name())).lore("&e⬇ " + camelCase(exchangeType.name())).lore("&7⬇ " + camelCase(exchangeType.nextWithLoop().name()));
    contents.set(2, 4, ClickableItem.of(item.build(), e -> {
        exchangeType = exchangeType.nextWithLoop();
        open(player);
    }));
}
Also used : Shop(gg.projecteden.nexus.models.shop.Shop) ShopProvider(gg.projecteden.nexus.features.shops.providers.common.ShopProvider) Player(org.bukkit.entity.Player) ARROWS(gg.projecteden.nexus.features.menus.SignMenuFactory.ARROWS) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) BigDecimal(java.math.BigDecimal) ItemClickData(gg.projecteden.nexus.features.menus.api.ItemClickData) Material(org.bukkit.Material) Product(gg.projecteden.nexus.models.shop.Shop.Product) RoundingMode(java.math.RoundingMode) Nexus(gg.projecteden.nexus.Nexus) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) Shops(gg.projecteden.nexus.features.shops.Shops) StringUtils.pretty(gg.projecteden.nexus.utils.StringUtils.pretty) StringUtils.camelCase(gg.projecteden.nexus.utils.StringUtils.camelCase) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Utils(gg.projecteden.nexus.utils.Utils) ItemStack(org.bukkit.inventory.ItemStack) Consumer(java.util.function.Consumer) ExchangeType(gg.projecteden.nexus.models.shop.Shop.ExchangeType) Title(gg.projecteden.nexus.features.menus.api.annotations.Title) ItemSetting(gg.projecteden.nexus.utils.ItemBuilder.ItemSetting) Nullables.isNullOrAir(gg.projecteden.nexus.utils.Nullables.isNullOrAir) ShopUtils.prettyMoney(gg.projecteden.nexus.features.shops.ShopUtils.prettyMoney) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder)

Example 3 with InventoryContents

use of gg.projecteden.nexus.features.menus.api.content.InventoryContents in project Nexus by ProjectEdenGG.

the class BrowseProductsProvider method addItems.

public void addItems(Player player, InventoryContents contents) {
    List<Shop> shops = shop != null ? Collections.singletonList(shop) : service.getShops();
    if (shops == null || shops.size() == 0)
        return;
    List<ClickableItem> items = new ArrayList<>();
    Pagination page = contents.pagination();
    List<Product> products = new ArrayList<Product>() {

        {
            shops.forEach(shop -> addAll(shop.getProducts(shopGroup)));
        }
    }.stream().filter(product -> !isFiltered(product)).sorted(Product::compareTo).toList();
    ClickableItem empty = ClickableItem.empty(new ItemStack(Material.BARRIER));
    int perPage = 36;
    if (page.getPage() > products.size() / perPage)
        page.page(products.size() / perPage);
    int start = perPage * page.getPage();
    int end = start + perPage;
    for (int i = 0; i < start; i++) items.add(empty);
    products.subList(start, Math.min(end, products.size())).forEach(product -> {
        try {
            items.add(ClickableItem.of(product.getItemWithCustomerLore(), e -> {
                if (!product.isPurchasable())
                    return;
                try {
                    if (handleRightClick(product, e))
                        return;
                    if (e.isLeftClick())
                        product.process(player);
                    else if (e.isShiftLeftClick())
                        processAll(player, page, product);
                    open(player, page);
                } catch (Exception ex) {
                    PlayerUtils.send(player, PREFIX + "&c" + ex.getMessage());
                }
            }));
        } catch (Exception ex) {
            Nexus.severe("Error formatting product in BrowseItemsProvider: " + product.toString());
            ex.printStackTrace();
        }
    });
    if (end < products.size())
        items.add(empty);
    paginator().items(items).build();
}
Also used : Shop(gg.projecteden.nexus.models.shop.Shop) ShopProvider(gg.projecteden.nexus.features.shops.providers.common.ShopProvider) Getter(lombok.Getter) Player(org.bukkit.entity.Player) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) ArrayList(java.util.ArrayList) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) FilterExchangeType(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterExchangeType) FilterRequiredType(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterRequiredType) PREFIX(gg.projecteden.nexus.features.shops.Shops.PREFIX) Material(org.bukkit.Material) ConfirmationMenu(gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu) Product(gg.projecteden.nexus.models.shop.Shop.Product) Nexus(gg.projecteden.nexus.Nexus) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) ItemUtils.getRawShulkerContents(gg.projecteden.nexus.utils.ItemUtils.getRawShulkerContents) StringUtils.camelCase(gg.projecteden.nexus.utils.StringUtils.camelCase) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Filter(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.Filter) FilterSearchType(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterSearchType) FilterType(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterType) ItemStack(org.bukkit.inventory.ItemStack) FilterEmptyStock(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterEmptyStock) List(java.util.List) Rows(gg.projecteden.nexus.features.menus.api.annotations.Rows) FilterMarketItems(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterMarketItems) Title(gg.projecteden.nexus.features.menus.api.annotations.Title) Pagination(gg.projecteden.nexus.features.menus.api.content.Pagination) Collections(java.util.Collections) Shop(gg.projecteden.nexus.models.shop.Shop) Pagination(gg.projecteden.nexus.features.menus.api.content.Pagination) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) ArrayList(java.util.ArrayList) Product(gg.projecteden.nexus.models.shop.Shop.Product) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with InventoryContents

use of gg.projecteden.nexus.features.menus.api.content.InventoryContents in project Nexus by ProjectEdenGG.

the class BrowseProductsProvider method addExchangeFilter.

public void addExchangeFilter(Player player, InventoryContents contents) {
    Filter exchangeFilter = getFilter(FilterExchangeType.class);
    FilterExchangeType filter = exchangeFilter != null ? (FilterExchangeType) exchangeFilter.getType() : FilterExchangeType.BOTH;
    FilterExchangeType next = filter.nextWithLoop();
    ItemBuilder item = new ItemBuilder(Material.HOPPER).name("&6Filter by:").lore("&7⬇ " + camelCase(filter.previousWithLoop().name())).lore("&e⬇ " + camelCase(filter.name())).lore("&7⬇ " + camelCase(next.name()));
    contents.set(5, 4, ClickableItem.of(item.build(), e -> {
        formatFilter(exchangeFilter, next);
        open(player, contents.pagination().getPage());
    }));
}
Also used : Shop(gg.projecteden.nexus.models.shop.Shop) ShopProvider(gg.projecteden.nexus.features.shops.providers.common.ShopProvider) Getter(lombok.Getter) Player(org.bukkit.entity.Player) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) ArrayList(java.util.ArrayList) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) FilterExchangeType(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterExchangeType) FilterRequiredType(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterRequiredType) PREFIX(gg.projecteden.nexus.features.shops.Shops.PREFIX) Material(org.bukkit.Material) ConfirmationMenu(gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu) Product(gg.projecteden.nexus.models.shop.Shop.Product) Nexus(gg.projecteden.nexus.Nexus) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) ItemUtils.getRawShulkerContents(gg.projecteden.nexus.utils.ItemUtils.getRawShulkerContents) StringUtils.camelCase(gg.projecteden.nexus.utils.StringUtils.camelCase) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Filter(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.Filter) FilterSearchType(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterSearchType) FilterType(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterType) ItemStack(org.bukkit.inventory.ItemStack) FilterEmptyStock(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterEmptyStock) List(java.util.List) Rows(gg.projecteden.nexus.features.menus.api.annotations.Rows) FilterMarketItems(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterMarketItems) Title(gg.projecteden.nexus.features.menus.api.annotations.Title) Pagination(gg.projecteden.nexus.features.menus.api.content.Pagination) Collections(java.util.Collections) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) Filter(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.Filter) FilterExchangeType(gg.projecteden.nexus.features.shops.providers.common.ShopMenuFunctions.FilterExchangeType)

Example 5 with InventoryContents

use of gg.projecteden.nexus.features.menus.api.content.InventoryContents in project Nexus by ProjectEdenGG.

the class MobHeadUserMenu method formatKillsFilter.

private void formatKillsFilter(Player player, InventoryContents contents) {
    final ItemBuilder item = getFilterItem(Material.NETHERITE_SWORD, killsFilter);
    contents.set(5, 3, ClickableItem.of(item.build(), e -> {
        killsFilter = killsFilter.nextWithLoop();
        open(player, contents.pagination().getPage());
    }));
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) MobHeadUser(gg.projecteden.nexus.models.mobheads.MobHeadUser) StringUtils(gg.projecteden.nexus.utils.StringUtils) Getter(lombok.Getter) MobHeadUserService(gg.projecteden.nexus.models.mobheads.MobHeadUserService) MobHeadVariant(gg.projecteden.nexus.features.mobheads.common.MobHeadVariant) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Player(org.bukkit.entity.Player) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) IteratableEnum(gg.projecteden.utils.EnumUtils.IteratableEnum) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) BiPredicate(java.util.function.BiPredicate) List(java.util.List) Title(gg.projecteden.nexus.features.menus.api.annotations.Title) InventoryProvider(gg.projecteden.nexus.features.menus.api.content.InventoryProvider) AllArgsConstructor(lombok.AllArgsConstructor) MobHead(gg.projecteden.nexus.features.mobheads.common.MobHead) Material(org.bukkit.Material) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder)

Aggregations

InventoryContents (gg.projecteden.nexus.features.menus.api.content.InventoryContents)16 ClickableItem (gg.projecteden.nexus.features.menus.api.ClickableItem)15 Title (gg.projecteden.nexus.features.menus.api.annotations.Title)15 ItemBuilder (gg.projecteden.nexus.utils.ItemBuilder)15 Material (org.bukkit.Material)15 ArrayList (java.util.ArrayList)13 List (java.util.List)13 Player (org.bukkit.entity.Player)13 StringUtils.camelCase (gg.projecteden.nexus.utils.StringUtils.camelCase)11 ItemStack (org.bukkit.inventory.ItemStack)11 ShopProvider (gg.projecteden.nexus.features.shops.providers.common.ShopProvider)9 Shop (gg.projecteden.nexus.models.shop.Shop)9 PlayerUtils (gg.projecteden.nexus.utils.PlayerUtils)9 Nexus (gg.projecteden.nexus.Nexus)8 Product (gg.projecteden.nexus.models.shop.Shop.Product)8 Getter (lombok.Getter)8 InventoryProvider (gg.projecteden.nexus.features.menus.api.content.InventoryProvider)7 Collections (java.util.Collections)6 ConfirmationMenu (gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu)5 Rows (gg.projecteden.nexus.features.menus.api.annotations.Rows)5