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