use of gg.projecteden.nexus.features.menus.api.ItemClickData 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.of(itemStack.get(), action));
else
contents.set(row, 4, ClickableItem.of(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.of(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.of(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.of(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.of(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);
})));
}
}
Aggregations