package com.elmakers.mine.bukkit.magic;

import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nullable;

import org.bukkit.Color;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.elmakers.mine.bukkit.api.magic.MagicPropertyType;
import com.elmakers.mine.bukkit.utility.ColorHD;
import com.elmakers.mine.bukkit.wand.Wand;

public class MageProperties extends CasterProperties {
    private final Mage mage;
    private ColorHD effectColor = null;

    public MageProperties(Mage mage) {
        super(MagicPropertyType.MAGE, mage.getController());
        this.mage = mage;
    }

    @Override
    public void loadProperties() {
        super.loadProperties();

        if (hasProperty("effect_color")) {
            setEffectColor(getString("effect_color"));
        }
    }

    @Override
    public void updated() {
        updateMaxMana(mage);
        Wand activeWand = mage.getActiveWand();
        if (activeWand != null) {
            activeWand.updated();
        }
        mage.updatePassiveEffects();
    }

    public void setEffectColor(String hexColor) {
        // TODO: Move to CasterProperties?
        if (hexColor == null || hexColor.length() == 0 || hexColor.equals("none")) {
            effectColor = null;
            return;
        }
        effectColor = new ColorHD(hexColor);
        if (hexColor.equals("random")) {
            setProperty("effect_color", effectColor.toString());
        }
    }

    @Override
    public void describe(CommandSender sender, @Nullable Set<String> ignoreProperties, @Nullable Set<String> overriddenProperties) {
        MageClass activeClass = mage.getActiveClass();
        if (activeClass != null) {
            if (overriddenProperties == null) {
                overriddenProperties = new HashSet<>();
            }
            overriddenProperties.addAll(activeClass.getEffectiveConfiguration().getKeys(false));
        }

        super.describe(sender, ignoreProperties, overriddenProperties);
    }

    @Override
    public boolean isPlayer() {
        return mage.isPlayer();
    }

    @Nullable
    @Override
    public Player getPlayer() {
        return mage.getPlayer();
    }

    @Override
    public Mage getMage() {
        return mage;
    }

    @Nullable
    public Color getEffectColor() {
       return effectColor == null ? null : effectColor.getColor();
    }

    @Nullable
    @Override
    public BaseMagicConfigurable getStorage(MagicPropertyType propertyType) {
        switch (propertyType) {
            case WAND:
                return mage.getActiveWand();
            case CLASS:
            case SUBCLASS:
                return mage.getActiveClass().getStorage(propertyType);
            case MAGE:
                return this;
            default:
                return null;
        }
    }
}

@@ -458,48 +458,8 @@
 age;
-%0A    private ColorHD effectColor = null;
 %0A%0A  
@@ -593,205 +593,8 @@
  %7D%0A%0A
-    @Override%0A    public void loadProperties() %7B%0A        super.loadProperties();%0A%0A        if (hasProperty(%22effect_color%22)) %7B%0A            setEffectColor(getString(%22effect_color%22));%0A        %7D%0A    %7D%0A%0A
     
@@ -834,416 +834,8 @@
  %7D%0A%0A
-    public void setEffectColor(String hexColor) %7B%0A        // TODO: Move to CasterProperties?%0A        if (hexColor == null %7C%7C hexColor.length() == 0 %7C%7C hexColor.equals(%22none%22)) %7B%0A            effectColor = null;%0A            return;%0A        %7D%0A        effectColor = new ColorHD(hexColor);%0A        if (hexColor.equals(%22random%22)) %7B%0A            setProperty(%22effect_color%22, effectColor.toString());%0A        %7D%0A    %7D%0A%0A
     
@@ -1595,24 +1595,24 @@
 getMage() %7B%0A
+
         retu
@@ -1631,132 +1631,8 @@
  %7D%0A%0A
-    @Nullable%0A    public Color getEffectColor() %7B%0A       return effectColor == null ? null : effectColor.getColor();%0A    %7D%0A%0A
     

Remove extraneous effectColor from MageProperties