Search in sources :

Example 26 with SpellTemplate

use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.

the class MagicController method cast.

public boolean cast(Mage mage, String spellName, ConfigurationSection parameters, CommandSender sender, Entity entity) {
    Player usePermissions = (sender == entity && entity instanceof Player) ? (Player) entity : (sender instanceof Player ? (Player) sender : null);
    if (entity == null && sender instanceof Player) {
        entity = (Player) sender;
    }
    Location targetLocation = null;
    if (mage == null) {
        CommandSender mageController = (entity != null && entity instanceof Player) ? (Player) entity : sender;
        if (sender != null && sender instanceof BlockCommandSender) {
            targetLocation = ((BlockCommandSender) sender).getBlock().getLocation();
        }
        if (entity == null) {
            mage = getMage(mageController);
        } else {
            mage = getMageFromEntity(entity, mageController);
        }
    }
    // This is a bit of a hack to make automata maintain direction
    if (targetLocation != null) {
        Location mageLocation = mage.getLocation();
        if (mageLocation != null) {
            targetLocation.setPitch(mageLocation.getPitch());
            targetLocation.setYaw(mageLocation.getYaw());
        }
    }
    SpellTemplate template = getSpellTemplate(spellName);
    if (template == null || !template.hasCastPermission(usePermissions)) {
        if (sender != null) {
            sender.sendMessage("Spell " + spellName + " unknown");
        }
        return false;
    }
    com.elmakers.mine.bukkit.api.spell.Spell spell = mage.getSpell(spellName);
    if (spell == null) {
        if (sender != null) {
            sender.sendMessage("Spell " + spellName + " unknown");
        }
        return false;
    }
    // TODO: Load configured list of parameters!
    // Make it free and skip cooldowns, if configured to do so.
    toggleCastCommandOverrides(mage, sender, true);
    boolean success = false;
    try {
        success = spell.cast(parameters, targetLocation);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    toggleCastCommandOverrides(mage, sender, false);
    return success;
}
Also used : EffectPlayer(com.elmakers.mine.bukkit.effect.EffectPlayer) Player(org.bukkit.entity.Player) CommandSender(org.bukkit.command.CommandSender) BlockCommandSender(org.bukkit.command.BlockCommandSender) Spell(com.elmakers.mine.bukkit.api.spell.Spell) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) ParseException(java.text.ParseException) Location(org.bukkit.Location) CastSourceLocation(com.elmakers.mine.bukkit.api.magic.CastSourceLocation) BlockCommandSender(org.bukkit.command.BlockCommandSender) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 27 with SpellTemplate

use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.

the class MagicController method removeItemFromWand.

@Nullable
public ItemStack removeItemFromWand(Wand wand, ItemStack droppedItem) {
    if (wand == null || droppedItem == null || Wand.isWand(droppedItem)) {
        return null;
    }
    if (Wand.isSpell(droppedItem)) {
        String spellKey = Wand.getSpell(droppedItem);
        wand.removeSpell(spellKey);
        // Update the item for proper naming and lore
        SpellTemplate spell = getSpellTemplate(spellKey);
        if (spell != null) {
            Wand.updateSpellItem(messages, droppedItem, spell, "", null, null, true);
        }
    } else if (Wand.isBrush(droppedItem)) {
        String brushKey = Wand.getBrush(droppedItem);
        wand.removeBrush(brushKey);
        // Update the item for proper naming and lore
        Wand.updateBrushItem(getMessages(), droppedItem, brushKey, null);
    }
    return droppedItem;
}
Also used : SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) Nullable(javax.annotation.Nullable)

Example 28 with SpellTemplate

use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.

the class MagicController method activateMetrics.

protected void activateMetrics() {
    // Activate Metrics
    final MagicController controller = this;
    metrics = null;
    if (metricsLevel > 0) {
        try {
            metrics = new Metrics(plugin);
            if (metricsLevel > 1) {
                metrics.addCustomChart(new Metrics.MultiLineChart("Plugin Integration") {

                    @Override
                    public HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap) {
                        valueMap.put("Essentials", controller.hasEssentials ? 1 : 0);
                        valueMap.put("Dynmap", controller.hasDynmap ? 1 : 0);
                        valueMap.put("Factions", controller.factionsManager.isEnabled() ? 1 : 0);
                        valueMap.put("WorldGuard", controller.worldGuardManager.isEnabled() ? 1 : 0);
                        valueMap.put("Elementals", controller.elementalsEnabled() ? 1 : 0);
                        valueMap.put("Citizens", controller.citizens != null ? 1 : 0);
                        valueMap.put("CommandBook", controller.hasCommandBook ? 1 : 0);
                        valueMap.put("PvpManager", controller.pvpManager.isEnabled() ? 1 : 0);
                        valueMap.put("Multiverse-Core", controller.multiverseManager.isEnabled() ? 1 : 0);
                        valueMap.put("Towny", controller.townyManager.isEnabled() ? 1 : 0);
                        valueMap.put("GriefPrevention", controller.griefPreventionManager.isEnabled() ? 1 : 0);
                        valueMap.put("PreciousStones", controller.preciousStonesManager.isEnabled() ? 1 : 0);
                        valueMap.put("Lockette", controller.locketteManager.isEnabled() ? 1 : 0);
                        valueMap.put("NoCheatPlus", controller.ncpManager.isEnabled() ? 1 : 0);
                        return valueMap;
                    }
                });
                metrics.addCustomChart(new Metrics.MultiLineChart("Features Enabled") {

                    @Override
                    public HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap) {
                        valueMap.put("Crafting", controller.crafting.isEnabled() ? 1 : 0);
                        valueMap.put("Enchanting", controller.enchanting.isEnabled() ? 1 : 0);
                        valueMap.put("SP", controller.isSPEnabled() ? 1 : 0);
                        return valueMap;
                    }
                });
            }
            if (metricsLevel > 2) {
                metrics.addCustomChart(new Metrics.MultiLineChart("Total Casts by Category") {

                    @Override
                    public HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap) {
                        for (final SpellCategory category : categories.values()) {
                            valueMap.put(category.getName(), (int) category.getCastCount());
                        }
                        return valueMap;
                    }
                });
            }
            if (metricsLevel > 3) {
                metrics.addCustomChart(new Metrics.MultiLineChart("Total Casts") {

                    @Override
                    public HashMap<String, Integer> getValues(HashMap<String, Integer> valueMap) {
                        for (final SpellTemplate spell : spells.values()) {
                            if (!(spell instanceof Spell))
                                continue;
                            valueMap.put(spell.getName(), (int) ((Spell) spell).getCastCount());
                        }
                        return valueMap;
                    }
                });
            }
            plugin.getLogger().info("Activated BStats");
        } catch (Exception ex) {
            plugin.getLogger().warning("Failed to load BStats: " + ex.getMessage());
        }
    }
}
Also used : Metrics(org.bstats.Metrics) SpellCategory(com.elmakers.mine.bukkit.spell.SpellCategory) HashMap(java.util.HashMap) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) ParseException(java.text.ParseException) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 29 with SpellTemplate

use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.

the class MagicConfigurableExecutor method onLevelSpells.

protected boolean onLevelSpells(String command, CommandSender sender, Player player, CasterProperties caster, Integer maxLevel) {
    Collection<String> spells = caster.getSpells();
    MageController controller = api.getController();
    int levelledCount = 0;
    for (String spellKey : spells) {
        SpellTemplate spellTemplate = controller.getSpellTemplate(spellKey);
        if (spellTemplate == null)
            continue;
        SpellKey key = spellTemplate.getSpellKey();
        int currentLevel = key.getLevel();
        if (maxLevel != null && currentLevel >= maxLevel)
            continue;
        int targetLevel = key.getLevel();
        while (spellTemplate != null && (maxLevel == null || targetLevel < maxLevel)) {
            key = new SpellKey(key.getBaseKey(), targetLevel + 1);
            spellTemplate = controller.getSpellTemplate(key.getKey());
            if (spellTemplate != null) {
                targetLevel++;
            }
        }
        if (currentLevel >= targetLevel)
            continue;
        key = new SpellKey(key.getBaseKey(), targetLevel);
        caster.addSpell(key.getKey());
        levelledCount++;
    }
    if (sender != player) {
        if (levelledCount > 0) {
            sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
        } else {
            sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_not_levelled", "$name", player.getName()));
        }
    } else {
        if (levelledCount > 0) {
            sender.sendMessage(api.getMessages().getParameterized(command + ".spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
        } else {
            sender.sendMessage(api.getMessages().getParameterized(command + ".spells_not_levelled", "$name", player.getName()));
        }
    }
    return true;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 30 with SpellTemplate

use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.

the class MagicGiveCommandExecutor method onTabComplete.

@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
    Set<String> options = new HashSet<>();
    if (!sender.hasPermission("Magic.commands.mgive"))
        return options;
    if (args.length == 1 && sender.hasPermission("Magic.commands.mgive.others")) {
        options.addAll(api.getPlayerNames());
    }
    if (args.length == 1 || args.length == 2) {
        Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
        for (SpellTemplate spell : spellList) {
            addIfPermissible(sender, options, "Magic.create.", spell.getKey());
        }
        Collection<String> allWands = api.getWandKeys();
        for (String wandKey : allWands) {
            addIfPermissible(sender, options, "Magic.create.", wandKey);
        }
        for (Material material : Material.values()) {
            addIfPermissible(sender, options, "Magic.create.", material.name().toLowerCase());
        }
        Collection<String> allItems = api.getController().getItemKeys();
        for (String itemKey : allItems) {
            addIfPermissible(sender, options, "Magic.create.", itemKey);
        }
        addIfPermissible(sender, options, "Magic.create.", "xp");
        addIfPermissible(sender, options, "Magic.create.", "sp");
    }
    return options;
}
Also used : Material(org.bukkit.Material) HashSet(java.util.HashSet) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Aggregations

SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)48 ArrayList (java.util.ArrayList)16 Mage (com.elmakers.mine.bukkit.api.magic.Mage)14 Spell (com.elmakers.mine.bukkit.api.spell.Spell)10 SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)9 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)8 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)8 ItemStack (org.bukkit.inventory.ItemStack)8 Wand (com.elmakers.mine.bukkit.api.wand.Wand)7 Player (org.bukkit.entity.Player)7 MageController (com.elmakers.mine.bukkit.api.magic.MageController)5 Messages (com.elmakers.mine.bukkit.api.magic.Messages)5 SpellCategory (com.elmakers.mine.bukkit.api.spell.SpellCategory)5 BaseSpell (com.elmakers.mine.bukkit.spell.BaseSpell)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Nullable (javax.annotation.Nullable)5 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)4 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)3 ProgressionPath (com.elmakers.mine.bukkit.api.magic.ProgressionPath)3