Illuminatiiiiii
1/6/2019 - 2:42 PM

Armor Stand GUI Part 2

Episode 17:

package me.illuminatiproductions.armorstandgui;

import me.illuminatiproductions.armorstandgui.commands.ArmorStandCommand;
import me.illuminatiproductions.armorstandgui.events.MenuHandler;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;

public final class ArmorStandGUI extends JavaPlugin {

    @Override
    public void onEnable() {
        // Plugin startup logic
        System.out.println("Plugin has started up.");

        getCommand("armorstand").setExecutor(new ArmorStandCommand(this));

        getServer().getPluginManager().registerEvents(new MenuHandler(this), this);
    }
    public void openMainMenu(Player player){
        Inventory main_menu = Bukkit.createInventory(player, 9, ChatColor.BLUE + "Armor Stand GUI");

        //Options for main menu
        ItemStack create = new ItemStack(Material.ARMOR_STAND);
        ItemMeta create_meta = create.getItemMeta();
        create_meta.setDisplayName(ChatColor.GREEN + "Create");
        ArrayList<String> create_lore = new ArrayList<>();
        create_lore.add(ChatColor.DARK_PURPLE + "Create a new armor stand.");
        create_meta.setLore(create_lore);
        create.setItemMeta(create_meta);

        ItemStack close = new ItemStack(Material.BARRIER);
        ItemMeta close_meta = close.getItemMeta();
        close_meta.setDisplayName(ChatColor.RED + "Close");
        close.setItemMeta(close_meta);

        main_menu.setItem(0, create);
        main_menu.setItem(8, close);
        player.openInventory(main_menu);
    }

    public void openCreateMenu(Player player){
        Inventory create_menu = Bukkit.createInventory(player, 18, ChatColor.GREEN + "Create an Armor Stand");

        //Options
        ItemStack arms = new ItemStack(Material.ARMOR_STAND);
        ItemStack glow = new ItemStack(Material.BEACON);
        ItemStack armor = new ItemStack(Material.LEATHER_CHESTPLATE);
        ItemStack base = new ItemStack(Material.STONE_SLAB);
        ItemStack complete = new ItemStack(Material.GREEN_WOOL); //Finish creating your armor stand
        ItemStack cancel = new ItemStack(Material.RED_WOOL); //Cancel and return to main menu

        ItemMeta arms_meta = arms.getItemMeta();
        arms_meta.setDisplayName(ChatColor.YELLOW + "Arms");
        ItemMeta glow_meta = glow.getItemMeta();
        glow_meta.setDisplayName("Glow");
        ItemMeta armor_meta = armor.getItemMeta();
        armor_meta.setDisplayName(ChatColor.AQUA + "Armor");
        ItemMeta base_meta = base.getItemMeta();
        base_meta.setDisplayName(ChatColor.GOLD + "Base");
        ItemMeta complete_meta = complete.getItemMeta();
        complete_meta.setDisplayName(ChatColor.GREEN + "Complete & Create");
        ItemMeta cancel_meta = cancel.getItemMeta();
        cancel_meta.setDisplayName(ChatColor.RED + "Cancel Creation");
        arms.setItemMeta(arms_meta);
        glow.setItemMeta(glow_meta);
        armor.setItemMeta(armor_meta);
        base.setItemMeta(base_meta);
        complete.setItemMeta(complete_meta);
        cancel.setItemMeta(cancel_meta);

        //Add items
        create_menu.setItem(0, arms);
        create_menu.setItem(1, glow);
        create_menu.setItem(2, armor);
        create_menu.setItem(3, base);
        create_menu.setItem(16, complete);
        create_menu.setItem(17, cancel);
        player.openInventory(create_menu);
    }

    public void openConfirmMenu(Player player, Material option){
        Inventory confirm_menu = Bukkit.createInventory(player, 36, ChatColor.GREEN + "Confirm Option");

        ItemStack option_item = new ItemStack(option);
        ItemMeta option_meta = option_item.getItemMeta();
        if (option == Material.ARMOR_STAND){
            option_meta.setDisplayName(ChatColor.YELLOW + "Give Arms?");
            option_item.setItemMeta(option_meta);
        }else if(option == Material.BEACON){
            option_meta.setDisplayName(ChatColor.YELLOW + "Add Glow?");
            option_item.setItemMeta(option_meta);
        }else if(option == Material.STONE_SLAB){
            option_meta.setDisplayName(ChatColor.YELLOW + "Add Base?");
            option_item.setItemMeta(option_meta);
        }
        ItemStack yes = new ItemStack(Material.GREEN_WOOL);
        ItemMeta yes_meta = yes.getItemMeta();
        yes_meta.setDisplayName(ChatColor.GREEN + "YES");
        yes.setItemMeta(yes_meta);
        ItemStack no = new ItemStack(Material.RED_WOOL);
        ItemMeta no_meta = no.getItemMeta();
        no_meta.setDisplayName(ChatColor.RED + "NO");
        no.setItemMeta(no_meta);

        confirm_menu.setItem(13, option_item);
        confirm_menu.setItem(21, yes);
        confirm_menu.setItem(23, no);
        player.openInventory(confirm_menu);
    }

}
package me.illuminatiproductions.armorstandgui.events;

import me.illuminatiproductions.armorstandgui.ArmorStandGUI;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;

public class MenuHandler implements Listener {

    ArmorStandGUI plugin;

    public MenuHandler(ArmorStandGUI plugin) {
        this.plugin = plugin;
    }

    @EventHandler
    public void onMenuClick(InventoryClickEvent e){
        Player player = (Player) e.getWhoClicked();

        //Menu list
        final String MAIN_MENU = ChatColor.BLUE + "Armor Stand GUI";
        final String CREATE_MENU = ChatColor.GREEN + "Create an Armor Stand";
        final String CONFIRM_MENU = ChatColor.GREEN + "Confirm Option";

        if (e.getClickedInventory().getTitle().equalsIgnoreCase(MAIN_MENU)){
            switch(e.getCurrentItem().getType()){
                case ARMOR_STAND:
                    player.sendMessage("Opened Armor Stand Create Menu");
                    player.closeInventory();
                    //Open the armor stand menu
                    plugin.openCreateMenu(player);
                    break;
                case BARRIER:
                    player.sendMessage("Closing Main Menu");
                    player.closeInventory();
                    break;
            }
        }else if(e.getClickedInventory().getTitle().equalsIgnoreCase(CREATE_MENU)){
            switch(e.getCurrentItem().getType()){
                case ARMOR_STAND:
                    player.sendMessage("Add Arms?");
                    plugin.openConfirmMenu(player, Material.ARMOR_STAND);
                    break;
                case BEACON:
                    player.sendMessage("Add Glow?");
                    plugin.openConfirmMenu(player, Material.BEACON);
                    break;
                case LEATHER_CHESTPLATE:
                    player.sendMessage("Add Armor?");
                    //Open armor menu
                    break;
                case STONE_SLAB:
                    player.sendMessage("Add Base?");
                    plugin.openConfirmMenu(player, Material.STONE_SLAB);
                    break;
            }
            e.setCancelled(true);
        }
    }

}
package me.illuminatiproductions.armorstandgui.commands;

import me.illuminatiproductions.armorstandgui.ArmorStandGUI;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class ArmorStandCommand implements CommandExecutor {

    ArmorStandGUI plugin;

    public ArmorStandCommand(ArmorStandGUI plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {


        if(sender instanceof Player){
            Player player = (Player) sender;
            plugin.openMainMenu(player);
        }
        return true;
    }
}