Search in sources :

Example 1 with ModifierType

use of com.archyx.aureliumskills.modifier.ModifierType in project AureliumSkills by Archy-X.

the class RequirementManager method load.

public void load() {
    FileConfiguration config = plugin.getConfig();
    this.globalRequirements = new HashSet<>();
    for (ModifierType type : ModifierType.values()) {
        List<String> list = config.getStringList("requirement." + type.name().toLowerCase(Locale.ENGLISH) + ".global");
        for (String text : list) {
            String[] splitText = text.split(" ");
            Optional<XMaterial> potentialMaterial = XMaterial.matchXMaterial(splitText[0].toUpperCase());
            if (potentialMaterial.isPresent()) {
                XMaterial material = potentialMaterial.get();
                Map<Skill, Integer> requirements = new HashMap<>();
                for (int i = 1; i < splitText.length; i++) {
                    String requirementText = splitText[i];
                    try {
                        Skill skill = plugin.getSkillRegistry().getSkill(requirementText.split(":")[0]);
                        if (skill != null) {
                            int level = Integer.parseInt(requirementText.split(":")[1]);
                            requirements.put(skill, level);
                        }
                    } catch (Exception e) {
                        Bukkit.getLogger().warning("[AureliumSkills] Error parsing global skill " + type.name().toLowerCase(Locale.ENGLISH) + " requirement skill level pair with text " + requirementText);
                    }
                }
                GlobalRequirement globalRequirement = new GlobalRequirement(type, material, requirements);
                globalRequirements.add(globalRequirement);
            } else {
                Bukkit.getLogger().warning("[AureliumSkills] Error parsing global skill " + type.name().toLowerCase(Locale.ENGLISH) + " requirement material with text " + splitText[0]);
            }
        }
    }
}
Also used : XMaterial(com.cryptomorin.xseries.XMaterial) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Skill(com.archyx.aureliumskills.skills.Skill) ModifierType(com.archyx.aureliumskills.modifier.ModifierType)

Example 2 with ModifierType

use of com.archyx.aureliumskills.modifier.ModifierType in project AureliumSkills by Archy-X.

the class Requirements method convertFromLegacy.

public ItemStack convertFromLegacy(ItemStack item) {
    if (isNBTDisabled())
        return item;
    NBTItem nbtItem = new NBTItem(item);
    NBTCompound oldRequirementsCompound = nbtItem.getCompound("skillRequirements");
    if (oldRequirementsCompound != null) {
        for (ModifierType type : ModifierType.values()) {
            NBTCompound oldTypeCompound = oldRequirementsCompound.getCompound(type.toString().toLowerCase(Locale.ENGLISH));
            if (oldTypeCompound != null) {
                NBTCompound compound = ItemUtils.getRequirementsTypeCompound(nbtItem, type);
                for (String key : oldTypeCompound.getKeys()) {
                    compound.setInteger(StringUtils.capitalize(key), oldTypeCompound.getInteger(key));
                }
            }
        }
    }
    nbtItem.removeKey("skillRequirements");
    return nbtItem.getItem();
}
Also used : NBTCompound(de.tr7zw.changeme.nbtapi.NBTCompound) ModifierType(com.archyx.aureliumskills.modifier.ModifierType) NBTItem(de.tr7zw.changeme.nbtapi.NBTItem)

Aggregations

ModifierType (com.archyx.aureliumskills.modifier.ModifierType)2 Skill (com.archyx.aureliumskills.skills.Skill)1 XMaterial (com.cryptomorin.xseries.XMaterial)1 NBTCompound (de.tr7zw.changeme.nbtapi.NBTCompound)1 NBTItem (de.tr7zw.changeme.nbtapi.NBTItem)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1