Search in sources :

Example 1 with ClickableItem

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

the class PerkMenu method init.

@Override
public void init() {
    ClickableItem yourPerks = ClickableItem.of(new ItemBuilder(Material.PLAYER_HEAD).skullOwner(player).name("&6&lYour Perks").build(), e -> new CategoryMenu<>(PlayerPerksMenu.class).open(player));
    ClickableItem buyPerks = ClickableItem.of(new ItemBuilder(Material.EMERALD).name("&a&lBuy Perks").build(), e -> new CategoryMenu<>(BuyPerksMenu.class).open(player));
    contents.set(SlotPos.of(1, 3), yourPerks);
    contents.set(SlotPos.of(1, 5), buyPerks);
    PerkOwner perkOwner = new PerkOwnerService().get(player);
    contents.set(0, 8, ClickableItem.empty(new ItemBuilder(Material.EMERALD).name("&2&lBalance").lore("&f" + FORMATTER.format(perkOwner.getTokens()) + plural(" token", perkOwner.getTokens())).build()));
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) CategoryMenu(gg.projecteden.nexus.features.minigames.menus.perks.CategoryMenu) PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) PerkOwnerService(gg.projecteden.nexus.models.perkowner.PerkOwnerService)

Example 2 with ClickableItem

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

the class SpawnpointLocationsMenu method init.

@Override
public void init() {
    addBackItem(e -> new TeamEditorMenu(arena, team).open(player));
    Pagination page = contents.pagination();
    contents.set(0, 4, ClickableItem.of(new ItemBuilder(Material.EMERALD_BLOCK).name("&eAdd Spawnpoint").lore("&3Click to add a spawnpoint", "&3at your current location."), e -> {
        team.getSpawnpoints().add(player.getLocation());
        arena.write();
        new SpawnpointLocationsMenu(arena, team).open(player, page.getPage());
    }));
    contents.set(0, 8, ClickableItem.of(new ItemBuilder(Material.TNT).name("&cDelete Item").lore("&7Click me to enter deletion mode.", "&7Then, click a spawnpoint with me to", "&7delete the spawnpoint."), e -> Tasks.wait(2, () -> {
        if (player.getItemOnCursor().getType().equals(Material.TNT)) {
            player.setItemOnCursor(new ItemStack(Material.AIR));
        } else if (isNullOrAir(player.getItemOnCursor())) {
            player.setItemOnCursor(new ItemBuilder(Material.TNT).name("&cDelete Item").lore("&7Click me to enter deletion mode.", "&7Then, click a spawnpoint with me to", "&7delete the spawnpoint.").build());
        }
    })));
    if (team.getSpawnpoints() == null)
        return;
    ClickableItem[] clickableItems = new ClickableItem[team.getSpawnpoints().size()];
    List<Location> spawnpoints = new ArrayList<>(team.getSpawnpoints());
    for (int i = 0; i < spawnpoints.size(); i++) {
        Location spawnpoint = spawnpoints.get(i);
        clickableItems[i] = ClickableItem.of(new ItemBuilder(Material.COMPASS).name("&eSpawnpoint #" + (i + 1)).lore(getLocationLore(spawnpoints.get(i))).lore("", "&7Click to Teleport"), e -> {
            if (player.getItemOnCursor().getType().equals(Material.TNT)) {
                Tasks.wait(2, () -> {
                    team.getSpawnpoints().remove(spawnpoint);
                    arena.write();
                    player.setItemOnCursor(new ItemStack(Material.AIR));
                    new SpawnpointLocationsMenu(arena, team).open(player, page.getPage());
                });
            } else {
                player.teleport(spawnpoint);
            }
        });
        page.setItems(clickableItems);
        page.setItemsPerPage(36);
        page.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, 1, 0));
        if (!page.isLast())
            contents.set(0, 8, ClickableItem.of(Material.ARROW, "&fNext Page", e -> new SpawnpointLocationsMenu(arena, team).open(player, page.next().getPage())));
        if (!page.isFirst())
            contents.set(0, 7, ClickableItem.of(Material.BARRIER, "&fPrevious Page", e -> new SpawnpointLocationsMenu(arena, team).open(player, page.previous().getPage())));
    }
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Tasks(gg.projecteden.nexus.utils.Tasks) MenuUtils.getLocationLore(gg.projecteden.nexus.features.menus.MenuUtils.getLocationLore) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) SlotIterator(gg.projecteden.nexus.features.menus.api.content.SlotIterator) Arena(gg.projecteden.nexus.features.minigames.models.Arena) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) List(java.util.List) Location(org.bukkit.Location) Title(gg.projecteden.nexus.features.menus.api.annotations.Title) InventoryProvider(gg.projecteden.nexus.features.menus.api.content.InventoryProvider) Nullables.isNullOrAir(gg.projecteden.nexus.utils.Nullables.isNullOrAir) Pagination(gg.projecteden.nexus.features.menus.api.content.Pagination) Team(gg.projecteden.nexus.features.minigames.models.Team) Material(org.bukkit.Material) Pagination(gg.projecteden.nexus.features.menus.api.content.Pagination) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 3 with ClickableItem

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

the class BuyPerksMenu method init.

@Override
public void init() {
    addBackItem($ -> new CategoryMenu<>(getClass()).open(player));
    PerkOwner perkOwner = service.get(player);
    contents.set(0, 8, ClickableItem.empty(new ItemBuilder(Material.EMERALD).name("&2&lBalance").lore("&f" + FORMATTER.format(perkOwner.getTokens()) + plural(" token", perkOwner.getTokens())).build()));
    // get perks and sort them
    List<PerkSortWrapper> perkSortWrappers = new ArrayList<>();
    PerkType.getByCategory(category).forEach(perkType -> perkSortWrappers.add(PerkSortWrapper.of(perkOwner, perkType)));
    perkSortWrappers.sort(Comparator.comparing(PerkSortWrapper::isOwned).thenComparing(PerkSortWrapper::getPrice).thenComparing(PerkSortWrapper::getName));
    List<PerkType> perks = perkSortWrappers.stream().map(PerkSortWrapper::getPerkType).collect(Collectors.toList());
    // create the items
    paginator().items(new ArrayList<ClickableItem>() {

        {
            perks.forEach(perkType -> {
                Perk perk = perkType.getPerk();
                boolean userOwned = perkOwner.getPurchasedPerks().containsKey(perkType);
                List<String> lore = getLore(player, perk);
                lore.add(1, userOwned ? "&cPurchased" : ("&aPurchase for &e" + perk.getPrice() + "&a " + plural("token", perk.getPrice())));
                if (lore.size() > 2)
                    lore.add(2, "");
                ItemBuilder item = getItem(perk, lore);
                add(ClickableItem.of(item, e -> buyItem(player, perkType, contents)));
            });
        }
    }).build();
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) StringUtils.plural(gg.projecteden.nexus.utils.StringUtils.plural) SoundCategory(org.bukkit.SoundCategory) DecimalFormat(java.text.DecimalFormat) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) Perk(gg.projecteden.nexus.features.minigames.models.perks.Perk) Collectors(java.util.stream.Collectors) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) PerkCategory(gg.projecteden.nexus.features.minigames.models.perks.PerkCategory) SoundBuilder(gg.projecteden.nexus.utils.SoundBuilder) ArrayList(java.util.ArrayList) List(java.util.List) MenuUtils(gg.projecteden.nexus.features.menus.MenuUtils) Title(gg.projecteden.nexus.features.menus.api.annotations.Title) PerkType(gg.projecteden.nexus.features.minigames.models.perks.PerkType) Comparator(java.util.Comparator) PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) Material(org.bukkit.Material) PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) ArrayList(java.util.ArrayList) Perk(gg.projecteden.nexus.features.minigames.models.perks.Perk) PerkType(gg.projecteden.nexus.features.minigames.models.perks.PerkType) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder)

Example 4 with ClickableItem

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

the class AdventMenu method init.

@Override
public void init() {
    int row = 1;
    int column = Pugmas21.EPOCH.getDayOfWeek().getValue() + 1;
    final SlotIterator slotIterator = innerSlotIterator(contents, SlotPos.of(row, column));
    for (int day = 1; day <= 25; day++) {
        final int _day = day;
        final LocalDate date = Pugmas21.EPOCH.plusDays(_day - 1);
        final Icon icon = getIcon(date);
        final ItemBuilder item = new ItemBuilder(icon.getItem(_day));
        ClickableItem clickableItem = ClickableItem.empty(item.build());
        if (user.advent().hasFound(_day)) {
            item.lore("", "&aShow Waypoint");
            clickableItem = ClickableItem.of(item.build(), e -> {
                player.closeInventory();
                Advent.glow(user, _day);
            });
        }
        slotIterator.next().set(clickableItem);
    }
    updateTask(player, contents);
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) AdventPresent(gg.projecteden.nexus.models.pugmas21.Advent21Config.AdventPresent) NonNull(lombok.NonNull) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Tasks(gg.projecteden.nexus.utils.Tasks) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Player(org.bukkit.entity.Player) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) SlotIterator(gg.projecteden.nexus.features.menus.api.content.SlotIterator) IteratableEnum(gg.projecteden.utils.EnumUtils.IteratableEnum) Advent21Config(gg.projecteden.nexus.models.pugmas21.Advent21Config) Pugmas21User(gg.projecteden.nexus.models.pugmas21.Pugmas21User) SlotPos(gg.projecteden.nexus.features.menus.api.content.SlotPos) LocalDate(java.time.LocalDate) InventoryProvider(gg.projecteden.nexus.features.menus.api.content.InventoryProvider) StringUtils.colorize(gg.projecteden.nexus.utils.StringUtils.colorize) Pugmas21(gg.projecteden.nexus.features.events.y2021.pugmas21.Pugmas21) AllArgsConstructor(lombok.AllArgsConstructor) NotNull(org.jetbrains.annotations.NotNull) Material(org.bukkit.Material) MenuUtils.innerSlotIterator(gg.projecteden.nexus.features.menus.MenuUtils.innerSlotIterator) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) SlotIterator(gg.projecteden.nexus.features.menus.api.content.SlotIterator) MenuUtils.innerSlotIterator(gg.projecteden.nexus.features.menus.MenuUtils.innerSlotIterator) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) LocalDate(java.time.LocalDate)

Example 5 with ClickableItem

use of gg.projecteden.nexus.features.menus.api.ClickableItem 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)

Aggregations

ClickableItem (gg.projecteden.nexus.features.menus.api.ClickableItem)26 ItemBuilder (gg.projecteden.nexus.utils.ItemBuilder)25 ArrayList (java.util.ArrayList)21 List (java.util.List)20 Title (gg.projecteden.nexus.features.menus.api.annotations.Title)18 Material (org.bukkit.Material)17 Player (org.bukkit.entity.Player)12 ItemStack (org.bukkit.inventory.ItemStack)12 InventoryProvider (gg.projecteden.nexus.features.menus.api.content.InventoryProvider)11 InventoryContents (gg.projecteden.nexus.features.menus.api.content.InventoryContents)7 PlayerUtils (gg.projecteden.nexus.utils.PlayerUtils)7 Tasks (gg.projecteden.nexus.utils.Tasks)7 AllArgsConstructor (lombok.AllArgsConstructor)7 Getter (lombok.Getter)7 RequiredArgsConstructor (lombok.RequiredArgsConstructor)7 MenuUtils (gg.projecteden.nexus.features.menus.MenuUtils)6 EventStoreItem (gg.projecteden.nexus.features.events.store.EventStoreItem)4 Pagination (gg.projecteden.nexus.features.menus.api.content.Pagination)4 ShopProvider (gg.projecteden.nexus.features.shops.providers.common.ShopProvider)4 Shop (gg.projecteden.nexus.models.shop.Shop)4