Solved Setting Item Meta: Stained Glass Pane ItemStack.

Discussion in 'Spigot Plugin Development' started by Surprisejedi, May 25, 2017.

  1. When trying to set the Lore/Display Name It just DOESN'T work. Nothing gets it work, none of the Item Meta shows up, its just a regular old glass pane. Code:
    Code (Java):
    private Inventory inv;
            private ItemStack c, s, a;
            public Effects(Plugin p) {
                    inv = Bukkit.getServer().createInventory(null, 54, "Effect Chooser");
                    c = new ItemStack(Material.STAINED_GLASS_PANE, 1, DyeColor.ORANGE.getDyeData());
                    c.getItemMeta().setDisplayName("Remove Effects");
                    c.getItemMeta().setLore(Arrays.asList("Remove All Current Effects"));
                    s = createItem(Material.IRON_SWORD, ChatColor.RED + "Strength");
                    a = createItem(Material.BLAZE_POWDER, ChatColor.GOLD + "Fire Resistance");            
                    inv.setItem(2, a);
                    inv.setItem(4, s);
                    inv.setItem(49, c);
                    Bukkit.getServer().getPluginManager().registerEvents(this, p);
            private ItemStack createItem(Material material, String name) {
                ItemStack i = new ItemStack(material);
                ItemMeta im = i.getItemMeta();
                im.setLore(Arrays.asList("Give yourself",  name.toLowerCase()));
                return i;
    It shows up as:
  2. you have to define the item meta set it as the item's item meta. additionally, you could use some of those item builder classes that have been created, to easily define an itemstack with the use of the builder pattern.

    Code (Java):

    ItemStack itemStack = new ItemStack(Material.IRON_SWORD);
    ItemMeta meta = itemStack.getItemMeta();

    meta.setLore(Arrays.asList("line 1", "line2"));

    you did it just right with your createItem method. you could modify the current method or create another with an extra parameter for byte/short data value, and use that to create your glass pane.
    • Winner Winner x 3
  3. Thanks, works great!!!
    • Funny Funny x 1