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;
}
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);
}));
}
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();
}
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());
}));
}
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());
}));
}
Aggregations