Skip to content

A simple, opensource Menu API for the Spigot API.

Notifications You must be signed in to change notification settings

nicholasveronico/MenuAPI

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Menu API

This is a simplistic Menu API made for the Spigot API, with built-in pagination, actions, and more.

Note

  • Menu fillers are currently in development, and issues may occur.

Usage

Registering the menu handler:

You have to register the MenuHandler object somewhere, preferably inside of the main class, for example:

@Override
public void onEnable() {
    new MenuHandler(this);
    // your code
}

Creating a new menu

You have to make a class extending the Menu class (or PaginatedMenu), or make a new anonymous class, for example:

Anonymous Class

import io.github.nosequel.menu.buttons.Button;
import io.github.nosequel.menu.pagination.PaginatedMenu;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.List;

class ExampleClass {

    public ExampleClass(Player player) {
        final PaginatedMenu menu = new PaginatedMenu(player, "example", 18) {
            @Override
            public void tick() {
                for (int i = 0; i < 27; i++) {
                    this.buttons[i] = new Button(Material.ENDER_PEARL)
                            .setDisplayName("&aSlot: " + i)
                            .setClickAction(event -> event.setCancelled(true));
                }
            }
        };

        menu.updateMenu();
    }
}

Extending Menu

import io.github.nosequel.menu.buttons.Button;
import io.github.nosequel.menu.pagination.PaginatedMenu;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.List;

public class ExampleMenu extends PaginatedMenu {

    public ExampleMenu(Player player) {
        super(player, "example", 18, 4);
    }

    @Override
    public void tick() {
        for(int i = 0; i < 27; i++) {
            this.buttons[i] = new Button(Material.ENDER_PEARL)
                    .setDisplayName("&aSlot: " + i)
                    .setClickAction(event -> event.setCancelled(true));
        }
    }
}
new ExampleMenu(player).updateMenu();

Configuring Menu Pagination

PaginatedMenu#setNavigationPosition(NavigationPosition)
PaginatedMenu#setNextPageButton(Button)
PaginatedMenu#setPreviousPageButton(Button)

Configuring Pagination Navigation Bar

In order to add additional buttons to the navigation bar, you must create a button and add it to the navigation bar. The int provided must be a number from 1 to 7. An image showing the slots is provided below:

PaginatedMenu#getNavigationPosition().setNavigationBetweenButton(int, PaginatedMenu, Button);

Navigation Buttons

An example of this implementation is shown below:

import io.github.nosequel.menu.buttons.Button;
import io.github.nosequel.menu.pagination.PaginatedMenu;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.List;

public class ExampleMenu extends PaginatedMenu {

    public ExampleMenu(Player player) {
        super(player, "example", 18, 4);
    }

    @Override
    public void tick() {
        Button close = new Button(Material.STRUCTURE_VOID)
                .setDisplayName("&3&lExit Menu")
                .setClickAction(click -> {
                    click.setCancelled(true);
                    click.getWhoClicked().closeInventory();
                });

        getNavigationPosition().setNavigationBetweenButton(4, this, close);
    }
}

Configuring Menu Filling

Menu#addFiller(FillingType)

About

A simple, opensource Menu API for the Spigot API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%