Search in sources :

Example 61 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.

the class MageCommandExecutor method onMageGetData.

public boolean onMageGetData(CommandSender sender, Player player, String[] args) {
    Mage mage = controller.getMage(player);
    ConfigurationSection data = mage.getData();
    if (args != null && args.length > 0) {
        if (args[0].equals("*")) {
            sender.sendMessage(ChatColor.GOLD + "Mage data for " + ChatColor.AQUA + player.getDisplayName() + ChatColor.GOLD + ": ");
            Collection<Spell> spells = mage.getSpells();
            if (spells.size() == 0) {
                sender.sendMessage(ChatColor.RED + "No spell casts!");
                return true;
            }
            for (Spell spell : spells) {
                sender.sendMessage(ChatColor.LIGHT_PURPLE + spell.getName() + ChatColor.AQUA + " Cast Count: " + ChatColor.GOLD + spell.getCastCount());
            }
            return true;
        }
        Spell spell = mage.getSpell(args[0]);
        if (spell != null) {
            sender.sendMessage(ChatColor.GOLD + "Mage data for " + ChatColor.AQUA + player.getDisplayName() + ChatColor.GOLD + ": " + ChatColor.LIGHT_PURPLE + spell.getName());
            sender.sendMessage(ChatColor.AQUA + " Cast Count: " + ChatColor.GOLD + spell.getCastCount());
            return true;
        }
        ConfigurationSection subSection = data.getConfigurationSection(args[0]);
        if (subSection == null) {
            sender.sendMessage(ChatColor.RED + "Unknown subsection or spell: " + args[0]);
            return true;
        }
        data = subSection;
    }
    Collection<String> keys = data.getKeys(false);
    sender.sendMessage(ChatColor.GOLD + "Mage data for " + ChatColor.AQUA + player.getDisplayName());
    for (String key : keys) {
        if (data.isConfigurationSection(key)) {
            ConfigurationSection subSection = data.getConfigurationSection(key);
            sender.sendMessage(ChatColor.AQUA + " " + key + ChatColor.DARK_AQUA + " (" + subSection.getKeys(true).size() + " items)");
        } else {
            String value = data.getString(key);
            if (value != null) {
                sender.sendMessage(ChatColor.AQUA + " " + key + ChatColor.DARK_AQUA + " (" + value + ")");
            } else {
                sender.sendMessage(ChatColor.AQUA + " " + key);
            }
        }
    }
    return true;
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) Spell(com.elmakers.mine.bukkit.api.spell.Spell) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 62 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.

the class HeroesManager method createSkillSpell.

@Nullable
public SpellTemplate createSkillSpell(MagicController controller, String skillName) {
    if (skills == null)
        return null;
    Skill skill = skills.getSkill(skillName);
    if (skill == null)
        return null;
    MageSpell newSpell = new HeroesSkillSpell();
    newSpell.initialize(controller);
    ConfigurationSection config = new MemoryConfiguration();
    String iconURL = SkillConfigManager.getRaw(skill, "icon-url", SkillConfigManager.getRaw(skill, "icon_url", null));
    if (iconURL == null || iconURL.isEmpty()) {
        String icon = SkillConfigManager.getRaw(skill, "icon", null);
        if (icon == null || icon.isEmpty()) {
            config.set("icon", controller.getDefaultSkillIcon());
        } else if (icon.startsWith("http://")) {
            config.set("icon_url", icon);
        } else {
            config.set("icon", icon);
        }
    } else {
        config.set("icon_url", iconURL);
    }
    String iconDisabledURL = SkillConfigManager.getRaw(skill, "icon-disabled-url", SkillConfigManager.getRaw(skill, "icon_disabled_url", null));
    if (iconDisabledURL == null || iconDisabledURL.isEmpty()) {
        String icon = SkillConfigManager.getRaw(skill, "icon-disabled", SkillConfigManager.getRaw(skill, "icon_disabled", null));
        if (icon != null && !icon.isEmpty()) {
            if (icon.startsWith("http://")) {
                config.set("icon_disabled_url", icon);
            } else {
                config.set("icon_disabled", icon);
            }
        }
    } else {
        config.set("icon_disabled_url", iconDisabledURL);
    }
    String nameTemplate = controller.getMessages().get("skills.item_name", "$skill");
    String skillDisplayName = SkillConfigManager.getRaw(skill, "name", skill.getName());
    config.set("name", nameTemplate.replace("$skill", skillDisplayName));
    config.set("category", "skills");
    String descriptionTemplate = controller.getMessages().get("skills.item_description", "$description");
    descriptionTemplate = descriptionTemplate.replace("$description", SkillConfigManager.getRaw(skill, "description", ""));
    config.set("description", descriptionTemplate);
    newSpell.loadTemplate("heroes*" + skillName, config);
    return newSpell;
}
Also used : Skill(com.herocraftonline.heroes.characters.skill.Skill) ActiveSkill(com.herocraftonline.heroes.characters.skill.ActiveSkill) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Nullable(javax.annotation.Nullable)

Example 63 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.

the class HeroesSpellSkill method getDefaultConfig.

@Override
public ConfigurationSection getDefaultConfig() {
    ConfigurationSection node = super.getDefaultConfig();
    // Add in all configured spell parameters
    // Change keys to match heroes-format
    ConfigurationSection spellParameters = spellTemplate.getSpellParameters();
    if (spellParameters != null) {
        Set<String> parameterKeys = spellParameters.getKeys(false);
        for (String parameterKey : parameterKeys) {
            if (!spellParameters.isConfigurationSection(parameterKey) && !spellParameters.isList(parameterKey)) {
                String heroesKey = magicToHeroes(parameterKey);
                Object value = spellParameters.get(parameterKey);
                node.set(heroesKey, value);
                parameters.set(heroesKey, value);
            }
        }
    }
    node.set("icon-url", spellTemplate.getIconURL());
    MaterialAndData icon = spellTemplate.getIcon();
    if (icon != null && icon.getMaterial() != Material.AIR) {
        node.set("icon", icon.getKey());
    }
    MaterialAndData disabledIcon = spellTemplate.getDisabledIcon();
    if (disabledIcon != null && disabledIcon.getMaterial() != Material.AIR) {
        node.set("icon-disabled", disabledIcon.getKey());
    }
    node.set("icon-url", spellTemplate.getIconURL());
    node.set("icon-disabled-url", spellTemplate.getDisabledIconURL());
    node.set("cooldown", spellTemplate.getCooldown());
    node.set("name", spellTemplate.getName());
    Collection<CastingCost> costs = spellTemplate.getCosts();
    if (costs != null) {
        for (CastingCost cost : costs) {
            if (cost.getMana() > 0) {
                node.set(SkillSetting.MANA.node(), cost.getMana());
            }
        // TODO: Reagent costs from item costs
        }
    }
    // Check for an upgrade, set tier if present
    SpellKey upgradeKey = new SpellKey(spellTemplate.getSpellKey().getBaseKey(), 2);
    SpellTemplate upgrade = controller.getSpellTemplate(upgradeKey.getKey());
    if (upgrade != null) {
        int maxUpgrade = 2;
        while (upgrade != null) {
            upgradeKey = new SpellKey(spellTemplate.getSpellKey().getBaseKey(), maxUpgrade + 1);
            upgrade = controller.getSpellTemplate(upgradeKey.getKey());
            if (upgrade != null)
                maxUpgrade++;
        }
        node.set("tier", 1);
        node.set("tier-max", maxUpgrade);
    }
    return node;
}
Also used : CastingCost(com.elmakers.mine.bukkit.api.spell.CastingCost) MaterialAndData(com.elmakers.mine.bukkit.api.block.MaterialAndData) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 64 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.

the class EffectTransform method load.

@Override
public void load(Plugin plugin, ConfigurationSection parameters) {
    super.load(plugin, parameters);
    ConfigurationSection transform = ConfigurationUtils.getConfigurationSection(parameters, "position_transform");
    if (transform != null) {
        positionTransform = new VectorTransform(transform);
    } else {
        positionTransform = null;
    }
    steps = parameters.getInt("steps", 0);
    maxStep = parameters.getInt("max_steps", 0);
}
Also used : VectorTransform(de.slikey.effectlib.math.VectorTransform) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 65 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project MagicPlugin by elBukkit.

the class BaseMagicProperties method describe.

public void describe(CommandSender sender, @Nullable Set<String> ignoreProperties, @Nullable Set<String> overriddenProperties) {
    ConfigurationSection itemConfig = getConfiguration();
    Set<String> keys = itemConfig.getKeys(false);
    for (String key : keys) {
        Object value = itemConfig.get(key);
        if (value != null && (ignoreProperties == null || !ignoreProperties.contains(key))) {
            ChatColor propertyColor = ChatColor.GRAY;
            if (overriddenProperties == null || !overriddenProperties.contains(key)) {
                propertyColor = PROPERTY_KEYS.contains(key) ? ChatColor.DARK_AQUA : ChatColor.DARK_GREEN;
            }
            sender.sendMessage(propertyColor.toString() + key + ChatColor.GRAY + ": " + ChatColor.WHITE + describeProperty(value));
        }
    }
}
Also used : ChatColor(org.bukkit.ChatColor) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ConfigurationSection (org.bukkit.configuration.ConfigurationSection)263 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)29 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)27 ItemStack (org.bukkit.inventory.ItemStack)26 File (java.io.File)22 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)22 IOException (java.io.IOException)21 Map (java.util.Map)18 Mage (com.elmakers.mine.bukkit.api.magic.Mage)17 Material (org.bukkit.Material)16 Nullable (javax.annotation.Nullable)14 Location (org.bukkit.Location)13 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)11 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)10 Player (org.bukkit.entity.Player)10 EntityType (org.bukkit.entity.EntityType)9 List (java.util.List)8 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)7 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)7