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;
           
            @SuppressWarnings("deprecation")
            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.setDisplayName(name);
                im.setLore(Arrays.asList("Give yourself",  name.toLowerCase()));
                i.setItemMeta(im);
                return i;
            }
    It shows up as:
    [​IMG]
     
  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.setDisplayName("example");
    meta.setLore(Arrays.asList("line 1", "line2"));

    itemStack.setItemMeta(meta);
     
    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 2
  3. Thanks, works great!!!
     
    • Funny Funny x 1

Share This Page