Search in sources :

Example 11 with Messages

use of com.elmakers.mine.bukkit.api.magic.Messages in project MagicPlugin by elBukkit.

the class Wand method add.

public boolean add(Wand other, com.elmakers.mine.bukkit.api.magic.Mage mage) {
    if (!isModifiable()) {
        // and only if the paths match.
        if (!other.isUpgrade() || other.path == null || path == null || other.path.isEmpty() || path.isEmpty() || !other.path.equals(path)) {
            return false;
        }
    }
    // Can't combine limited-use wands
    if (hasUses || other.hasUses) {
        return false;
    }
    if (isHeroes || other.isHeroes) {
        return false;
    }
    ConfigurationSection templateConfig = controller.getWandTemplateConfiguration(other.getTemplateKey());
    // Check for forced upgrades
    if (other.isForcedUpgrade()) {
        if (templateConfig == null) {
            return false;
        }
        templateConfig = ConfigurationUtils.cloneConfiguration(templateConfig);
        templateConfig.set("name", templateConfig.getString("upgrade_name"));
        templateConfig.set("description", templateConfig.getString("upgrade_description"));
        templateConfig.set("force", null);
        templateConfig.set("upgrade", null);
        templateConfig.set("icon", templateConfig.getString("upgrade_icon"));
        templateConfig.set("indestructible", null);
        templateConfig.set("upgrade_icon", null);
        configure(templateConfig);
        return true;
    }
    // Don't allow upgrades from an item on a different path
    if (other.isUpgrade() && other.path != null && !other.path.isEmpty() && (this.path == null || !this.path.equals(other.path))) {
        return false;
    }
    ConfigurationSection upgradeConfig = ConfigurationUtils.cloneConfiguration(other.getEffectiveConfiguration());
    upgradeConfig.set("id", null);
    upgradeConfig.set("indestructible", null);
    upgradeConfig.set("upgrade", null);
    upgradeConfig.set("icon", other.upgradeIcon == null ? null : other.upgradeIcon.getKey());
    upgradeConfig.set("upgrade_icon", null);
    upgradeConfig.set("template", other.upgradeTemplate);
    Messages messages = controller.getMessages();
    if (other.rename && templateConfig != null) {
        String newName = messages.get("wands." + other.template + ".name");
        newName = templateConfig.getString("name", newName);
        upgradeConfig.set("name", newName);
    } else {
        upgradeConfig.set("name", null);
    }
    if (other.renameDescription && templateConfig != null) {
        String newDescription = messages.get("wands." + other.template + ".description");
        newDescription = templateConfig.getString("description", newDescription);
        upgradeConfig.set("description", newDescription);
    } else {
        upgradeConfig.set("description", null);
    }
    return upgrade(upgradeConfig);
}
Also used : Messages(com.elmakers.mine.bukkit.api.magic.Messages) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 12 with Messages

use of com.elmakers.mine.bukkit.api.magic.Messages in project MagicPlugin by elBukkit.

the class WandUpgradePath method load.

protected void load(MageController controller, String key, ConfigurationSection template) {
    // Cache spells, mainly used for spellbooks
    Collection<PrerequisiteSpell> pathSpells = ConfigurationUtils.getPrerequisiteSpells(controller, template, "spells", "path " + key, true);
    for (PrerequisiteSpell prereq : pathSpells) {
        spells.add(prereq.getSpellKey().getKey());
    }
    allSpells.addAll(spells);
    Collection<PrerequisiteSpell> pathExtraSpells = ConfigurationUtils.getPrerequisiteSpells(controller, template, "extra_spells", "path " + key, true);
    for (PrerequisiteSpell prereq : pathExtraSpells) {
        extraSpells.add(prereq.getSpellKey().getKey());
    }
    allExtraSpells.addAll(extraSpells);
    // Get brush info
    brushes.addAll(ConfigurationUtils.getKeysOrList(template, "brushes"));
    allBrushes.addAll(brushes);
    // Upgrade information
    followsPath = template.getString("follows");
    upgradeKey = template.getString("upgrade");
    upgradeItemKey = template.getString("upgrade_item");
    Collection<PrerequisiteSpell> prerequisiteSpells = ConfigurationUtils.getPrerequisiteSpells(controller, template, "required_spells", "path " + key, false);
    this.requiredSpells = new ArrayList<>(pathSpells.size() + prerequisiteSpells.size());
    requiredSpells.addAll(pathSpells);
    requiredSpells.addAll(prerequisiteSpells);
    requiredSpellKeys = new HashSet<>(prerequisiteSpells.size());
    for (PrerequisiteSpell prereq : prerequisiteSpells) {
        requiredSpellKeys.add(prereq.getSpellKey().getKey());
        allRequiredSpells.add(prereq.getSpellKey().getKey());
    }
    // Icon information for upgrading/migrating wands
    icon = ConfigurationUtils.getMaterialAndData(template, "icon");
    migrateIcon = ConfigurationUtils.getMaterialAndData(template, "migrate_icon");
    // Validate requirements - disabling a required spell disables the upgrade.
    for (PrerequisiteSpell requiredSpell : requiredSpells) {
        SpellTemplate spell = controller.getSpellTemplate(requiredSpell.getSpellKey().getKey());
        if (spell == null) {
            controller.getLogger().warning("Invalid spell required for upgrade: " + requiredSpell.getSpellKey().getKey() + ", upgrade path " + key + " will disable upgrades");
            upgradeKey = null;
        }
    }
    matchSpellMana = template.getBoolean("match_spell_mana", matchSpellMana);
    hidden = template.getBoolean("hidden", false);
    earnsSP = template.getBoolean("earns_sp", earnsSP);
    // Description information
    Messages messages = controller.getMessages();
    name = template.getString("name", name);
    name = messages.get("paths." + key + ".name", name);
    description = template.getString("description", description);
    description = messages.get("paths." + key + ".description", description);
    // Upgrade commands
    upgradeCommands = template.getStringList("upgrade_commands");
    // Effects
    if (template.contains("effects")) {
        effects.clear();
        ConfigurationSection effectsNode = template.getConfigurationSection("effects");
        Collection<String> effectKeys = effectsNode.getKeys(false);
        for (String effectKey : effectKeys) {
            if (effectsNode.isString(effectKey)) {
                String referenceKey = effectsNode.getString(effectKey);
                if (effects.containsKey(referenceKey)) {
                    effects.put(effectKey, new ArrayList<>(effects.get(referenceKey)));
                }
            } else {
                effects.put(effectKey, EffectPlayer.loadEffects(controller.getPlugin(), effectsNode, effectKey));
            }
        }
    }
    // Fetch overall limits
    maxUses = template.getInt("max_uses", maxUses);
    maxMaxMana = template.getInt("max_mana", maxMaxMana);
    maxManaRegeneration = template.getInt("max_mana_regeneration", maxManaRegeneration);
    maxMana = template.getInt("mana_max", maxMana);
    manaRegeneration = template.getInt("mana_regeneration", manaRegeneration);
    minLevel = template.getInt("min_enchant_level", minLevel);
    maxLevel = template.getInt("max_enchant_level", maxLevel);
    ConfigurationSection maxConfig = template.getConfigurationSection("max_properties");
    if (maxConfig != null) {
        for (String maxKey : maxConfig.getKeys(false)) {
            double value = maxConfig.getDouble(maxKey);
            maxProperties.put(maxKey.replace("|", "."), value);
        }
    }
    Collection<String> tagList = ConfigurationUtils.getStringList(template, "tags");
    if (tagList != null && !tagList.isEmpty()) {
        if (tags == null) {
            tags = new HashSet<>(tagList);
        } else {
            tags.addAll(tagList);
        }
    }
    // Parse defined levels
    if (levelMap == null) {
        levelMap = new TreeMap<>();
    }
    if (template.contains("levels")) {
        String[] levelStrings = StringUtils.split(template.getString("levels"), ',');
        levels = new int[levelStrings.length];
        for (int i = 0; i < levels.length; i++) {
            levels[i] = Integer.parseInt(levelStrings[i]);
        }
    }
    if (levels == null) {
        levels = new int[1];
        levels[0] = 1;
    }
    for (int level = 1; level <= levels[levels.length - 1]; level++) {
        // TODO: Could this be optimized?
        int levelIndex;
        int nextLevelIndex = 0;
        float distance = 1;
        for (levelIndex = 0; levelIndex < levels.length; levelIndex++) {
            if (level == levels[levelIndex] || levelIndex == levels.length - 1) {
                nextLevelIndex = levelIndex;
                distance = 0;
                break;
            }
            if (level < levels[levelIndex + 1]) {
                nextLevelIndex = levelIndex + 1;
                int previousLevel = levels[levelIndex];
                int nextLevel = levels[nextLevelIndex];
                distance = (float) (level - previousLevel) / (float) (nextLevel - previousLevel);
                break;
            }
        }
        WandLevel wandLevel = levelMap.get(level);
        WandLevel newLevel = new WandLevel(this, controller, template, levelIndex, nextLevelIndex, distance);
        if (wandLevel == null) {
            wandLevel = newLevel;
        } else {
            newLevel.add(wandLevel);
            wandLevel = newLevel;
        }
        levelMap.put(level, wandLevel);
    }
}
Also used : Messages(com.elmakers.mine.bukkit.api.magic.Messages) PrerequisiteSpell(com.elmakers.mine.bukkit.api.spell.PrerequisiteSpell) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 13 with Messages

use of com.elmakers.mine.bukkit.api.magic.Messages in project MagicPlugin by elBukkit.

the class SelectorAction method getBalanceDescription.

protected String getBalanceDescription(CastContext context) {
    Mage mage = context.getMage();
    Player player = mage.getPlayer();
    Messages messages = context.getController().getMessages();
    String description = "";
    switch(defaultConfiguration.getCostType()) {
        case "xp":
            String xpAmount = Integer.toString(mage.getExperience());
            description = messages.get("costs.xp_amount").replace("$amount", xpAmount);
            break;
        case "sp":
            String spAmount = Integer.toString(mage.getSkillPoints());
            description = messages.get("costs.sp_amount").replace("$amount", spAmount);
            break;
        case "levels":
            int levels = player == null ? 0 : player.getLevel();
            String levelAmount = Integer.toString(levels);
            description = messages.get("costs.levels_amount").replace("$amount", levelAmount);
            break;
        default:
            if (VaultController.hasEconomy()) {
                double balance = VaultController.getInstance().getBalance(player);
                description = VaultController.getInstance().format(balance);
            }
    }
    return description;
}
Also used : Player(org.bukkit.entity.Player) Messages(com.elmakers.mine.bukkit.api.magic.Messages) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 14 with Messages

use of com.elmakers.mine.bukkit.api.magic.Messages in project MagicPlugin by elBukkit.

the class SkillSelectorAction method perform.

@Override
public SpellResult perform(CastContext context) {
    this.context = context;
    MageController apiController = context.getController();
    Player player = context.getMage().getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    if (!(apiController instanceof MagicController))
        return SpellResult.FAIL;
    MagicController controller = (MagicController) apiController;
    Messages messages = controller.getMessages();
    HeroesManager heroes = controller.getHeroes();
    allSkills.clear();
    if (controller.useHeroesSkills() && heroes != null) {
        @Nonnull String classString = heroes.getClassName(player);
        @Nonnull String class2String = heroes.getSecondaryClassName(player);
        String messageKey = !class2String.isEmpty() ? "skills.inventory_title_secondary" : "skills.inventory_title";
        inventoryTitle = controller.getMessages().get(messageKey, "Skills ($page/$pages)");
        inventoryTitle = inventoryTitle.replace("$class2", class2String).replace("$class", classString);
        List<String> heroesSkills = heroes.getSkillList(player, true, true);
        for (String heroesSkill : heroesSkills) {
            allSkills.add(new SkillDescription(heroes, controller, player, heroesSkill));
        }
    } else {
        inventoryTitle = messages.get("skills.inventory_title");
    }
    if (controller.usePermissionSkills()) {
        boolean bypassHidden = player.hasPermission("Magic.bypass_hidden");
        Collection<SpellTemplate> spells = controller.getSpellTemplates(bypassHidden);
        for (SpellTemplate spell : spells) {
            SpellKey key = spell.getSpellKey();
            if (key.isVariant())
                continue;
            if (key.getBaseKey().startsWith("heroes*"))
                continue;
            if (!spell.hasCastPermission(player))
                continue;
            allSkills.add(new SkillDescription(spell));
        }
    } else {
        Mage mage = controller.getMage(player);
        MageClass activeClass = mage.getActiveClass();
        if (activeClass != null) {
            // gather spells in player's inventory to avoid showing
            Set<String> hasSpells = new HashSet<>();
            for (ItemStack item : player.getInventory().getContents()) {
                String spellKey = controller.getSpell(item);
                if (spellKey != null) {
                    hasSpells.add(spellKey);
                }
            }
            classKey = activeClass.getKey();
            skillsConfig = activeClass.getProperty("skills", ConfigurationSection.class);
            inventoryLimit = activeClass.getProperty("skills.skill_limit", 0);
            Collection<String> spells = activeClass.getSpells();
            for (String spellKey : spells) {
                if (hasSpells.contains(spellKey)) {
                    extraSlots++;
                    continue;
                }
                SpellTemplate spell = controller.getSpellTemplate(spellKey);
                if (spell != null) {
                    allSkills.add(new SkillDescription(spell));
                }
            }
        }
    }
    if (allSkills.size() == 0) {
        player.sendMessage(messages.get("skills.none"));
        return SpellResult.NO_ACTION;
    }
    Collections.sort(allSkills);
    openInventory();
    return SpellResult.CAST;
}
Also used : Player(org.bukkit.entity.Player) Messages(com.elmakers.mine.bukkit.api.magic.Messages) MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Nonnull(javax.annotation.Nonnull) HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MagicController(com.elmakers.mine.bukkit.magic.MagicController) ItemStack(org.bukkit.inventory.ItemStack) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) HashSet(java.util.HashSet) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 15 with Messages

use of com.elmakers.mine.bukkit.api.magic.Messages in project MagicPlugin by elBukkit.

the class MaterialBrush method getItem.

@Nullable
public ItemStack getItem(MageController controller, boolean isItem) {
    Messages messages = controller.getMessages();
    MaterialAndData icon = new MaterialAndData(this.getMaterial(), this.getData());
    String extraLore = null;
    String customName = getName(messages);
    ItemStack itemStack = null;
    if (mode == BrushMode.ERASE) {
        icon = MaterialBrush.EraseMaterial;
        if (EraseCustomIcon != null && !EraseCustomIcon.isEmpty() && controller.isUrlIconsEnabled()) {
            itemStack = InventoryUtils.getURLSkull(EraseCustomIcon);
        }
        extraLore = messages.get("wand.erase_material_description");
    } else if (mode == BrushMode.COPY) {
        icon = MaterialBrush.CopyMaterial;
        if (CopyCustomIcon != null && !CopyCustomIcon.isEmpty() && controller.isUrlIconsEnabled()) {
            itemStack = InventoryUtils.getURLSkull(CopyCustomIcon);
        }
        extraLore = messages.get("wand.copy_material_description");
    } else if (mode == BrushMode.CLONE) {
        icon = MaterialBrush.CloneMaterial;
        if (CloneCustomIcon != null && !CloneCustomIcon.isEmpty() && controller.isUrlIconsEnabled()) {
            itemStack = InventoryUtils.getURLSkull(CloneCustomIcon);
        }
        extraLore = messages.get("wand.clone_material_description");
    } else if (mode == BrushMode.REPLICATE) {
        icon = MaterialBrush.ReplicateMaterial;
        if (ReplicateCustomIcon != null && !ReplicateCustomIcon.isEmpty() && controller.isUrlIconsEnabled()) {
            itemStack = InventoryUtils.getURLSkull(ReplicateCustomIcon);
        }
        extraLore = messages.get("wand.replicate_material_description");
    } else if (mode == BrushMode.MAP) {
        icon = MaterialBrush.MapMaterial;
        if (MapCustomIcon != null && !MapCustomIcon.isEmpty() && controller.isUrlIconsEnabled()) {
            itemStack = InventoryUtils.getURLSkull(MapCustomIcon);
        }
        extraLore = messages.get("wand.map_material_description");
    } else if (mode == BrushMode.SCHEMATIC) {
        icon = MaterialBrush.SchematicMaterial;
        if (SchematicCustomIcon != null && !SchematicCustomIcon.isEmpty() && controller.isUrlIconsEnabled()) {
            itemStack = InventoryUtils.getURLSkull(SchematicCustomIcon);
        }
        extraLore = messages.get("wand.schematic_material_description").replace("$schematic", schematicName);
    } else {
        MaterialAndData replacementMaterial = replacements.get(icon);
        if (replacementMaterial != null) {
            icon = replacementMaterial;
        }
        extraLore = messages.get("wand.building_material_description").replace("$material", customName);
    }
    if (itemStack == null) {
        itemStack = icon.getItemStack(1);
        itemStack = InventoryUtils.makeReal(itemStack);
        if (itemStack == null) {
            if (DefaultBrushCustomIcon != null && !DefaultBrushCustomIcon.isEmpty() && controller.isUrlIconsEnabled()) {
                itemStack = InventoryUtils.getURLSkull(DefaultBrushCustomIcon);
            }
            if (itemStack == null) {
                itemStack = DefaultBrushMaterial.getItemStack(1);
                itemStack = InventoryUtils.makeReal(itemStack);
                if (itemStack == null) {
                    return itemStack;
                }
            }
        }
    }
    ItemMeta meta = itemStack.getItemMeta();
    if (meta == null)
        return null;
    List<String> lore = new ArrayList<>();
    if (extraLore != null) {
        lore.add(ChatColor.LIGHT_PURPLE + extraLore);
    }
    if (isItem) {
        ConfigurationUtils.addIfNotEmpty(messages.get("wand.brush_item_description"), lore);
    }
    meta.setLore(lore);
    if (customName != null) {
        meta.setDisplayName(customName);
    }
    itemStack.setItemMeta(meta);
    return itemStack;
}
Also used : Messages(com.elmakers.mine.bukkit.api.magic.Messages) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Nullable(javax.annotation.Nullable)

Aggregations

Messages (com.elmakers.mine.bukkit.api.magic.Messages)17 Player (org.bukkit.entity.Player)6 Mage (com.elmakers.mine.bukkit.api.magic.Mage)5 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)5 ItemStack (org.bukkit.inventory.ItemStack)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)4 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 Mage (com.elmakers.mine.bukkit.magic.Mage)3 Wand (com.elmakers.mine.bukkit.wand.Wand)3 ArrayList (java.util.ArrayList)3 EventHandler (org.bukkit.event.EventHandler)3 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)2 Spell (com.elmakers.mine.bukkit.api.spell.Spell)2 Block (org.bukkit.block.Block)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 CastEvent (com.elmakers.mine.bukkit.api.event.CastEvent)1 PreCastEvent (com.elmakers.mine.bukkit.api.event.PreCastEvent)1 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)1 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)1