Search in sources :

Example 1 with UndoQueue

use of com.elmakers.mine.bukkit.api.block.UndoQueue in project MagicPlugin by elBukkit.

the class TransmuteSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    BlockList transmuteAction = null;
    /*
         * Use target if targeting
         */
    Block target = getTargetBlock();
    if (target != null) {
        UndoQueue undoQueue = mage.getUndoQueue();
        transmuteAction = undoQueue.getLast(target);
    }
    if (transmuteAction == null) {
        UndoQueue undoQueue = mage.getUndoQueue();
        transmuteAction = undoQueue.getLast();
    }
    if (transmuteAction == null) {
        return SpellResult.NO_TARGET;
    }
    MaterialBrush buildWith = getBrush();
    for (BlockData undoBlock : transmuteAction) {
        Block block = undoBlock.getBlock();
        buildWith.modify(block);
    }
    return SpellResult.CAST;
}
Also used : UndoQueue(com.elmakers.mine.bukkit.api.block.UndoQueue) MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) BlockList(com.elmakers.mine.bukkit.api.block.BlockList) Block(org.bukkit.block.Block) BlockData(com.elmakers.mine.bukkit.api.block.BlockData)

Example 2 with UndoQueue

use of com.elmakers.mine.bukkit.api.block.UndoQueue in project MagicPlugin by elBukkit.

the class UndoSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    int timeout = parameters.getInt("target_timeout", 0);
    boolean targetSelf = parameters.getBoolean("target_up_self", false);
    boolean targetDown = parameters.getBoolean("target_down_block", false);
    Entity targetEntity = target.getEntity();
    SpellResult result = SpellResult.CAST;
    if (targetSelf && isLookingUp()) {
        targetEntity = mage.getEntity();
        getCurrentCast().setTargetName(mage.getName());
        result = SpellResult.ALTERNATE_UP;
    }
    if (targetEntity != null && controller.isMage(targetEntity)) {
        Mage targetMage = controller.getMage(targetEntity);
        Batch batch = targetMage.cancelPending();
        if (batch != null) {
            undoListName = (batch instanceof SpellBatch) ? ((SpellBatch) batch).getSpell().getName() : null;
            return SpellResult.ALTERNATE;
        }
        UndoQueue queue = targetMage.getUndoQueue();
        UndoList undoList = queue.undoRecent(timeout);
        if (undoList != null) {
            undoListName = undoList.getName();
        }
        return undoList != null ? result : SpellResult.NO_TARGET;
    }
    if (!parameters.getBoolean("target_blocks", true)) {
        return SpellResult.NO_TARGET;
    }
    Block targetBlock = target.getBlock();
    if (targetDown && isLookingDown()) {
        targetBlock = getLocation().getBlock();
    }
    if (targetBlock != null) {
        boolean targetAll = mage.isSuperPowered();
        if (targetAll) {
            UndoList undid = controller.undoRecent(targetBlock, timeout);
            if (undid != null) {
                Mage targetMage = undid.getOwner();
                undoListName = undid.getName();
                getCurrentCast().setTargetName(targetMage.getName());
                return result;
            }
        } else {
            getCurrentCast().setTargetName(mage.getName());
            UndoList undoList = mage.undo(targetBlock);
            if (undoList != null) {
                undoListName = undoList.getName();
                return result;
            }
        }
    }
    return SpellResult.NO_TARGET;
}
Also used : Entity(org.bukkit.entity.Entity) SpellBatch(com.elmakers.mine.bukkit.api.batch.SpellBatch) Target(com.elmakers.mine.bukkit.utility.Target) UndoQueue(com.elmakers.mine.bukkit.api.block.UndoQueue) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Batch(com.elmakers.mine.bukkit.api.batch.Batch) SpellBatch(com.elmakers.mine.bukkit.api.batch.SpellBatch) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Block(org.bukkit.block.Block) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

Example 3 with UndoQueue

use of com.elmakers.mine.bukkit.api.block.UndoQueue in project MagicPlugin by elBukkit.

the class UndoAction method perform.

@Override
public SpellResult perform(CastContext context) {
    // Start of new functionality
    if (undoOldest > 0 || undoToSize > 0) {
        return performNew(context);
    }
    // Old functionality- this should be converted into an action that processes
    // blocks instead of creating a separate batch.
    Entity targetEntity = context.getTargetEntity();
    SpellResult result = SpellResult.CAST;
    Mage mage = context.getMage();
    if (targetSelf) {
        targetEntity = context.getEntity();
        context.setTargetName(mage.getName());
        result = SpellResult.ALTERNATE_UP;
    }
    MageController controller = context.getController();
    if (targetEntity != null && controller.isMage(targetEntity)) {
        Mage targetMage = controller.getMage(targetEntity);
        mage.sendDebugMessage(ChatColor.AQUA + "Undo checking last spell of " + ChatColor.GOLD + targetMage + ChatColor.AQUA + " with timeout of " + ChatColor.YELLOW + timeout + ChatColor.AQUA + " for target spellKey" + ChatColor.BLUE + targetSpellKey, 2);
        Batch batch = targetMage.cancelPending(targetSpellKey);
        if (batch != null) {
            undoListName = batch.getName();
            if (cancel) {
                return SpellResult.DEACTIVATE;
            }
        }
        UndoQueue queue = targetMage.getUndoQueue();
        UndoList undoList = queue.undoRecent(timeout, targetSpellKey);
        if (undoList != null) {
            undoListName = undoList.getName();
        }
        return undoList != null ? result : SpellResult.NO_TARGET;
    }
    if (!targetBlocks) {
        return SpellResult.NO_TARGET;
    }
    Block targetBlock = context.getTargetBlock();
    if (targetDown) {
        targetBlock = context.getLocation().getBlock();
    }
    if (targetBlock != null) {
        boolean undoAny = targetOtherBlocks;
        undoAny = undoAny || (adminPermission != null && context.getController().hasPermission(context.getMage().getCommandSender(), adminPermission));
        undoAny = undoAny || mage.isSuperPowered();
        if (undoAny) {
            mage.sendDebugMessage(ChatColor.AQUA + "Looking for recent cast at " + ChatColor.GOLD + targetBlock + ChatColor.AQUA + " with timeout of " + ChatColor.YELLOW + blockTimeout, 2);
            UndoList undid = controller.undoRecent(targetBlock, blockTimeout);
            if (undid != null) {
                Mage targetMage = undid.getOwner();
                undoListName = undid.getName();
                if (targetMage != null) {
                    context.setTargetName(targetMage.getName());
                }
                return result;
            }
        } else {
            mage.sendDebugMessage(ChatColor.AQUA + "Looking for recent self-cast at " + ChatColor.GOLD + targetBlock, 2);
            context.setTargetName(mage.getName());
            UndoList undoList = mage.undo(targetBlock);
            if (undoList != null) {
                undoListName = undoList.getName();
                return result;
            }
        }
    }
    return SpellResult.NO_TARGET;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) UndoQueue(com.elmakers.mine.bukkit.api.block.UndoQueue) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Batch(com.elmakers.mine.bukkit.api.batch.Batch) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Block(org.bukkit.block.Block) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

Aggregations

UndoQueue (com.elmakers.mine.bukkit.api.block.UndoQueue)3 Block (org.bukkit.block.Block)3 Batch (com.elmakers.mine.bukkit.api.batch.Batch)2 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)2 Entity (org.bukkit.entity.Entity)2 SpellBatch (com.elmakers.mine.bukkit.api.batch.SpellBatch)1 BlockData (com.elmakers.mine.bukkit.api.block.BlockData)1 BlockList (com.elmakers.mine.bukkit.api.block.BlockList)1 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 Target (com.elmakers.mine.bukkit.utility.Target)1