Illuminatiiiiii
1/9/2019 - 10:27 PM

Armor Stand GUI Part 3

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.ArmorStand;
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;
import java.util.HashMap;

public final class ArmorStandGUI extends JavaPlugin {

    public HashMap<Player, ArmorStand> armorstands = new HashMap<>();

    @Override
    public void onEnable() {
        // Plugin startup logic

        getServer().getPluginManager().registerEvents(new MenuHandler(this), this);

        getCommand("armorstand").setExecutor(new ArmorStandCommand(this)); //Opens main menu
    }

    //Create and open the main Armor Stand menu
    public void openMainMenu(Player player){
        Inventory main_menu = Bukkit.createInventory(player, 9, ChatColor.BLUE + "Armor Stand GUI");

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

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

        //Add everything
        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, 9, ChatColor.GREEN + "Create a Armor Stand");

        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);

        create_menu.setItem(0, arms);
        create_menu.setItem(1, glow);
        create_menu.setItem(2, armor);
        create_menu.setItem(3, base);
        create_menu.setItem(7, complete);
        create_menu.setItem(8, 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.ArmorStand;
import org.bukkit.entity.EntityType;
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 a Armor Stand";
        final String CONFIRM_MENU = ChatColor.GREEN + "Confirm Option";

        //Determine which inventory is open
        if (e.getClickedInventory().getTitle().equalsIgnoreCase(MAIN_MENU)){
            //Figure out what button was clicked
            switch(e.getCurrentItem().getType()){
                case ARMOR_STAND:
                    player.sendMessage("Opened Armor Stand Create Menu");
                    //Open the menu for creating an armor stand
                    plugin.openCreateMenu(player);
                    break;
                case BARRIER:
                    player.sendMessage("Closing Menu.");
                    player.closeInventory();
                    break;
            }

            e.setCancelled(true);
        }else if(e.getClickedInventory().getTitle().equalsIgnoreCase(CREATE_MENU)){

            if (!plugin.armorstands.containsKey(player)){
                ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(player.getLocation(), EntityType.ARMOR_STAND);
                stand.setVisible(false);
                plugin.armorstands.put(player, stand);
            }

            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("Choose Armor?");
                    //Armor select menu
                    break;
                case STONE_SLAB:
                    player.sendMessage("Add Base?");
                    plugin.openConfirmMenu(player, Material.STONE_SLAB);
                    break;
                case GREEN_WOOL:
                    if (plugin.armorstands.containsKey(player)){
                        ArmorStand stand = plugin.armorstands.get(player);
                        stand.setVisible(true);
                        plugin.armorstands.remove(player);
                        player.closeInventory();
                        player.sendMessage("Created Armor Stand");
                    }
                    break;
                case RED_WOOL:
                    if (plugin.armorstands.containsKey(player)){
                        plugin.armorstands.remove(player);
                        player.closeInventory();
                        player.sendMessage("Cancelled Armor Stand");
                    }
                    break;
            }
            e.setCancelled(true);
        }else if(e.getClickedInventory().getTitle().equalsIgnoreCase(CONFIRM_MENU)){
            if (e.getClickedInventory().contains(Material.ARMOR_STAND)) {
                switch (e.getCurrentItem().getType()) {
                    case GREEN_WOOL:
                        player.sendMessage("Option Confirmed");
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setArms(true);
                        }
                        plugin.openCreateMenu(player);
                        break;
                    case RED_WOOL:
                        player.sendMessage("Cancelled Option");
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setArms(false);
                        }
                        plugin.openCreateMenu(player);
                        break;
                }
            }else if(e.getClickedInventory().contains(Material.BEACON)){
                switch (e.getCurrentItem().getType()) {
                    case GREEN_WOOL:
                        player.sendMessage("Option Confirmed");
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setGlowing(true);
                        }
                        plugin.openCreateMenu(player);
                        break;
                    case RED_WOOL:
                        player.sendMessage("Cancelled Option");
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setGlowing(false);
                        }
                        plugin.openCreateMenu(player);
                        break;
                }
            }else if(e.getClickedInventory().contains(Material.STONE_SLAB)){
                switch (e.getCurrentItem().getType()) {
                    case GREEN_WOOL:
                        player.sendMessage("Option Confirmed");
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setBasePlate(true);
                        }
                        plugin.openCreateMenu(player);
                        break;
                    case RED_WOOL:
                        player.sendMessage("Cancelled Option");
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setBasePlate(false);
                        }
                        plugin.openCreateMenu(player);
                        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;
    }
}