Getting Started - Xernas78/menu-lib GitHub Wiki

Getting Started

Installation

First, you have to install it, you can use a dependency manager or the release

Dependency Manager

Note: Since, for now, this project doesn't have a repository, you have to do it locally

You must have Maven installed

Clone the GitHub repo
git clone https://github.com/Xernas78/menu-lib.git
Then install it as a local Maven dependency using
maven install

Maven

Add this to your pom.xml file:

<dependency>
   <groupId>dev.xernas</groupId>
   <artifactId>MenuLib</artifactId>
   <version>1.1.0</version>
</dependency>

Gradle

Add this to your build.gradle file:

repositories {
  mavenLocal()
}

dependencies {
    compile 'dev.xernas:MenuLib:1.1.0'
}

Release

Just add the jar file to the project :)

Congratulations! You have now installed the library

Set Up

To use it you now have to connect the library to your plugin, you just have to use MenuLib.init(plugin)

Here is an example of the Main class:

import dev.xernas.menulib.MenuLib;
import org.bukkit.plugin.java.JavaPlugin;

public final class MenuLibTests extends JavaPlugin {

    @Override
    public void onEnable() {
        MenuLib.init(this);
    }

    @Override
    public void onDisable() {

    }
}

You are now ready to create Menus !

Creating Menus

To create a Menu, you have to create a class that extends from the Menu or PaginatedMenu class.

import dev.xernas.menulib.Menu;
import dev.xernas.menulib.utils.InventorySize;
import dev.xernas.menulib.utils.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public class WikiMenu extends Menu {

    public WikiMenu(Player owner) {
        super(owner);
    }

    @Override
    public @NotNull String getName() {
        return "Welcome to the wiki !"; // The menu name
    }

    @Override
    public @NotNull InventorySize getInventorySize() {
        return InventorySize.LARGEST; // Inventory Sizes: 9 (SMALLEST), 18, 27, 36, 45, 54 (LARGEST)
    }

    @Override
    public void onInventoryClick(InventoryClickEvent inventoryClickEvent) {
        // Do whatever you want here, the event is fired when the menu is clicked
    }

    @Override
    public @NotNull Map<Integer, ItemStack> getContent() { // This method gets the content of the menu
        return fill(Material.GRAY_STAINED_GLASS_PANE); // The util method fill(material) fills the menu with the material as the parameter
    }
}

The inventory works with a Map so it's easier to work with, the map has an Integer for the key, it's the slot number (starting at 0), and has an ItemStack for the value, it's the item that goes into the slot.

Then, to open your menu, create a new instance of it and call the open() method

WikiMenu menu = new WikiMenu(player);
menu.open();

For example, you can do that inside a command to open the menu when you execute a command.

Go see the Menus page for more information about menus!

Learn More

Okay, now that you know the basics, you can dive into the more serious stuff like the ItemBuilder and the PaginatedMenu :)

⚠️ **GitHub.com Fallback** ⚠️