Filled GUI

Discussion in 'Spigot Plugin Development' started by Exodus54, Mar 8, 2018.

  1. Hello, so I am currently trying to make a help gui that is filled with stained glass pane data, 7 (Gray Stained Glass Pane)
    Here is my Current Code.
    Please fix it.
    Code (Text):
    package animated.chubbyduck1;

    import java.util.ArrayList;
    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.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin implements Listener
    {
      public void onEnable()
      {
        getLogger().info(ChatColor.translateAlternateColorCodes('&', "&e&l[!] &6HelpGUI &ehas been Enabled!"));
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
      }
     
      public void onDisable()
      {
        getLogger().info(ChatColor.translateAlternateColorCodes('&', "&e&l[!] &6HelpGUI has been Disabled!"));
      }
     
      public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
      {
        Player player = (Player)sender;
        if (command.getName().equalsIgnoreCase("help")) {
          createMenu(player);
        }
        return false;
      }
     
      @EventHandler
      public void onInventoryClick(InventoryClickEvent event)
      {
          for(int slot = 0; slot < event.getInventory().getSize(); slot++) {
                if(event.getInventory().getItem(slot) == null) {
                    event.getInventory().addItem(slot, Material.ANVIL);
                }
            }
        Player player = (Player)event.getWhoClicked();
        if (event.getInventory().getTitle().equals(ChatColor.translateAlternateColorCodes('&', "&8&lHelp Menu")))
        {
          event.setCancelled(true);
          if (event.getRawSlot() == 10)
          {
            event.setCancelled(true);
            player.performCommand("enchanter");
          }
        }
      }
     
      public void createMenu(Player player)
      {
        Inventory inv = Bukkit.getServer().createInventory(null, 27, ChatColor.translateAlternateColorCodes('&',"&8&lHelp Menu"));
       
        ItemStack item1 = new ItemStack(Material.BOOK, 1, (short)0);
        ItemMeta item1Meta = item1.getItemMeta();
        ArrayList<String> item1Lore = new ArrayList();
        item1Lore.add(ChatColor.translateAlternateColorCodes('&', "&7Purchase this to receive a" + "&7Divine Enchantment Book" + "" + "&6&l* &e&LCOST: &715000 Experience"));
        item1Meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&d&lDivine Custom Enchantment"));
        item1Meta.setLore(item1Lore);
        item1.setItemMeta(item1Meta);
        player.performCommand("enchanter");
       
        ItemStack border = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)15);
        ItemMeta borderMeta = border.getItemMeta();
        borderMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&b&l(!) &bYou currently have &3" + player.getTotalExperience() + " &bExp."));
        border.setItemMeta(borderMeta);
       
        inv.setItem(10, item1);
        inv.setItem(0, border);
        inv.setItem(1, border);
        inv.setItem(2, border);
        inv.setItem(3, border);
        inv.setItem(4, border);
        inv.setItem(5, border);
        inv.setItem(6, border);
        inv.setItem(7, border);
        inv.setItem(8, border);
        inv.setItem(9, border);
        inv.setItem(11, border);
        inv.setItem(12, border);
        inv.setItem(13, border);
        inv.setItem(14, border);
        inv.setItem(15, border);
        inv.setItem(16, border);
        inv.setItem(17, border);
        inv.setItem(18, border);
        inv.setItem(19, border);
        inv.setItem(20, border);
        inv.setItem(21, border);
        inv.setItem(22, border);
        inv.setItem(23, border);
        inv.setItem(24, border);
        inv.setItem(25, border);
        inv.setItem(26, border);
       
        player.openInventory(inv);
      }
    }
     
    Thanks!
    Sincerely, Exodus54
     
  2. Could you provide some more information what might be wrong / what is not working. Are there stacktraces in the console that you could share with us? This forum isn't really intended for people to share broken code asking someone else to fix it without any clear idea of what might be wrong.
     
  3. So Well, I am trying to make it in Eclipse and I'm getting errors on this
    Code (Text):
          for(int slot = 0; slot < event.getInventory().getSize(); slot++) {
                if(event.getInventory().getItem(slot) == null) {
                    event.getInventory().addItem(slot, Material.ANVIL);
                }
            }
    I am getting a error on "event.getInventory().addItem(slot, Material.ANVIL);"
    to be specific the error is on addItem
     
    • Agree Agree x 1
  4. You need to add an ItemStack, can't add direct materials to an inventory.
     
  5. For loops my friend, for loops.
    Code (Text):
    inv.setItem(10, item1);
        inv.setItem(0, border);
        inv.setItem(1, border);
        inv.setItem(2, border);
        inv.setItem(3, border);
        inv.setItem(4, border);
        inv.setItem(5, border);
        inv.setItem(6, border);
        inv.setItem(7, border);
        inv.setItem(8, border);
        inv.setItem(9, border);
        inv.setItem(11, border);
        inv.setItem(12, border);
        inv.setItem(13, border);
        inv.setItem(14, border);
        inv.setItem(15, border);
        inv.setItem(16, border);
        inv.setItem(17, border);
        inv.setItem(18, border);
        inv.setItem(19, border);
        inv.setItem(20, border);
        inv.setItem(21, border);
        inv.setItem(22, border);
        inv.setItem(23, border);
        inv.setItem(24, border);
        inv.setItem(25, border);
        inv.setItem(26, border);
    For loops my friend, for loops.
     
    • Agree Agree x 1
  6. As said before, Material.ANVIL can’t just be passed as a parameter in the addItem method,

    new ItemStack(Material.ANVIL); will work instead.
     
  7. This line is your problem
    Code (Text):
    event.getInventory().addItem(slot, Material.ANVIL);
    A Material is not an ItemStack. Try using
    Code (Text):
    event.getInventory().addItem(slot, ItemStack);
    EDIT: I just saw someone else said this too.
     

Share This Page