Search in sources :

Example 11 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class ParallelAction method finish.

@Override
public void finish(CastContext context) {
    super.finish(context);
    ActionHandler actions = getHandler("actions");
    if (actions != null) {
        actions.finish(context);
    }
}
Also used : ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler)

Example 12 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class ActionSpell method loadTemplate.

@Override
protected void loadTemplate(ConfigurationSection template) {
    castOnNoTarget = true;
    super.loadTemplate(template);
    undoable = false;
    requiresBuildPermission = false;
    requiresBreakPermission = false;
    usesBrush = template.getBoolean("uses_brush", false);
    ConfigurationSection actionsNode = template.getConfigurationSection("actions");
    if (actionsNode != null) {
        ConfigurationSection parameters = template.getConfigurationSection("parameters");
        Object baseActions = actionsNode.get("cast");
        Collection<String> templateKeys = template.getKeys(false);
        for (String templateKey : templateKeys) {
            if (templateKey.endsWith("_parameters")) {
                ConfigurationSection overrides = ConfigurationUtils.cloneConfiguration(template.getConfigurationSection(templateKey));
                String handlerKey = templateKey.substring(0, templateKey.length() - 11);
                handlerParameters.put(handlerKey, overrides);
                // Auto-register base actions, kind of hacky to check for alternates though.
                if (baseActions != null && !actionsNode.contains(handlerKey) && handlerKey.startsWith("alternate_")) {
                    actionsNode.set(handlerKey, baseActions);
                }
            }
        }
        actionsNode = ConfigurationUtils.replaceParameters(actionsNode, parameters);
        if (actionsNode != null) {
            Collection<String> actionKeys = actionsNode.getKeys(false);
            for (String actionKey : actionKeys) {
                ActionHandler handler = new ActionHandler();
                handler.load(this, actionsNode, actionKey);
                handler.initialize(this, parameters);
                usesBrush = usesBrush || handler.usesBrush();
                undoable = undoable || handler.isUndoable();
                requiresBuildPermission = requiresBuildPermission || handler.requiresBuildPermission();
                requiresBreakPermission = requiresBreakPermission || handler.requiresBreakPermission();
                actions.put(actionKey, handler);
            }
        }
    }
    undoable = template.getBoolean("undoable", undoable);
    requiresBreakPermission = template.getBoolean("require_break", requiresBreakPermission);
    requiresBuildPermission = template.getBoolean("require_build", requiresBuildPermission);
}
Also used : ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 13 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class AbsorbSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    target();
    ActionHandler handler = new ActionHandler();
    handler.loadAction(new AbsorbAction());
    handler.initialize(this, parameters);
    return handler.start(getCurrentCast(), parameters);
}
Also used : ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler) AbsorbAction(com.elmakers.mine.bukkit.action.builtin.AbsorbAction)

Example 14 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class FireSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (target == null || !target.isValid()) {
        return SpellResult.NO_TARGET;
    }
    Block targetBlock = target.getBlock();
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    CoverAction cover = new CoverAction();
    cover.addAction(new BurnAction());
    ActionHandler handler = new ActionHandler();
    handler.loadAction(cover);
    handler.initialize(this, parameters);
    registerForUndo();
    return handler.start(getCurrentCast(), parameters);
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) CoverAction(com.elmakers.mine.bukkit.action.builtin.CoverAction) BurnAction(com.elmakers.mine.bukkit.action.builtin.BurnAction) Block(org.bukkit.block.Block) ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler)

Example 15 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class FlowerSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (target == null || !target.isValid()) {
        return SpellResult.NO_TARGET;
    }
    Block targetBlock = target.getBlock();
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    CoverAction cover = new CoverAction();
    cover.addAction(new FlowerAction());
    ActionHandler handler = new ActionHandler();
    handler.loadAction(cover);
    handler.initialize(this, parameters);
    registerForUndo();
    return handler.start(getCurrentCast(), parameters);
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) CoverAction(com.elmakers.mine.bukkit.action.builtin.CoverAction) FlowerAction(com.elmakers.mine.bukkit.action.builtin.FlowerAction) Block(org.bukkit.block.Block) ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler)

Aggregations

ActionHandler (com.elmakers.mine.bukkit.action.ActionHandler)15 CoverAction (com.elmakers.mine.bukkit.action.builtin.CoverAction)4 Target (com.elmakers.mine.bukkit.utility.Target)4 Block (org.bukkit.block.Block)4 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)3 ActionContext (com.elmakers.mine.bukkit.action.ActionContext)2 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)2 AbsorbAction (com.elmakers.mine.bukkit.action.builtin.AbsorbAction)1 BurnAction (com.elmakers.mine.bukkit.action.builtin.BurnAction)1 DamageAction (com.elmakers.mine.bukkit.action.builtin.DamageAction)1 FlowerAction (com.elmakers.mine.bukkit.action.builtin.FlowerAction)1 FreezeAction (com.elmakers.mine.bukkit.action.builtin.FreezeAction)1 LightningAction (com.elmakers.mine.bukkit.action.builtin.LightningAction)1 PotionEffectAction (com.elmakers.mine.bukkit.action.builtin.PotionEffectAction)1 TargetType (com.elmakers.mine.bukkit.api.spell.TargetType)1 SourceLocation (com.elmakers.mine.bukkit.magic.SourceLocation)1 ArrayList (java.util.ArrayList)1 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)1