Solved Gui item refuse to glow

Discussion in 'Spigot Plugin Development' started by Lockface77, Nov 22, 2020.

  1. Hello,

    I am trying to get an item glow inside of my gui menu.

    I have found in other posts this method:
    1. Add unsafe enchant to the item
    2. Add the flag hide enchant
    That what I did but the item still does not glow :(

    Here is my code:

    Code (Java):
    ItemStack item = createGuiItem(material, "§a" + name, new String[] {
                                "§aCurrently selected"
    });
    ItemMeta meta = item.getItemMeta();
    item.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 0);
    meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
    meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
    item.setItemMeta(meta);
    ret[i] = item;
    createGuiItem is just a method to simplify the creation of an item with lore and name. Here are the function:

    Code (Java):
    protected static ItemStack createGuiItem(String material, short additional, String name, String[] lore) {
        final ItemStack ret = new ItemStack(Material.getMaterial(material), 1, additional);
        return createGuiItem(ret, name, lore);
    }
         protected static ItemStack createGuiItem(String material, String name, String[] lore) {
            return createGuiItem(material, (short) 0, name, lore);
        }
        protected static ItemStack createGuiItem(ItemStack itemStack, String name, String[] lore) {
            final ItemMeta meta = itemStack.getItemMeta();
            meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
            meta.setDisplayName(name.replace('&', '§'));
            List<String> newLore = new ArrayList<>();
            for (String l : lore) {
                newLore.add("§r" + l.replace('&', '§'));
            }
            meta.setLore(newLore);
            itemStack.setItemMeta(meta);
            return itemStack;
        }
    What happen at the end, is that I have my lore "selected" to the selected item, but this item is not glowing at all.
    I am using these enchants on Material.POTION and on Material.DIAMOND_SWORD

    I hope someone could tell me what is wrong
     
  2. In older threads I've seen the enchants getting added to the ItemMeta, perhaps that works.

    Example of md_5 from this thread

    Code (Java):
        @EventHandler
        public void test(PlayerCommandPreprocessEvent event)
        {
            if ( event.getMessage().equals( "/test" ) )
            {
                ItemStack item = event.getPlayer().getItemInHand();
                addGlow( item );
            }
        }

        public void addGlow(ItemStack stack)
        {
            ItemMeta meta = stack.getItemMeta();
            meta.addEnchant( Enchantment.LURE, 1, false );
            meta.addItemFlags( ItemFlag.HIDE_ENCHANTS );
            stack.setItemMeta( meta );
        }
     
    • Winner Winner x 1
  3. I've had this before, you set an enchantment onto the item and then change the item meta and since that is a new item meta (if the item didn't already have any meta) which does not contain your enchantment when you set it onto the item it overrides the enchantment you have added.

    Change
    Code (Text):
    item.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 0);
    To
    Code (Text):
    meta.addEnchant(Enchantment.ARROW_INFINITE, 0, true);
     
    • Like Like x 1
  4. Thanks, modifying the enchant in Meta worked