Search in sources :

Example 1 with ARROWS

use of gg.projecteden.nexus.features.menus.SignMenuFactory.ARROWS in project Nexus by ProjectEdenGG.

the class TrustProvider method init.

@Override
public void init(Player player, InventoryContents contents) {
    if (back == null)
        addCloseItem(contents);
    else
        addBackItem(contents, e -> back.run());
    List<ClickableItem> items = new ArrayList<>();
    trust.getAll().stream().map(PlayerUtils::getPlayer).sorted(Comparator.comparing(Nickname::of)).collect(Collectors.toList()).forEach(_player -> {
        if (filterType.get() != null)
            if (!trust.trusts(filterType.get(), _player))
                return;
        ItemBuilder builder = new ItemBuilder(Material.PLAYER_HEAD).skullOwner(_player).name("&e" + Nickname.of(_player));
        for (Trust.Type type : Trust.Type.values()) {
            // TODO Decorations
            if (type.equals(Type.DECORATIONS) && !Rank.of(player).isStaff())
                continue;
            if (trust.trusts(type, _player))
                builder.lore("&a" + type.camelCase());
            else
                builder.lore("&c" + type.camelCase());
        }
        builder.lore("").lore("&fClick to edit");
        items.add(ClickableItem.from(builder.build(), e -> TrustPlayerProvider.open(player, _player)));
    });
    paginator(player, contents, items);
    ItemBuilder add = new ItemBuilder(Material.LIME_CONCRETE_POWDER).name("&aAdd Trust");
    contents.set(0, 8, ClickableItem.from(add.build(), e -> Nexus.getSignMenuFactory().lines("", ARROWS, "Enter a", "player's name").prefix(Features.get(TrustFeature.class).getPrefix()).response(lines -> {
        if (lines[0].length() > 0) {
            OfflinePlayer trusted = PlayerUtils.getPlayer(lines[0]);
            TrustPlayerProvider.open(player, trusted);
        } else
            openMenu(player);
    }).open(player)));
    Trust.Type previous = filterType.get() == null ? Type.values()[0].previousWithLoop() : filterType.get().previous();
    Trust.Type current = filterType.get();
    Trust.Type next = filterType.get() == null ? Type.values()[0] : filterType.get().next();
    if (current == previous)
        previous = null;
    if (current == next)
        next = null;
    ItemBuilder item = new ItemBuilder(Material.HOPPER).name("&6Filter by:").lore("&7⬇ " + (previous == null ? "All" : previous.camelCase())).lore("&e⬇ " + (current == null ? "All" : current.camelCase())).lore("&7⬇ " + (next == null ? "All" : next.camelCase()));
    Trust.Type finalNext = next;
    contents.set(contents.inventory().getRows() - 1, 4, ClickableItem.from(item.build(), e -> {
        filterType.set(finalNext);
        refresh();
    }));
}
Also used : Nexus(gg.projecteden.nexus.Nexus) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) Trust(gg.projecteden.nexus.models.trust.Trust) Rank(gg.projecteden.nexus.models.nerd.Rank) SmartInventory(fr.minuskube.inv.SmartInventory) Player(org.bukkit.entity.Player) ARROWS(gg.projecteden.nexus.features.menus.SignMenuFactory.ARROWS) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) OfflinePlayer(org.bukkit.OfflinePlayer) ArrayList(java.util.ArrayList) Features(gg.projecteden.nexus.framework.features.Features) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) List(java.util.List) Type(gg.projecteden.nexus.models.trust.Trust.Type) InventoryProvider(fr.minuskube.inv.content.InventoryProvider) InventoryContents(fr.minuskube.inv.content.InventoryContents) MenuUtils(gg.projecteden.nexus.features.menus.MenuUtils) TrustFeature(gg.projecteden.nexus.features.trust.TrustFeature) TrustService(gg.projecteden.nexus.models.trust.TrustService) Nickname(gg.projecteden.nexus.models.nickname.Nickname) Comparator(java.util.Comparator) Material(org.bukkit.Material) ClickableItem(fr.minuskube.inv.ClickableItem) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) ClickableItem(fr.minuskube.inv.ClickableItem) ArrayList(java.util.ArrayList) OfflinePlayer(org.bukkit.OfflinePlayer) Type(gg.projecteden.nexus.models.trust.Trust.Type) Trust(gg.projecteden.nexus.models.trust.Trust)

Example 2 with ARROWS

use of gg.projecteden.nexus.features.menus.SignMenuFactory.ARROWS in project Nexus by ProjectEdenGG.

the class EditProductProvider method init.

@Override
public void init(Player player, InventoryContents contents) {
    super.init(player, contents);
    contents.set(0, 4, ClickableItem.from(product.getItemWithOwnLore().build(), e -> new ExchangeConfigProvider(this, product).open(player)));
    if (product.getExchangeType() == ExchangeType.BUY) {
        ItemBuilder builder = new ItemBuilder(Material.GOLD_INGOT).name("&6Edit Stock").lore("&7Enter the dollar amount you are").lore("&7willing to spend on this item, or").lore("&7enter -1 to allow unlimited purchases").loreize(false);
        contents.set(1, 4, ClickableItem.from(builder.build(), e -> Nexus.getSignMenuFactory().lines("", ARROWS, "Enter an amount", "or -1 for no limit").prefix(Shops.PREFIX).onError(() -> open(player)).response(lines -> {
            if (lines[0].length() > 0) {
                String input = lines[0].replaceAll("[^\\d.-]+", "");
                if (!Utils.isDouble(input))
                    throw new InvalidInputException("Could not parse &e" + lines[0] + " &cas a dollar amount");
                double stock = new BigDecimal(input).setScale(2, RoundingMode.HALF_UP).doubleValue();
                if (!(stock == -1 || stock >= 0))
                    throw new InvalidInputException("Stock must be -1 (unlimited), or $0 or greater");
                product.setStock(stock);
                service.save(product.getShop());
            }
            open(player);
        }).open(player)));
    } else {
        contents.set(1, 3, ClickableItem.from(new ItemBuilder(Material.LIME_CONCRETE_POWDER).name("&6Add Stock").lore("&f", "&7Right click to add in bulk").build(), e -> {
            if (isRightClick(e)) {
                player.closeInventory();
                ShopCommand.getInteractStockMap().put(player.getUniqueId(), product);
                PlayerUtils.send(player, new JsonBuilder(Shops.PREFIX + "Right click any container (ie chest, shulker box, etc) to stock &e" + pretty(product.getItem()) + "&3. &eClick here to end").command("/shop cancelInteractStock"));
            } else {
                new AddStockProvider(this, product).open(player);
            }
        }));
        contents.set(1, 5, ClickableItem.from(nameItem(Material.RED_CONCRETE_POWDER, "&6Remove Stock"), e -> new RemoveStockProvider(this, product).open(player)));
    }
    ItemBuilder purchasable = new ItemBuilder(Material.WHITE_STAINED_GLASS);
    if (product.isPurchasable())
        purchasable.name("&aPurchasable").lore("&7Click to &cdisable &7purchases").lore("&7Item will still show in your shop,").lore("&7but players cannot purchase it.").lore("&7Can be used for shop organization").loreize(false);
    else
        purchasable.name("&cNot purchasable").lore("&7Click to &aenable &7purchases");
    ItemBuilder enabled = new ItemBuilder(Material.LEVER);
    if (product.isEnabled())
        enabled.name("&aEnabled").lore("&7Click to &cdisable&7, hiding").lore("&7the item from public view");
    else
        enabled.name("&cDisabled").lore("&7Click to &aenable&7, allowing others").lore("&7to view and purchase the item");
    contents.set(3, 2, ClickableItem.from(purchasable.build(), e -> {
        product.setPurchasable(!product.isPurchasable());
        service.save(product.getShop());
        open(player);
    }));
    contents.set(3, 4, ClickableItem.from(enabled.build(), e -> {
        product.setEnabled(!product.isEnabled());
        service.save(product.getShop());
        open(player);
    }));
    contents.set(3, 6, ClickableItem.from(new ItemBuilder(Material.LAVA_BUCKET).name("&cDelete").build(), e -> ConfirmationMenu.builder().onConfirm(e2 -> {
        Shop shop = service.get(player);
        shop.removeProduct(product);
        service.save(shop);
        previousMenu.open(player);
    }).onCancel(e2 -> open(player)).open(player)));
}
Also used : Shop(gg.projecteden.nexus.models.shop.Shop) ShopProvider(gg.projecteden.nexus.features.shops.providers.common.ShopProvider) Nullables(gg.projecteden.nexus.utils.Nullables) Getter(lombok.Getter) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) ItemUtils.isSimilar(gg.projecteden.nexus.utils.ItemUtils.isSimilar) Player(org.bukkit.entity.Player) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) ARROWS(gg.projecteden.nexus.features.menus.SignMenuFactory.ARROWS) ShopCommand(gg.projecteden.nexus.features.shops.ShopCommand) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) BigDecimal(java.math.BigDecimal) InventoryContents(fr.minuskube.inv.content.InventoryContents) TemporaryListener(gg.projecteden.nexus.features.listeners.TemporaryListener) Material(org.bukkit.Material) ClickableItem(fr.minuskube.inv.ClickableItem) Product(gg.projecteden.nexus.models.shop.Shop.Product) Bukkit(org.bukkit.Bukkit) 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) ShopService(gg.projecteden.nexus.models.shop.ShopService) Tasks(gg.projecteden.nexus.utils.Tasks) Utils(gg.projecteden.nexus.utils.Utils) ItemStack(org.bukkit.inventory.ItemStack) ExchangeType(gg.projecteden.nexus.models.shop.Shop.ExchangeType) List(java.util.List) Nullables.isNullOrAir(gg.projecteden.nexus.utils.Nullables.isNullOrAir) StringUtils.colorize(gg.projecteden.nexus.utils.StringUtils.colorize) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) Shop(gg.projecteden.nexus.models.shop.Shop) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) BigDecimal(java.math.BigDecimal)

Example 3 with ARROWS

use of gg.projecteden.nexus.features.menus.SignMenuFactory.ARROWS in project Nexus by ProjectEdenGG.

the class ExchangeConfigProvider method addItemSelector.

public void addItemSelector(Player player, InventoryContents contents, int row, AtomicReference<ItemStack> itemStack, boolean allowEditItem) {
    ItemStack placeholder = new ItemBuilder(Material.BLACK_STAINED_GLASS).name("&ePlace your item here").lore("&7or click to search for an item").build();
    if (!allowEditItem)
        contents.set(row, 4, ClickableItem.empty(itemStack.get()));
    else {
        Consumer<ItemClickData> action = e -> {
            ((InventoryClickEvent) e.getEvent()).setCancelled(true);
            if (!isNullOrAir(player.getItemOnCursor())) {
                try {
                    ItemStack item = player.getItemOnCursor();
                    if (new ItemBuilder(item).isNot(ItemSetting.TRADEABLE))
                        throw new InvalidInputException("You can not trade that item in shops");
                    itemStack.set(item);
                    PlayerUtils.giveItem(player, itemStack.get().clone());
                    player.setItemOnCursor(null);
                    open(player);
                } catch (Exception ex) {
                    PlayerUtils.send(player, Shops.PREFIX + "&c" + ex.getMessage());
                    open(player);
                }
            } else if (contents.get(row, 4).isPresent() && contents.get(row, 4).get().getItem().equals(placeholder)) {
                Nexus.getSignMenuFactory().lines("", ARROWS, "Enter a", "search term").prefix(Shops.PREFIX).onError(() -> open(player)).response(lines -> {
                    if (lines[0].length() > 0) {
                        Function<Material, Boolean> filter = material -> material.name().toLowerCase().contains(lines[0].toLowerCase());
                        new ItemSearchProvider(this, filter, onChoose -> {
                            itemStack.set(new ItemStack(onChoose.getItem().getType()));
                            open(player);
                        }).open(player);
                    } else
                        open(player);
                }).open(player);
            } else {
                itemStack.set(null);
                open(player);
            }
        };
        if (itemStack.get() != null)
            contents.set(row, 4, ClickableItem.from(itemStack.get(), action));
        else
            contents.set(row, 4, ClickableItem.from(placeholder, action));
    }
    if (contents.get(row, 4).isPresent() && contents.get(row, 4).get().getItem() != null && contents.get(row, 4).get().getItem().equals(placeholder)) {
        contents.set(row, 2, ClickableItem.empty(less8));
        contents.set(row, 3, ClickableItem.empty(less1));
        contents.set(row, 5, ClickableItem.empty(more1));
        contents.set(row, 6, ClickableItem.empty(more8));
    } else {
        contents.set(row, 2, ClickableItem.from(less8, e2 -> contents.get(row, 4).ifPresent(i -> {
            ItemStack item = i.getItem();
            item.setAmount(Math.max(1, Math.min(item.getType().getMaxStackSize(), item.getAmount() == 64 ? 56 : item.getAmount() - 8)));
            open(player);
        })));
        contents.set(row, 3, ClickableItem.from(less1, e2 -> contents.get(row, 4).ifPresent(i -> {
            ItemStack item = i.getItem();
            item.setAmount(Math.max(1, Math.min(item.getType().getMaxStackSize(), item.getAmount() - 1)));
            open(player);
        })));
        contents.set(row, 5, ClickableItem.from(more1, e2 -> contents.get(row, 4).ifPresent(i -> {
            ItemStack item = i.getItem();
            item.setAmount(Math.min(64, Math.min(item.getType().getMaxStackSize(), item.getAmount() + 1)));
            open(player);
        })));
        contents.set(row, 6, ClickableItem.from(more8, e2 -> contents.get(row, 4).ifPresent(i -> {
            ItemStack item = i.getItem();
            item.setAmount(Math.min(64, Math.min(item.getType().getMaxStackSize(), item.getAmount() == 1 ? 8 : item.getAmount() + 8)));
            open(player);
        })));
    }
}
Also used : Shop(gg.projecteden.nexus.models.shop.Shop) ShopProvider(gg.projecteden.nexus.features.shops.providers.common.ShopProvider) Nullables(gg.projecteden.nexus.utils.Nullables) Player(org.bukkit.entity.Player) ARROWS(gg.projecteden.nexus.features.menus.SignMenuFactory.ARROWS) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) BigDecimal(java.math.BigDecimal) InventoryContents(fr.minuskube.inv.content.InventoryContents) Material(org.bukkit.Material) ClickableItem(fr.minuskube.inv.ClickableItem) 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) ItemClickData(fr.minuskube.inv.ItemClickData) Utils(gg.projecteden.nexus.utils.Utils) ItemStack(org.bukkit.inventory.ItemStack) Consumer(java.util.function.Consumer) ExchangeType(gg.projecteden.nexus.models.shop.Shop.ExchangeType) ItemSetting(gg.projecteden.nexus.utils.ItemBuilder.ItemSetting) Nullables.isNullOrAir(gg.projecteden.nexus.utils.Nullables.isNullOrAir) ShopUtils.prettyMoney(gg.projecteden.nexus.features.shops.ShopUtils.prettyMoney) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) Function(java.util.function.Function) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) ItemClickData(fr.minuskube.inv.ItemClickData) ItemStack(org.bukkit.inventory.ItemStack) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException)

Aggregations

ClickableItem (fr.minuskube.inv.ClickableItem)3 InventoryContents (fr.minuskube.inv.content.InventoryContents)3 Nexus (gg.projecteden.nexus.Nexus)3 ARROWS (gg.projecteden.nexus.features.menus.SignMenuFactory.ARROWS)3 ItemBuilder (gg.projecteden.nexus.utils.ItemBuilder)3 PlayerUtils (gg.projecteden.nexus.utils.PlayerUtils)3 Material (org.bukkit.Material)3 Player (org.bukkit.entity.Player)3 Shops (gg.projecteden.nexus.features.shops.Shops)2 ShopProvider (gg.projecteden.nexus.features.shops.providers.common.ShopProvider)2 InvalidInputException (gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException)2 Shop (gg.projecteden.nexus.models.shop.Shop)2 ExchangeType (gg.projecteden.nexus.models.shop.Shop.ExchangeType)2 Product (gg.projecteden.nexus.models.shop.Shop.Product)2 Nullables (gg.projecteden.nexus.utils.Nullables)2 Nullables.isNullOrAir (gg.projecteden.nexus.utils.Nullables.isNullOrAir)2 StringUtils.pretty (gg.projecteden.nexus.utils.StringUtils.pretty)2 Utils (gg.projecteden.nexus.utils.Utils)2 BigDecimal (java.math.BigDecimal)2 RoundingMode (java.math.RoundingMode)2