Search in sources :

Example 61 with Mage

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

the class CommandAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    CommandSender sender = asConsole ? Bukkit.getConsoleSender() : mage.getCommandSender();
    if (sender == null) {
        return SpellResult.FAIL;
    }
    Queue<String> conversationCommands = new ArrayDeque<>(commands.size());
    boolean isOp = sender.isOp();
    if (opPlayer && !isOp) {
        sender.setOp(true);
    }
    for (String command : commands) {
        try {
            String converted = context.parameterize(command);
            if (converted.contains("@arg")) {
                conversationCommands.add(converted);
            } else {
                controller.getPlugin().getServer().dispatchCommand(sender, converted);
            }
        } catch (Exception ex) {
            controller.getLogger().log(Level.WARNING, "Error running command: " + command, ex);
        }
    }
    if (opPlayer && !isOp) {
        sender.setOp(false);
    }
    if (!conversationCommands.isEmpty()) {
        runConversations(context, conversationCommands, opPlayer);
    }
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) CommandSender(org.bukkit.command.CommandSender) ArrayDeque(java.util.ArrayDeque)

Example 62 with Mage

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

the class ModifyManaAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity target = context.getTargetEntity();
    if (target == null) {
        return SpellResult.NO_TARGET;
    }
    MageController controller = context.getController();
    Mage mage = controller.getRegisteredMage(target);
    if (mage == null) {
        return SpellResult.NO_TARGET;
    }
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    double currentMana = mage.getMana();
    if (mana < 0 && currentMana <= 0) {
        return SpellResult.NO_TARGET;
    }
    int manaMax = mage.getManaMax();
    if (mana > 0 && currentMana >= manaMax) {
        return SpellResult.NO_TARGET;
    }
    if (fillMana) {
        currentMana = manaMax;
    } else {
        currentMana = Math.min(Math.max(0, currentMana + mana), manaMax);
    }
    mage.setMana((float) currentMana);
    mage.updateMana();
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 63 with Mage

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

the class ModifyPropertiesAction method perform.

@Override
public SpellResult perform(CastContext context) {
    if (modify == null) {
        return SpellResult.FAIL;
    }
    Entity entity = context.getTargetEntity();
    Mage mage = entity == null ? null : context.getController().getRegisteredMage(entity);
    if (mage == null) {
        return SpellResult.NO_TARGET;
    }
    CasterProperties properties = null;
    if (modifyTarget.equals("wand")) {
        properties = mage.getActiveWand();
    } else if (modifyTarget.equals("player")) {
        properties = mage.getProperties();
    } else {
        properties = mage.getClass(modifyTarget);
    }
    // I am now wishing I hadn't made a base class called "mage" :(
    if (properties == null && modifyTarget.equals("mage")) {
        properties = mage.getProperties();
    }
    if (properties == null) {
        return SpellResult.NO_TARGET;
    }
    ConfigurationSection original = new MemoryConfiguration();
    ConfigurationSection changed = new MemoryConfiguration();
    for (ModifyProperty property : modify) {
        Object originalValue = properties.getProperty(property.path);
        Object newValue = property.value;
        if ((originalValue == null || originalValue instanceof Number) && property.value instanceof String) {
            EquationTransform transform = EquationStore.getInstance().getTransform((String) property.value);
            originalValue = originalValue == null ? null : NumberConversions.toDouble(originalValue);
            double defaultValue = property.defaultValue == null ? 0 : property.defaultValue;
            if (transform.isValid()) {
                if (originalValue == null) {
                    originalValue = defaultValue;
                } else if (property.max != null && (Double) originalValue >= property.max) {
                    continue;
                } else if (property.min != null && (Double) originalValue <= property.min) {
                    continue;
                }
                transform.setVariable("x", (Double) originalValue);
                double transformedValue = transform.get();
                if (!Double.isNaN(transformedValue)) {
                    if (property.max != null) {
                        transformedValue = Math.min(transformedValue, property.max);
                    }
                    if (property.min != null) {
                        transformedValue = Math.max(transformedValue, property.min);
                    }
                    newValue = transformedValue;
                }
            }
        }
        changed.set(property.path, newValue);
        original.set(property.path, originalValue);
    }
    if (changed.getKeys(false).isEmpty())
        return SpellResult.NO_TARGET;
    if (upgrade)
        properties.upgrade(changed);
    else
        properties.configure(changed);
    context.registerForUndo(new ModifyPropertyUndoAction(original, properties));
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) EquationTransform(de.slikey.effectlib.math.EquationTransform) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 64 with Mage

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

the class ModifySPAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    int currentSP = mage.getSkillPoints();
    if (sp < 0 && currentSP <= 0) {
        return SpellResult.NO_TARGET;
    }
    int spMax = controller.getSPMaximum();
    if (sp > 0 && currentSP >= spMax) {
        return SpellResult.NO_TARGET;
    }
    mage.addSkillPoints(sp);
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 65 with Mage

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

the class IgniteAction method perform.

@Override
public SpellResult perform(CastContext context) {
    int ticks = duration * 20 / 1000;
    Entity entity = context.getTargetEntity();
    MageController controller = context.getController();
    boolean isElemental = controller.isElemental(entity);
    if (!isElemental && entity.getFireTicks() == ticks) {
        return SpellResult.NO_TARGET;
    }
    context.registerDamaged(entity);
    if (isElemental) {
        Mage mage = context.getMage();
        controller.damageElemental(entity, 0, ticks, mage.getCommandSender());
    } else {
        entity.setFireTicks(ticks);
    }
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Aggregations

Mage (com.elmakers.mine.bukkit.api.magic.Mage)187 Player (org.bukkit.entity.Player)62 Entity (org.bukkit.entity.Entity)56 Wand (com.elmakers.mine.bukkit.api.wand.Wand)47 MageController (com.elmakers.mine.bukkit.api.magic.MageController)45 ItemStack (org.bukkit.inventory.ItemStack)38 Location (org.bukkit.Location)33 LivingEntity (org.bukkit.entity.LivingEntity)31 ArrayList (java.util.ArrayList)25 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)18 Inventory (org.bukkit.inventory.Inventory)16 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)15 Spell (com.elmakers.mine.bukkit.api.spell.Spell)14 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)14 Block (org.bukkit.block.Block)14 Target (com.elmakers.mine.bukkit.utility.Target)13 EventHandler (org.bukkit.event.EventHandler)13 ItemMeta (org.bukkit.inventory.meta.ItemMeta)12 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)10 Vector (org.bukkit.util.Vector)10