use of gg.projecteden.nexus.features.menus.api.opener.InventoryOpener 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;
}
Aggregations