Anything Inventory [Spigot 1.8.X] 1.2

Create an Inventory menu with ease!

  1. Bfox1
    Contributors:
    bfox1
    [​IMG]
    Anything Inventory is a Plugin API designed to create Menus with ease.​

    How it works: AI(Anything Inventory) Stores plugin information to which has been registered. This is a Key for the Plugin which wants to utilize AIs menu API. Having AI store the Plugin information, it houses all and any plugin that uses the API. Providing an easy way for plugins to interact with other plugins Menus if necessary. Since each Menu is split based upon the Plugin, you will never get duplicate Menus. As a bonus, the items you add into the menu will never override each other. Even if they have the Same name.


    First things first you need to register your Plugin for Menu Use:
    This can be added to your Main Plugin Class.
    Code (Text):

    private final AnythingInventory ai;

    public void onEnable()
    {
    this.ai = getPluginManager().getPlugin("AnythingInventory);

    if(ai == null)
    {
    getPluginManager().disablePlugin(this);
    }
    }
     
    This is a test menu
    Code (Text):
    public class Test extends InventoryMenu
    {
        public Test(String menuName, int inventorySize, JavaPlugin plugin)
        {
            super(menuName, inventorySize, plugin);
            this.addItemIcon(new ItemIcon(new ItemStack(Material.DIAMOND), "This is my Test", null, ItemAction.ITEM, new ItemStack(Material.DIAMOND)));

            /**
             * The ItemIcon consists of a few parameters for more complex Icons.
             * So lets break this down.
             * The first parameter is the ItemStack to be represented when the inventory is Opened.
             * The Second parameter is the ItemStacks Name. Pretty Simple.
             * The third is the Lore of the ItemStack presented.
             * The forth is the Action being performed when it is clicked on. You have ITEM, INVENTORY, COMMAND, TELEPORT, NONE.
             * Note: ItemAction NONE is meant for an Empty Item or Filler item inside the menu which has no use.
             * The fifth is the Performing action taken when its clicked on. This MUST tie in with the ItemAction you set.
             * Example: ItemAction.ITEM, new ItemStack(Material.DIRT), ItemAction.Inventory, "AnotherTestMenu"
             * ItemAction.Command, "/gamemode 0", ItemAction.TELEPORT, new Location(world, x, y, z), ItemAction.NONE, null
             */
        }
    }
    To register it simply add the following line:
    Code (Text):
    ai.addMenu(this, new TestMenu("Test Menu", 54, this);

     

    Inside your EventListener, add the following:
    Code (Text):
    @EventHandler

        public void onItemIconClicked(InventoryClickEvent event)
        {
            ItemIcon icon = ai.iconUtil.validateClickedItemAsIcon(event, this); //This is assuming your event listener is the Main plugin class

            if(icon != null)
            {
                ai.iconUtil.lockInventoryFromItemStack(event, this);
           
           
                    icon.fireItemAction((Player)event.getWhoClicked());
             
            }
        }
    After the icon has fired its Action, we have added a clever way to stop such events from triggering with the ItemActionEvent which triggers upon firing the Action. This is great for restricting certain players from clicking on the Item or preventing players from using another plugins Icon.

    So lets say the Internal Actions are not what you want and you have something else you want to be performed when the Icon is clicked on. Here is an example of a Custom Action Class
    Code (Text):
    /**
    * Instead of (new ItemIcon(itemstack, display name, lore, ItemAction, Action Parameters)) you would apply
    * custom action in place of ItemAction.
    * (new ItemIcon(itemStack, display name, lore, new Test(), Action Parameters))
    */
    public class Test implements CustomAction {

        @Override
        public void fireCustomAction(Player player, Object object)
        {
            //Add custom stuff here
        }

        @Override
        public String getName() {
            return "Test Action";
        }
    }

    One last step to add when opening the Inventory is pretty simple
    to get the Inventory Object simply use this method:
    Code (Text):
    //First you need to grab the instance of the Anything Inventory Class
    //This is also assuming you are getting the Inventory within the your plugins main class.
    ai.getMenu(this, "Test Menu").getInventory());

    If you have any more questions please feel free to ask me! More updates will come to the API as I progress along with a Open Source version of the API.
    ferrinweb likes this.