MenuAPI 1.0

A new way to manage your inventory GUI's!

  1. Thinglord129
    I still see people make use of the open source class that is called "IconMenu".
    I also know that this is not working fast and specialized. That's why I created an API called "MenuAPI". This makes it easy for any developer to create GUI's for players.
    So, no annoying InventoryClickListeners and Icon Menu anymore!

    What this API makes it easy for you is to make highly specialized GUI'ss for each player! Below is an example usable menu through BukkitAPI and a menu created with MenuAPI (Their doing exactly the same!)!

    Using the Bukkit API:
    Code (Text):
    public class BukkitAPI {

        public BukkitAPI() {
            // Register listener!
        }

        public void openGamemodeInventory(Player player){
            ItemStack creativeStack = new ItemStack(Material.REDSTONE);
            ItemStack survivalStack = new ItemStack(Material.DIAMOND_SWORD);

            ItemMeta creativeMeta = creativeStack.getItemMeta();
            creativeMeta.setDisplayName(ChatColor.GOLD + "Creative");

            ItemMeta survivalMeta = survivalStack.getItemMeta();
            survivalMeta.setDisplayName(ChatColor.GOLD + "Survival");

            creativeStack.setItemMeta(creativeMeta);
            survivalStack.setItemMeta(survivalMeta);

            Inventory inventory = Bukkit.getServer().createInventory(null, 9, "Select gamemode:");
            inventory.addItem(creativeStack);
            inventory.addItem(survivalStack);

            player.openInventory(inventory);
        }

        @EventHandler
        public void onPlayerInventoryClick(InventoryClickEvent event){
            if (event.getInventory() == null) return;
            if (event.getInventory().getTitle().equalsIgnoreCase("Select gamemode:")){
                ItemStack itemStack = event.getCurrentItem();
                if (itemStack.getItemMeta().getDisplayName() != null){
                    if (itemStack.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "Creative")){
                        event.getWhoClicked().setGameMode(GameMode.CREATIVE);
                    } else {
                        event.getWhoClicked().setGameMode(GameMode.SURVIVAL);
                    }

                    ((Player) event.getWhoClicked()).sendMessage(ChatColor.RED + "Your gamemode has been updated to " + event.getWhoClicked().getGameMode().toString().toLowerCase() + "!");
                }
            }

        }
    }

    Using the MenuAPI:
    Code (Text):
    public class MenuAPIExample extends Menu {

        public MenuAPIExample() {
            super("Select gamemode:", MenuSize.ONE_LINE);
        }

        @Override
        public Menu getParent() {
            return null;
        }

        @Override
        public void loadElements(Player account) {
            addElement(0, new GamemodeElement(GameMode.SURVIVAL, Material.DIAMOND_SWORD));
            addElement(1, new GamemodeElement(GameMode.CREATIVE, Material.REDSTONE_BLOCK));
        }

        public class GamemodeElement extends MenuElement{

            private GameMode gameMode;
            private Material item;

            public GamemodeElement(GameMode gameMode, Material item) {
                this.gameMode = gameMode;
                this.item = item;
            }

            @Override
            public ItemStack getIcon(Player player) {
                ItemBuilder builder = new ItemBuilder(item);
                builder.setTitle(ChatColor.GOLD + WordUtils.capitalize(gameMode.toString().toLowerCase()));
                return builder.build();
            }

            @Override
            public boolean click(Player player) {
                player.setGameMode(gameMode);
                return true; // Return true to close inventory, false to let it stay open!
            }
        }
    }
    Show the GUI to the player using: new MenuAPIExample().open(player);

    I hope you guys like it!
    You can contact me on the Spigot forums for any issues. (Or twitter @010Julian)
    danenco likes this.