package com.elmakers.mine.bukkit.wand;

import org.bukkit.configuration.ConfigurationSection;

import com.elmakers.mine.bukkit.api.magic.Mage;

public class WandUpgradeSlot {
    private final String slotType;
    private boolean hidden = false;
    private boolean swappable = false;
    private Wand slotted;

    public WandUpgradeSlot(String slotType) {
        this.slotType = slotType;
    }

    public WandUpgradeSlot(String configKey, ConfigurationSection config) {
        slotType = config.getString("type", configKey);
        hidden = config.getBoolean("hidden", false);
        swappable = config.getBoolean("swappable", false);
    }

    public Wand getSlotted() {
        return slotted;
    }

    public boolean addSlotted(Wand upgrade, Mage mage) {
        String slotType = upgrade.getSlot();
        if (slotType == null || slotType.isEmpty()) {
            return false;
        }
        if (!slotType.equals(slotType)) {
            return false;
        }
        if (slotted == null) {
            slotted = upgrade;
            return true;
        }
        if (!swappable || mage == null) {
            return false;
        }
        mage.giveItem(slotted.getItem());
        slotted = upgrade;
        return true;
    }

    public boolean isHidden() {
        return hidden;
    }

    public String getType() {
        return slotType;
    }
}

@@ -270,32 +270,73 @@
 ppable = false;%0A
+    private boolean replaceable = false;%0A
     private Wand
@@ -345,16 +345,16 @@
 lotted;%0A
-
 %0A    pub
@@ -673,24 +673,87 @@
 e%22, false);%0A
+        replaceable = config.getBoolean(%22replaceable%22, false);%0A
     %7D%0A%0A    p
@@ -1071,32 +1071,32 @@
 alse;%0A        %7D%0A
-
         if (slot
@@ -1098,32 +1098,47 @@
 (slotted == null
+ %7C%7C replaceable
 ) %7B%0A            

Add replaceable slot tag, for upgrades that can be replaced without returning the existing upgrade