package iocia.network.minecraft.plugins.iutilities.item.itembuilder;

import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Responsible for building regular {@linkplain org.bukkit.inventory.ItemStack item stacks} from the
 * build data given.
 */
public class ItemStackBuilder extends ItemMetadataBuilder<ItemStackBuilder> {
    /*---Constructors---*/
    /**
     * Creates a new ItemStackBuilder object. This object is responsible for making basic {@linkplain ItemStack item stacks}.
     * If more advanced creation features are needed, such as creating player skulls, then a more specific build should be used.
     */
    public ItemStackBuilder() {

    }

    /*---Methods---*/
    /**
     * Returns the instance of the derivative class.
     * This is used to allow chaining the builder methods.
     *
     * @return Instance of derivative class.
     */
    @Override
    protected ItemStackBuilder me() {
        return this;
    }

    /**
     * Builds the {@link ItemStack} with the current build properties.
     *
     * @return New {@link ItemStack}.
     */
    @Override
    public ItemStack build() {
        ItemStack item = new ItemStack(material, amount, damage);
        final ItemMeta metadata = item.getItemMeta();
        if (displayName != null)
            metadata.setDisplayName(displayName);
        if (localizedName != null)
            metadata.setLocalizedName(localizedName);
        if (lore != null && !lore.isEmpty()) {
            if (clearLore) {
                metadata.setLore((List<String>) lore);
            } else {
                Collection<String> combinedLore = new ArrayList<>();
                if (metadata.hasLore())
                    combinedLore.addAll(metadata.getLore());
                combinedLore.addAll(lore);
                metadata.setLore((List<String>) combinedLore);
            }
        }
        metadata.setUnbreakable(unbreakable);
        if (itemFlags != null && !itemFlags.isEmpty())
            metadata.addItemFlags(itemFlags.toArray(new ItemFlag[itemFlags.size()]));
        if (enchantments != null && !enchantments.isEmpty()) {
            enchantments.forEach((k, v) -> metadata.addEnchant(k, v.getLevel(), v.isLevelSafe()));
        }
        return item;
    }
}

@@ -241,16 +241,45 @@
 ection;%0A
+import java.util.LinkedList;%0A
 import j
@@ -293,16 +293,16 @@
 l.List;%0A
-
 %0A/**%0A * 
@@ -1415,24 +1415,564 @@
 ItemMeta();%0A
+        fillItemMeta(metadata);%0A        item.setItemMeta(metadata);%0A        return item;%0A    %7D%0A%0A    /**%0A     * Applies all the metadata values to the given %7B@link ItemMeta%7D.%0A     * This method is void meaning the metadata is applied to the passed metadata rather%0A     * than being applied to a new %7B@link ItemMeta%7D and returning it. The given metadata%0A     * must be passed by reference to properly apply the metadata.%0A     * @param metadata %7B@link ItemMeta%7D to apply the data to.%0A     */%0A    private void fillItemMeta(ItemMeta metadata) %7B%0A
         if (
@@ -2204,18 +2204,16 @@
 earLore)
- %7B
 %0A       
@@ -2238,31 +2238,16 @@
 setLore(
-(List%3CString%3E) 
 lore);%0A 
@@ -2256,18 +2256,16 @@
         
- %7D
  else %7B%0A
@@ -2280,26 +2280,20 @@
         
-Collection
+List
 %3CString%3E
@@ -2312,21 +2312,22 @@
 e = new 
-Array
+Linked
 List%3C%3E()
@@ -2509,23 +2509,8 @@
 ore(
-(List%3CString%3E) 
 comb
@@ -2783,34 +2783,32 @@
 ments.isEmpty())
- %7B
 %0A            enc
@@ -2828,17 +2828,16 @@
 Each((k,
- 
 v) -%3E me
@@ -2894,39 +2894,8 @@
 ));%0A
-        %7D%0A        return item;%0A
     

Split the logic for applying the ItemMeta into its own method