package musician101.minetanks.spigot.tank;

import musician101.minetanks.common.CommonReference.CommonItemText;
import musician101.minetanks.common.tank.AbstractTank;
import musician101.minetanks.common.tank.Armor;
import musician101.minetanks.spigot.SpigotReference;
import musician101.minetanks.spigot.tank.modules.Engine;
import musician101.minetanks.spigot.tank.modules.Radio;
import musician101.minetanks.spigot.tank.modules.cannon.Cannon;
import musician101.minetanks.spigot.tank.modules.tracks.Trackz;
import musician101.minetanks.spigot.tank.modules.turret.Turret;
import musician101.minetanks.spigot.util.MTUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Tank extends AbstractTank
{
    Armor armor;
    Cannon cannon;
    Engine engine;
    Radio radio;
    Trackz tracks;
    Turret turret;

    public Tank(String name, TankType type, int health, Armor armor, int speed, Cannon cannon, Engine engine, Radio radio, Trackz tracks, Turret turret, String... description)
    {
        super(name, type, health, speed, description);
        this.cannon = cannon;
        this.engine = engine;
        this.radio = radio;
        this.tracks = tracks;
        this.turret = turret;
    }

    private ItemStack parseArmorValue(ItemStack item)
    {
        return parseArmorValue(item, armor);
    }

    private ItemStack parseArmorValue(ItemStack item, Armor armor)
    {
        ItemMeta meta = item.getItemMeta();
        meta.addEnchant(Enchantment.DURABILITY, (int) Math.round(armor.getArmorValue()), true);
        item.setItemMeta(meta);
        return item;
    }

    private ItemStack parseSpeedValue(ItemStack item)
    {
        ItemMeta meta = item.getItemMeta();
        meta.setLore(Arrays.asList(meta.getLore().get(0), SpigotReference.number(CommonItemText.SPEED_VALUE, getSpeed())));
        item.setItemMeta(meta);
        return item;
    }

    private Inventory parseWeapons(Cannon cannon)
    {
        Inventory inv = Bukkit.createInventory(null, InventoryType.PLAYER);
        inv.setItem(0, cannon.getItem());
        inv.addItem(new ItemStack(Material.ARROW, cannon.getAmmoCount()));
        return inv;
    }

    public Cannon getCannon()
    {
        return cannon;
    }

    public ItemStack getHelmet()
    {
        return parseArmorValue(turret.getItem(), armor);
    }

    public ItemStack getChestplate()
    {
        return parseArmorValue(radio.getItem());
    }

    public ItemStack getLeggings()
    {
        return parseArmorValue(parseSpeedValue(engine.getItem()));
    }

    public ItemStack getBoots()
    {
        return parseArmorValue(tracks.getItem());
    }

    public List<ItemStack> getWeapons()
    {
        List<ItemStack> items = new ArrayList<>();
        items.add(cannon.getItem());
        ItemStack ammo = MTUtils.createCustomItem(Material.ARROW, CommonItemText.AMMO, "");
        ammo.setAmount(cannon.getAmmoCount());
        items.add(ammo);
        return items;
    }

    public PotionEffect getSpeedEffect()
    {
        int amplifier = 0;
        PotionEffectType effect;
        if (getSpeed() < 6)
        {
            effect = PotionEffectType.SLOW;
            if (getSpeed() == 1)
                amplifier = 5;
            else if (getSpeed() == 2)
                amplifier = 4;
            else if (getSpeed() == 3)
                amplifier = 3;
            else if (getSpeed() == 4)
                amplifier = 2;
            else if (getSpeed() == 5)
                amplifier = 1;
        }
        else
        {
            effect = PotionEffectType.SPEED;
            if (getSpeed() == 6)
                amplifier = 1;
            else if (getSpeed() == 7)
                amplifier = 2;
            else if (getSpeed() == 8)
                amplifier = 3;
            else if (getSpeed() == 9)
                amplifier = 4;
            else if (getSpeed() == 10)
                amplifier = 5;
        }

        return new PotionEffect(effect, amplifier, Integer.MAX_VALUE, false);
    }

    public TankType getType()
    {
        return (TankType) type;
    }
}

@@ -2265,284 +2265,8 @@
  %7D%0A%0A
-    private Inventory parseWeapons(Cannon cannon)%0A    %7B%0A        Inventory inv = Bukkit.createInventory(null, InventoryType.PLAYER);%0A        inv.setItem(0, cannon.getItem());%0A        inv.addItem(new ItemStack(Material.ARROW, cannon.getAmmoCount()));%0A        return inv;%0A    %7D%0A%0A
     

Remove unused method.