Creating GUI's

Discussion in 'Plugin Development' started by ReflectionCraft, Jun 1, 2017.

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

    ReflectionCraft

    I'm trying to become educated in creating GUI's with Bukkit API! I'm already aware how to create the GUI's and items inside of them, I just have a couple of questions about it! Also, I have linked a basic plugin I made along with a YT tutorial)

    1. How do you make it so you are not able to take the items out of the GUI? Tutorial links, please!
    2. How do you make it so a command happens when you click an item in the GUI?
    3. How to link economy to the GUI?

    Now some questions about the code!

    Code:
    package me.lapissky;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    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;
    
    public class FreeDirt extends JavaPlugin{
    
       
        //Makes it so when you type /dirt it open the inventory
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("dirt") && sender instanceof Player)
            {
           
               
                //Creates the inventory
                Player player = (Player) sender;
            Inventory gui = Bukkit.createInventory(null, 9,ChatColor.RED + "FREE DIRT" );
       
    
            //This is where you create the item
            ItemStack survival = new ItemStack (Material.DIRT);
            ItemMeta survivalMeta = survival.getItemMeta();
           
           
            //This is where you set the display name of the item
            survival.setItemMeta(survivalMeta);
           
            //This is where you decide what slot the item goes into
            gui.setItem(0, survival);
            gui.setItem(1, survival);
            gui.setItem(2, survival);
            gui.setItem(3, survival);
            gui.setItem(4, survival);
            gui.setItem(5, survival);
            gui.setItem(6, survival);
            gui.setItem(6, survival);
            gui.setItem(7, survival);
            gui.setItem(8, survival);
           
            //This opens the inventory
            player.openInventory(gui);
       
            }
           
           
           
           
           
            return true;}}
    
       
        
    1. for 'ItemStack survival', what does the 'survival part mean' Any good tutorials please link as well :)
    when I tried changing survival it said it had to be survival or creative

    2. Can I change Can I have multiple items with 'ItemStack survival'

    Thanks! If you have any good tutorials on YouTube about creating GUIS with Bukkit API (I use Eclipse to code) Please link em in the comments! Thanks so much!
     
  2. Offline

    Zombie_Striker

    @ReflectionCraft
    1. On InventryClickEvent, if the inventory is the GUI, cancel the event.
    2. On InventoryclickEvent. If it is the GUI, and the clicked item is equal to the one that executes the command, use Bukkit.dispatchCommand(-Who sent it, or the console- , "The command");
    3. How do you want it to be linked? If you want items in the inventory to be different (different blocks/ different lore), then create a new GUI instance of every player and set the block/lore to what you want depending on their economy 'status'.
    4. I do not fully understand what #4 (or, as it is listed, #1) is supposed to mean. Are you asking what the itemstack is supposed to do?
    5. Yes, you can have multiple slots with the same item. All that means is that there will be two slots that look identical and that do exactly the same thing.
     
  3. Offline

    ReflectionCraft

    Thanks this is really helpful could you link some YouTube Tutorials
     
  4. Offline

    Horsey

  5. Offline

    ReflectionCraft

Thread Status:
Not open for further replies.

Share This Page