WickedProduction
9/27/2019 - 11:16 PM

Armor Stand Part 4

For Episode 19:

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
        System.out.println("Plugin has started up.");

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

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

        //Setup Config
        getConfig().options().copyDefaults();
        saveDefaultConfig();
    }
    public void openMainMenu(Player player){
        Inventory main_menu = Bukkit.createInventory(player, 9, ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("main-menu")));

        //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, 9, ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("create-menu")));

        //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(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.translateAlternateColorCodes('&', this.getConfig().getString("confirm-menu")));

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

    public void openArmorMenu(Player player){
        Inventory armorMenu = Bukkit.createInventory(player, 45, ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("armor-menu")));

        ItemStack head = new ItemStack(Material.DIAMOND_HELMET);
        ItemStack body = new ItemStack(Material.DIAMOND_CHESTPLATE);
        ItemStack legs = new ItemStack(Material.DIAMOND_LEGGINGS);
        ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS);

        ItemStack confirm = new ItemStack(Material.GREEN_WOOL);
        ItemMeta confirm_meta = confirm.getItemMeta();
        confirm_meta.setDisplayName(ChatColor.GREEN + "Done");
        confirm.setItemMeta(confirm_meta);

        armorMenu.setItem(11, head);
        armorMenu.setItem(12, body);
        armorMenu.setItem(14, legs);
        armorMenu.setItem(15, boots);
        armorMenu.setItem(40, confirm);

        player.openInventory(armorMenu);
    }

}
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;
import org.bukkit.inventory.ItemStack;

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.translateAlternateColorCodes('&', plugin.getConfig().getString("main-menu"));
        final String CREATE_MENU = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("create-menu"));
        final String CONFIRM_MENU = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("confirm-menu"));
        final String ARMOR_MENU = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("armor-menu"));

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

            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:
                    plugin.openConfirmMenu(player, Material.ARMOR_STAND);
                    break;
                case BEACON:
                    plugin.openConfirmMenu(player, Material.BEACON);
                    break;
                case LEATHER_CHESTPLATE:
                    plugin.openArmorMenu(player);
                    break;
                case STONE_SLAB:
                    plugin.openConfirmMenu(player, Material.STONE_SLAB);
                    break;
                case GREEN_WOOL:
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("create-message")));
                    if (plugin.armorstands.containsKey(player)){
                        ArmorStand stand = plugin.armorstands.get(player);
                        stand.setVisible(true);
                        plugin.armorstands.remove(player);
                    }
                    player.closeInventory();
                    break;
                case RED_WOOL:
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("delete-message")));
                    if (plugin.armorstands.containsKey(player)){
                        ArmorStand stand = plugin.armorstands.get(player);
                        stand.remove();
                        plugin.armorstands.remove(player);
                    }
                    player.closeInventory();
                    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(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("confirm-option")));
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setArms(true);
                        }
                        plugin.openCreateMenu(player);
                        break;
                    case RED_WOOL:
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("cancel-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(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("confirm-option")));
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setGlowing(true);
                        }
                        plugin.openCreateMenu(player);
                        break;
                    case RED_WOOL:
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("cancel-option")));
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setGlowing(false);
                        }
                        plugin.openCreateMenu(player);
                        break;
                }
            }if (e.getClickedInventory().contains(Material.STONE_SLAB)){
                switch(e.getCurrentItem().getType()){
                    case GREEN_WOOL:
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("confirm-option")));
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setBasePlate(true);
                        }
                        plugin.openCreateMenu(player);
                        break;
                    case RED_WOOL:
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("cancel-option")));
                        if (plugin.armorstands.containsKey(player)){
                            ArmorStand stand = plugin.armorstands.get(player);
                            stand.setBasePlate(false);
                        }
                        plugin.openCreateMenu(player);
                        break;
                }
            }
            e.setCancelled(true);
        }else if(e.getClickedInventory().getTitle().equalsIgnoreCase(ARMOR_MENU)){

            if (plugin.armorstands.containsKey(player)){
                ArmorStand stand = plugin.armorstands.get(player);
                switch (e.getCurrentItem().getType()){
                    case DIAMOND_HELMET:
                        if (stand.getHelmet().getType() == Material.DIAMOND_HELMET){
                            stand.setHelmet(null);
                            player.sendMessage("Removed");
                        }else{
                            stand.setHelmet(new ItemStack(Material.DIAMOND_HELMET));
                            player.sendMessage("Added");
                        }
                        break;
                    case DIAMOND_CHESTPLATE:
                        if (stand.getHelmet().getType() == Material.DIAMOND_CHESTPLATE){
                            stand.setChestplate(null);
                            player.sendMessage("Removed");
                        }else{
                            stand.setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
                            player.sendMessage("Added");
                        }
                        break;
                    case DIAMOND_LEGGINGS:
                        if (stand.getHelmet().getType() == Material.DIAMOND_LEGGINGS){
                            stand.setLeggings(null);
                            player.sendMessage("Removed");
                        }else{
                            stand.setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS));
                            player.sendMessage("Added");
                        }
                        break;
                    case DIAMOND_BOOTS:
                        if (stand.getHelmet().getType() == Material.DIAMOND_BOOTS){
                            stand.setBoots(null);
                            player.sendMessage("Removed");
                        }else{
                            stand.setBoots(new ItemStack(Material.DIAMOND_BOOTS));
                            player.sendMessage("Added");
                        }
                        break;
                    case GREEN_WOOL:
                        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;
    }
}
create-message: '&eCreated Armor Stand'
delete-message: '&cDeleted Armor Stand'
confirm-option: '&aOption Confirmed'
cancel-option: '&cOption Cancelled'

#menu names
main-menu: '&1Armor Stand GUI'
create-menu: '&aCreate an Armor Stand'
confirm-menu: '&aConfirm Option'
armor-menu: '&bChoose some Armor'
name: ArmorStandGUI
version: ${project.version}
main: me.illuminatiproductions.armorstandgui.ArmorStandGUI
api-version: 1.13
authors: [Illuminatiiiiii]
description: Create armor stands with a GUI
website: https://youtube.com/c/IlluminatiProductions
commands:
  armorstand:
    description: Create a armor stand
    usage: /<command>
    aliases:
      - as