Skip to content

ericstolly/menu-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bukkit Menu Framework

Licence

Stars Badge Forks Badge Pull Requests Badge Issues Badge GitHub contributors

Installation

Maven

<repositories>
  <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependency>
    <groupId>com.github.ericstolly</groupId>
    <artifactId>menu-api</artifactId>
    <version>-b86620c97e-1</version>
    <scope>compile</scope>
</dependency>

Gradle

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

dependencies {
    implementation 'com.github.ericstolly:menu-api:Tag'
}

Usage

Menu Types

There are plenty of menu types you can pick from to star in your next product with many more in the works. These can be found in MenuType#.

AUTOMATIC_ROW_CHEST (Automatic)
SINGLE_ROW_CHEST (1 Row),
DOUBLE_ROW_CHEST (2 Rows),
TRIPPLE_ROW_CHEST (3 Rows),
QUADRUPLE_ROW_CHEST (4 Rows),
QUINTUPLE_ROW_CHEST (5 Rows),
SEXTUPLE_ROW_CHEST (6 Rows),
HOPPER,
BREWING_STAND,
DISPENSER,
DROPPER;

Update Types

There are 3 update modes that control how menus are updated/refreshed on your server. These can be found in MenuUpdateType#.

RUNNABLE (Repeating task every x amount of time),
ON_CLICK (Only when someone clicks a button),
NONE;

Implementations

Menus

Menus can be easily created with a few lines of code. We have provided you an example below.

public class ExampleMenu extends Menu {
  
    @Override
    public String getTitle(final @NonNull Player player) {
        return ChatColor.GOLD + "Example Menu";
    }

    @Override
    public MenuType getMenuType() {
        return MenuType.SINGLE_ROW_CHEST;
    }

    @Override
    public Map<Integer, MenuButton> getButtons(final @NonNull Player player) {
        HashMap<Integer, MenuButton> toReturn = new HashMap<Integer, MenuButton>();
        
        toReturn.put(1, new SimpleButton(new ItemstackBuilder(Material.DIRT).build(), false, null));
        
        return toReturn;
    }
}

Making a menu update/refresh is quickly done by overriding the getUpdateType(MenuUpdateType)#. To disable all update/refreshing of buttons you simply have to remove the overriding method. It will default to MenuUpdateType.NONE.


Buttons

We have provided you with SimpleButton# to speed up development using this Framework. We have provided you an example below.

new SimpleButton(new ItemstackBuilder(Material.DIRT).build(), false, null);

Buttons can also have a listener attached to them. This can be in an in-line or seperate class style or simply set to null if not required. We have provided you an example below.

// In-line style

new SimpleButton(new ItemstackBuilder(Material.DIRT).build(), false, (InventoryClickEvent event) -> { 
            event.getWhoClicked().sendMessage("Hello World from inline class!");
        });
// Seperate class style

public class ExampleButtonListener implements MenuButtonListener, Listener {

  public void onButtonClick(InventoryClickEvent event) {
    event.getWhoClicked().sendMessage("Hello World from seperate class!");
  }
}

This method can be paired with the provided ItemstackBuilder# class and methods to easily create the button ItemStack#.

  • JavaDoc
    • SimpleButton(ItemStack itemStack, boolean editable, MenuButtonListener menuButtonListener)

Registering The Listener

Once you have created your menu, buttons, it's time to register the listener. We have provided you an example below.

public class ExamplePlugin extends JavaPlugin {

  @Override
  public void onEnable() {
    getServer().getPluginManager().registerEvents(new MenuListener(), (Plugin)this);
  }
}

Opening A Menu

Once you have created your menu, buttons and registered the listener, you can now open it! We have provided you an example below.

new ExampleMenu(instance).open(player);
  • JavaDoc
    • ExampleMenu(JavaPlugin javaPlugin)

About

A very rudimentary and user-friendly Bukkit menu framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages