# Create severale pages menu

## Methods

<details>

<summary>onCloseMenu [OVERRIDE]</summary>

This event is called when player close the menu

```java
protected abstract void onCloseMenu(Player player);
```

</details>

<details>

<summary>onOpenMenu [OVERRIDE]</summary>

This event is called when player open the menu

```java
protected abstract void onOpenMenu(Player player);
```

</details>

<details>

<summary>onSwitchPage [OVERRIDE]</summary>

This event is called when player change page of menu

```java
protected abstract void onSwitchPage(Player player, int page);
```

</details>

<details>

<summary>addItem</summary>

</details>

<details>

<summary>refreshPage</summary>

I'm inviting you to see the same doc on refreshPage in [this part](https://kap35.gitbook.io/kap-easy-menu-plugin/dev-manual/create-a-menu/create-simple-menu).

</details>

{% tabs %}
{% tab title="Version 2." %}

## What's several page menu ?

several page menu is chest menu that allow you several pages. All pagination page logic is already set, you just have to place your items.

{% hint style="info" %}
When you gonna give your menu size, the system will keep last 9 slot for him and you cannot place items on thoses 9 last slots.
{% endhint %}

## Create your first menu

```java
public class MySimpleMenu extends ChestPaginationMenu {
    public MySimpleMenu(JavaPlugin plugin) {
        int menuSize = 27;
        super(plugin, "My Menu Title", menuSize);
    }
    
    @Override
    protected void onCloseMenu(Player player) {
        //event when user open your menu
    }
    
    @Override
    protected void onOpenMenu(Player player) {
        //event when user close your menu
    }
    
    @Override
    protected void onSwitchPage(Player player, int page) {
        //event when user chnage page
    }
}
```

Now you have your menu, let's add it to menu system.

```java
public MyPlugin extends JavaPlugin {
    GuiManager guiManager;
    
    public MyPlugin() {
    
    }
    
    private void initMyMenus() {
        MySimpleMenu simpleMenu = new MySimpleMenu(this);
        guiManager.registerMenus(simpleMenu, "MySimpleMenu");
    }
}
```

{% hint style="warning" %}
To init GuiManager, please refer to this documentation :&#x20;

[init-your-plugin](https://kap35.gitbook.io/kap-easy-menu-plugin/dev-manual/init-your-plugin "mention")
{% endhint %}

## Add items in menu

```java
public class MySimpleMenu extends ChestPaginationMenu {
    public MySimpleMenu(JavaPlugin plugin) {
        ...
        GuiItem item = new GuiItem(...);
        // add item in slot 2 page 0
        addItem(item, 2, 0);
    }
    
    @Override
    protected void onOpenMenu(Player player) {
        GuiItem otherItem = new GuiItem(...);
        // place only for the player otherItem in slot 3 page 1
        addItem(player, otherItem, 3, 1);
    }
}
```

{% endtab %}

{% tab title="Version 1." %}
{% hint style="danger" %}
This version is outdated. Please download latest release with versioning check system.

Some methods explained before does not exist in this version.
{% endhint %}

## Why use GuiMenuPages ?

GuiMenuPages is made to create easly a menu that contains the number of pages you want.

This class is better than GuiMenu for severale pages.

As the same way as GuiMenu, GuiMenuPages contains constructor, init function and update function.

## Let's see how to create this menu !

```java
public class MyMenu extends GuiMenuPages {

        public MyMenu(MyPlugin plugin) {
                // the 1st argument is your plugin class
                // the 2nd argument is the number of slots in your menu
                // the 3rd argument is your menu title
                // the 4th argument set your menu static or not
                super(plugin, 9, "My Menu Title", true);
        }
        
        @Override
        protected void initGUI() {
            super.initGUI();
            System.out.println("Init My Menu !");
        }
        
        @Override
        protected void onOpenMenu(Player player) {
            super.onOpenMenu(player);
            System.out.println("My menu is open !");
        }
        
        @Override
        protected void onCloseMenu(Player player) {
            super.onCloseMenu(player);
            System.out.println("My menu is close !");
        }

}
```

{% hint style="danger" %}
Your menu size is your content size. Do not calculate size with next and previous page items. It is added automatically in your menu.
{% endhint %}

To save your menu in the easy menu plugin please follow the instruction in [Create normal menu](https://kap35.gitbook.io/kap-easy-menu-plugin/dev-manual/create-simple-menu#lets-add-this-menu).
{% endtab %}
{% endtabs %}
