/** * Open the menu to the specified player. * * @param player The {@link Player} the inventory is going to be shown to. * @return the {@link Menu} instance. */ public final Menu open(Player player) { if (this.hasOpen(player)) { // Nope return this; } InventoryView view = player.openInventory(getInventory(player)); if (!view.getTopInventory().equals(getInventory(player))) { throw new IllegalStateException( "Failed to open inventory (was the InventoryOpenEvent cancelled?)"); } setMenu(player, this); this.onOpen(player); this.components .keySet() .forEach( component -> { component.onOpen(player); component.draw(player); }); return this; }