How to open a gui when a command is ran

Discussion in 'Plugin Development' started by 360_, Sep 4, 2017.

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

    360_

    So I'm trying to create a gui for staff members that will have the option to vanish or clear the chat etc. This is the code I have so far
    Code:
    package me.Server.devtest.command;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class StaffCommand implements CommandExecutor {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) {
            Player player = (Player) sender;
            if(sender instanceof Player){
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&eOpening the staff GUI"));
            }
            else {
                sender.sendMessage("HEY! Only players can run this");
            }
            return true;
        }
    
    }
    
    Thanks in advance to anyone that helps me
     
  2. Offline

    LRK

    Please search for an own solution first. Look in the bukkit api or search for threads.
    But Anyways here's a small summary:
    Code:
    // Create your inventory : null is the inventoryholder, CHEST is the inventory type and the last parameter is the inventory name
    Inventory inventory = Bukkit.getServer().createInventory(null, InventoryType.CHEST, "YourGUIName");
    
    // Create an item
    ItemStack beacon = new ItemStack(Material.BEACON);
    
    // Add the item to the given inventory slot
    inventory.setItem(0, beacon);
    
    // Then you can open the inventory like this
    p.openInventory(inventory);
    
    Then use the InventoryClickEvent to do something when the player click's an item.
     
Thread Status:
Not open for further replies.

Share This Page