Library [1.8/1.7] MenuEngine - Create simple and complex menus easily

Discussion in 'Resources' started by Vilsol, Feb 24, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Vilsol

    MenuEngine
    GitHub Repo
    Current version: 1.3​

    Hello everyone! I am finally writing this up, even though my library has been out for a while, I have been debugging it intensively, and it seems to be at a perfectly working state.

    What is MenuEngine?
    MenuEngine is a library, that makes it extremely easy to create custom menu's, including very simple ones, to complex and dynamic ones.

    Why MenuEngine?
    I have used many menu libraries before, but there always have been certain problems with them, where I wouldn't be able to use them for very complex inventories, or they would lag intensively, or even worse: break and not work at all. I have created MenuEngine, in the hope of fixing all of the above.

    Usage:

    For Server Owners

    Download latest version from Here and put it in your plugins folder.

    For Developers:

    Yes, it doesn't require a repository, it is in the central Maven repository.
    Code:xml
    1. <dependency>
    2. <groupId>me.vilsol</groupId>
    3. <artifactId>menuengine</artifactId>
    4. <version>1.3</version>
    5. </dependency>

    Example:
    Example (open)

    This example will create a menu, with an item that looks like an arrow, and once it left/right clicked, it will send a message to the player who clicked it and with which button.

    TestPlugin.class
    It is required that every object is initialized at least once.​
    Code:java
    1. public class TestPlugin extends JavaPlugin {
    2. public void onEnable(){
    3. // Register Items
    4. new ExampleItem().registerItem();
    5. // Register Menus
    6. new MainMenu();
    7. }
    8. }

    MainMenu.class
    In the simple MenuModel, you can simply add items in the constructor, by only passing the class of the item, and the slot you want the place the item in.​
    Code:java
    1. public class MainMenu extends MenuModel {
    2. public MainMenu() {
    3. super(9, "Main Menu");
    4. getMenu().addItem(ExampleItem.class, 0);
    5. }
    6. }

    ExampleItem.class
    Every menu item has to have its own class. Each item must have a registerItem() method, which will register the item in the MenuEngine.​
    Code:java
    1. public class ExampleItem implements MenuItem {
    2. @Override
    3. public void registerItem() {
    4. MenuItem.items.put(this.getClass(), this);
    5. }
    6.  
    7. @Override
    8. public void execute(Player plr, ClickType click) {
    9. plr.closeInventory();
    10. if(click == ClickType.LEFT){
    11. plr.sendMessage("You Left Clicked!");
    12. }else if(click == ClickType.RIGHT){
    13. plr.sendMessage("You Right Clicked!");
    14. }
    15. }
    16.  
    17. @Override
    18. public ItemStack getItem() {
    19. return new Builder(Material.ARROW).setName("Example Item").getItem();
    20. }
    21. }

     
    Last edited: Feb 26, 2015
    GrandmaJam and Skionz like this.
  2. Offline

    _Filip

    Code:
        @Override
        public ItemStack getItem() {
            return new Builder(Material.ARROW).setName("Example Item").getItem();
        }
    Those are incorrect builder pattern naming conventions.
     
  3. Offline

    Vilsol

    @_Filip Will be fixed in the next release
     
  4. Offline

    _Filip

    @Vilsol You're a pretty goofy guy.
     
    Regablith likes this.
  5. Offline

    Vilsol

    Any criticism is welcome!
     
  6. Offline

    Vilsol

    Released version 1.3.5

    Only one change in this release (though I learned how to auto-deploy to maven central), but this release deprecates old builder methods, and added new ones!
     
  7. Offline

    IhToN

    Hi there, I'm trying to use this API but I can't get it to work in an easy way.

    The only thing I could get to use it and show the menu was this:
    Code:
                    Menu m = MenuModel.getMenu(AdminMenu.class).getMenu();
                    m.addItem(ExampleItem.class, 0);
                    m.addItem(AdminCreateArena.class, 12);
                    m.showToPlayer(p);
                    break;
    As if I do the .getMenu().showToPlayer(p) without adding the items first (there are the getItem.add... in the AdminMenu class) it shows the menu without items.
     
Thread Status:
Not open for further replies.

Share This Page