InventoryMenuAPI

InventoryMenuAPI

This plugin will serve as an API to plugin developers who want to easily create interactive menus in their plugins. The developer using the API will be able to populate the menu with different options (using the inventory slots), and show players the inventory whenever they should chose. Each menu slot will be able to perform virtually any function (that is possible within the scope of Java and the Bukkit API).


Beta Release

I haven't been able to work much on this for the past few months, but I got working on it a few days and have been able to get a solid Beta version of the API out.

Current Version: Beta-0.1

Last updated: March 29, 2014


Features

  • Create and show players interactive menus made from inventories
  • Add descriptions to menu slots
  • Color support using & formatting codes
  • Enable/Disable auto-closing menus after an option is clicked on a per-slot basis.
  • Create slots to do whatever you want simply by extending the AbstractSlot class and implementing the execute method.


Usage

Creating Custom Slots

Simply extend the AbstractSlot class, define an explicit constructor, and implement the execute() method.

public class BroadcastSlot extends AbstractSlot {

	private String message;
	
        /**
            The id will be what the slot is named, and the material is the
            the item type that represents this slot in the inventory menu.
        */
	public BroadcastSlot(String id, Material mat, String message) {
		super(id, mat);
		this.message = message;
	}

	/**
             This method is what will run when the player clicks this slot.
        */
	public void execute(Player player) {
		Bukkit.broadcastMessage(player.getName() + ": " + message);
	}
}

Building and Showing Players Your Menu

To get the InventoryMenuAPI plugin instance, simply call the static method:

InventoryMenuAPI menuAPI = InventoryMenuAPI.getInstance();

Building your menu:

First, you need to create a MenuBuilder object:

// Pass in your Plugin instance and the name of your menu.
MenuBuilder menuBuilder = new MenuBuilder(Plugin owner, String menuName);

Then, you can use the MenuBuilder to build your menu (I'm using the custom slot we made earlier.):

// This adds a slot to our MenuBuilder called "First Slot", represented by bedrock, 
// and the third parameter is specifically for our custom slot. It's going to be the message 
// that is broadcasted when the player clicks on this slot.
menuBuilder.addSlot(new BroadcastSlot("&6First Slot", Material.BEDROCK, 
                 "This is slot one. Does not close when clicked."))
			.setCloseOnClick(false).setDescription("&1This is my description!");

The MenuBuilder.addSlot(AbstractSlot slot) method will return the AbstractSlot that you add. This allows for the stringing together of the AbstractSlot.setDescription(String desription) and AbstractSlot.setCloseOnClick(boolean closeOnClick) methods.
By default, the menus close when a slot is clicked, and have no description.

After adding however many slots you want, you can then build the menu with the MenuBuilder.getMenu() method:

InventoryMenu menu = menuBuilder.getMenu();

Then, you can send the menu to the players you want by using invoking either of the following methods on the InventoryMenuAPI instance:
InventoryMenuAPI.showInventoryMenu(Player player, InventoryMenu menu)
OR
InventoryMenuAPI.showInventoryMenu(Collection<Player> players, InventoryMenu menu)


Maven Information

If you want to use Maven to build your project that has InventoryMenuAPI as a dependency, you can add my public repository to your pom.xml

<repositories>
    ...
    <repository>
        <id>amhokies-repo</id>
        <url>http://amhokies.org/maven2</url>
    </repository>
    ...
</repositories>

Then, add the dependency:

<dependencies>
    ...
    <dependency>
        <groupId>edu.vccs.email.amm28053</groupId>
        <artifactId>InventoryMenuAPI</artifactId>
        <version>BETA-0.1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    ...
<dependencies>


Lastly, if you have any questions, please don't hesitate to message me.

JavaDoc: http://amhokies.org/javadoc/InventoryMenuAPI/
GitHub: https://github.com/amhokies/InventoryMenuAPI


Comments

Posts Quoted:
Reply
Clear All Quotes

About This Project

Categories

Members

Recent Files