Search in sources :

Example 26 with Spell

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

the class MageTrigger method cast.

private void cast(Mage mage, String castSpell) {
    if (castSpell.length() > 0) {
        String[] parameters = null;
        Spell spell = null;
        if (!castSpell.equalsIgnoreCase("none")) {
            if (castSpell.contains(" ")) {
                parameters = StringUtils.split(castSpell, ' ');
                castSpell = parameters[0];
                parameters = Arrays.copyOfRange(parameters, 1, parameters.length);
            }
            spell = mage.getSpell(castSpell);
        }
        if (spell != null) {
            spell.cast(parameters);
        }
    }
}
Also used : Spell(com.elmakers.mine.bukkit.api.spell.Spell)

Example 27 with Spell

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

the class MagicController method loadSpells.

protected void loadSpells(Map<String, ConfigurationSection> spellConfigs) {
    if (spellConfigs == null)
        return;
    // Reset existing spells.
    spells.clear();
    spellAliases.clear();
    categories.clear();
    for (Entry<String, ConfigurationSection> entry : spellConfigs.entrySet()) {
        String key = entry.getKey();
        if (key.equals("default") || key.equals("override"))
            continue;
        ConfigurationSection spellNode = entry.getValue();
        if (spellNode == null) {
            continue;
        }
        Spell newSpell = null;
        try {
            newSpell = loadSpell(key, spellNode, this);
        } catch (Exception ex) {
            newSpell = null;
            ex.printStackTrace();
        }
        if (newSpell == null) {
            getLogger().warning("Magic: Error loading spell " + key);
            continue;
        }
        if (!newSpell.hasIcon()) {
            String icon = spellNode.getString("icon");
            if (icon != null && !icon.isEmpty()) {
                getLogger().info("Couldn't load spell icon '" + icon + "' for spell: " + newSpell.getKey());
            }
        }
        addSpell(newSpell);
    }
    // Second pass to fulfill requirements, which needs all spells loaded
    for (Entry<String, ConfigurationSection> entry : spellConfigs.entrySet()) {
        SpellTemplate template = getSpellTemplate(entry.getKey());
        if (template != null) {
            template.loadPrerequisites(entry.getValue());
        }
    }
    // Update registered mages so their spells are current
    for (Mage mage : mages.values()) {
        if (mage instanceof com.elmakers.mine.bukkit.magic.Mage) {
            ((com.elmakers.mine.bukkit.magic.Mage) mage).loadSpells(spellConfigurations);
        }
    }
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) 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) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 28 with Spell

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

the class EffCast method execute.

@Override
protected void execute(Event event) {
    String spellKey = spell.getSingle(event);
    String parameterString = arguments == null ? null : arguments.getSingle(event);
    String[] parameters = parameterString == null ? null : StringUtils.split(parameterString, ' ');
    if (senders != null) {
        for (final CommandSender sender : senders.getArray(event)) {
            if (sender != null) {
                Spell spell = MagicPlugin.getAPI().getController().getMage(sender).getSpell(spellKey);
                if (spell != null) {
                    spell.cast(parameters);
                }
            }
        }
    } else {
        Spell spell = MagicPlugin.getAPI().getController().getMage(Bukkit.getConsoleSender()).getSpell(spellKey);
        if (spell != null) {
            spell.cast(parameters);
        }
    }
}
Also used : CommandSender(org.bukkit.command.CommandSender) Spell(com.elmakers.mine.bukkit.api.spell.Spell)

Example 29 with Spell

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

the class MageCommandExecutor method onMageDescribe.

public boolean onMageDescribe(CommandSender sender, Player player, String[] parameters) {
    Mage mage = controller.getMage(player);
    MageClass activeClass = mage.getActiveClass();
    MagicProperties mageProperties = mage.getProperties();
    if (parameters.length == 0) {
        sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/mage describe <property>" + ChatColor.BLUE + " for specific properties");
        sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/mage activate" + ChatColor.BLUE + " to change or clear the active class");
        Collection<String> classKeys = mage.getClassKeys();
        if (classKeys.size() > 0) {
            Collection<String> coloredClasses = new ArrayList<>();
            for (String classKey : classKeys) {
                ChatColor color = mage.hasClassUnlocked(classKey) ? ChatColor.GREEN : ChatColor.GRAY;
                coloredClasses.add(color + classKey);
            }
            sender.sendMessage(ChatColor.AQUA + "Classes: " + ChatColor.GREEN + StringUtils.join(coloredClasses, ","));
        }
        if (!mageProperties.isEmpty()) {
            sender.sendMessage(ChatColor.AQUA + "Mage properties:");
            mageProperties.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
        }
        if (activeClass != null) {
            sender.sendMessage(ChatColor.AQUA + "Active class: " + ChatColor.GREEN + activeClass.getKey());
        } else {
            sender.sendMessage(ChatColor.DARK_GREEN + "No active class");
        }
        Set<Spell> activeSpells = mage.getActiveSpells();
        if (activeSpells != null && !activeSpells.isEmpty()) {
            Collection<String> spellNames = new ArrayList<>();
            for (Spell spell : activeSpells) {
                spellNames.add(spell.getName());
            }
            sender.sendMessage(ChatColor.AQUA + "Active spells: " + ChatColor.DARK_AQUA + StringUtils.join(spellNames, ","));
        }
        if (activeClass != null) {
            activeClass.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
        }
    } else {
        Object property = activeClass.getProperty(parameters[0]);
        if (property == null) {
            sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.RED + "(Not Set)");
        } else {
            sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.WHITE + InventoryUtils.describeProperty(property));
        }
    }
    return true;
}
Also used : MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ArrayList(java.util.ArrayList) BaseMagicProperties(com.elmakers.mine.bukkit.magic.BaseMagicProperties) MagicProperties(com.elmakers.mine.bukkit.api.magic.MagicProperties) ChatColor(org.bukkit.ChatColor) Spell(com.elmakers.mine.bukkit.api.spell.Spell)

Example 30 with Spell

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

the class Wand method updateEffects.

public void updateEffects(Mage mage) {
    if (mage == null)
        return;
    Player player = mage.getPlayer();
    if (player == null)
        return;
    // Update Bubble effects effects
    if (effectBubbles && effectColor != null) {
        Location potionEffectLocation = player.getLocation();
        potionEffectLocation.setX(potionEffectLocation.getX() + random.nextDouble() - 0.5);
        potionEffectLocation.setY(potionEffectLocation.getY() + random.nextDouble() * player.getEyeHeight());
        potionEffectLocation.setZ(potionEffectLocation.getZ() + random.nextDouble() - 0.5);
        ParticleEffect.SPELL_MOB.display(potionEffectLocation, effectColor.getColor(), 24);
    }
    Location location = mage.getLocation();
    long now = System.currentTimeMillis();
    boolean playEffects = !activeEffectsOnly || inventoryIsOpen || isInOffhand;
    if (playEffects && effectParticle != null && effectParticleInterval > 0 && effectParticleCount > 0) {
        boolean velocityCheck = true;
        if (effectParticleMinVelocity > 0) {
            double velocitySquared = effectParticleMinVelocity * effectParticleMinVelocity;
            Vector velocity = mage.getVelocity().clone();
            velocity.setY(0);
            double speedSquared = velocity.lengthSquared();
            velocityCheck = (speedSquared > velocitySquared);
        }
        if (velocityCheck && (lastParticleEffect == 0 || now > lastParticleEffect + effectParticleInterval)) {
            lastParticleEffect = now;
            Location effectLocation = player.getLocation();
            Location eyeLocation = player.getEyeLocation();
            effectLocation.setY(eyeLocation.getY() + effectParticleOffset);
            if (effectPlayer == null) {
                effectPlayer = new EffectRing(controller.getPlugin());
                effectPlayer.setParticleCount(1);
                effectPlayer.setIterations(1);
                effectPlayer.setParticleOffset(0, 0, 0);
            }
            effectPlayer.setMaterial(location.getBlock().getRelative(BlockFace.DOWN));
            if (effectParticleData == 0) {
                effectPlayer.setColor(getEffectColor());
            } else {
                effectPlayer.setColor(null);
            }
            effectPlayer.setParticleType(effectParticle);
            effectPlayer.setParticleData(effectParticleData);
            effectPlayer.setSize(effectParticleCount);
            effectPlayer.setRadius((float) effectParticleRadius);
            effectPlayer.start(effectLocation, null);
        }
    }
    if (castSpell != null && castInterval > 0) {
        if (lastSpellCast == 0 || now > lastSpellCast + castInterval) {
            boolean velocityCheck = true;
            if (castMinVelocity > 0) {
                double velocitySquared = castMinVelocity * castMinVelocity;
                Vector velocity = mage.getVelocity();
                if (castVelocityDirection != null) {
                    velocity = velocity.clone().multiply(castVelocityDirection);
                    // This is kind of a hack to make jump-detection work.
                    if (castVelocityDirection.getY() < 0) {
                        velocityCheck = velocity.getY() < 0;
                    } else {
                        velocityCheck = velocity.getY() > 0;
                    }
                }
                if (velocityCheck) {
                    double speedSquared = velocity.lengthSquared();
                    velocityCheck = (speedSquared > velocitySquared);
                }
            }
            if (velocityCheck) {
                lastSpellCast = now;
                Spell spell = mage.getSpell(castSpell);
                if (spell != null) {
                    if (castParameters == null) {
                        castParameters = new MemoryConfiguration();
                    }
                    castParameters.set("passive", true);
                    mage.setCostFree(true);
                    mage.setQuiet(true);
                    try {
                        spell.cast(castParameters);
                    } catch (Exception ex) {
                        controller.getLogger().log(Level.WARNING, "Error casting aura spell " + spell.getKey(), ex);
                    }
                    mage.setCostFree(false);
                    mage.setQuiet(false);
                }
            }
        }
    }
    if (playEffects && effectSound != null && controller.soundsEnabled() && effectSoundInterval > 0) {
        if (lastSoundEffect == 0 || now > lastSoundEffect + effectSoundInterval) {
            lastSoundEffect = now;
            effectSound.play(controller.getPlugin(), mage.getPlayer());
        }
    }
}
Also used : Player(org.bukkit.entity.Player) EffectRing(com.elmakers.mine.bukkit.effect.builtin.EffectRing) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) Vector(org.bukkit.util.Vector) Spell(com.elmakers.mine.bukkit.api.spell.Spell) Location(org.bukkit.Location)

Aggregations

Spell (com.elmakers.mine.bukkit.api.spell.Spell)39 Mage (com.elmakers.mine.bukkit.api.magic.Mage)14 BaseSpell (com.elmakers.mine.bukkit.spell.BaseSpell)12 Player (org.bukkit.entity.Player)11 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)10 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)9 ItemStack (org.bukkit.inventory.ItemStack)9 MageController (com.elmakers.mine.bukkit.api.magic.MageController)6 Mage (com.elmakers.mine.bukkit.magic.Mage)5 ActionSpell (com.elmakers.mine.bukkit.spell.ActionSpell)5 Wand (com.elmakers.mine.bukkit.wand.Wand)5 ArrayList (java.util.ArrayList)5 Location (org.bukkit.Location)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 Wand (com.elmakers.mine.bukkit.api.wand.Wand)4 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)4 EventHandler (org.bukkit.event.EventHandler)4 Batch (com.elmakers.mine.bukkit.api.batch.Batch)3 SpellBatch (com.elmakers.mine.bukkit.api.batch.SpellBatch)3 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)3