Search in sources :

Example 26 with UndoList

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

the class UndoAction method performNew.

protected SpellResult performNew(CastContext context) {
    UndoList undoList = context.getUndoList();
    int totalSize = undoList.size() + undoList.getRunnableCount();
    if (totalSize == 0) {
        return SpellResult.NO_ACTION;
    }
    boolean undid = false;
    while (context.getWorkAllowed() > 0) {
        if (undoToSize > 0 && totalSize <= undoToSize)
            break;
        if (undoList.size() == 0) {
            if (undoList.undoNextRunnable() == null)
                break;
        } else {
            if (undoList.undoNext(false) == null)
                break;
        }
        undid = true;
        undone++;
        context.addWork(10);
        if (undoOldest > 0 && undone > undoOldest) {
            break;
        }
    }
    if (!undid)
        return SpellResult.NO_ACTION;
    return undoOldest == 0 || undone >= undoOldest ? SpellResult.CAST : SpellResult.PENDING;
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList)

Example 27 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList 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)

Example 28 with UndoList

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

the class BlockRecurse method recurse.

protected void recurse(Block block, ActionContext recurseAction, CastContext context, BlockFace nextFace, int rDepth) {
    if (nextFace != null) {
        block = block.getRelative(nextFace);
    }
    if (replaceable != null && !replaceable.contains(new MaterialAndData(block))) {
        return;
    }
    UndoList undoList = context.getUndoList();
    if (undoList != null) {
        if (undoList.contains(block)) {
            return;
        }
        undoList.add(block);
    }
    context.setTargetLocation(block.getLocation());
    if (recurseAction.perform(context) != SpellResult.CAST) {
        return;
    }
    if (rDepth < maxRecursion) {
        for (BlockFace face : BlockData.FACES) {
            if (nextFace == null || nextFace != BlockData.getReverseFace(face)) {
                recurse(block, recurseAction, context, face, rDepth + 1);
            }
        }
    }
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList) BlockFace(org.bukkit.block.BlockFace) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData)

Example 29 with UndoList

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

the class ExplosionController method getExplosionUndo.

@Nullable
protected UndoList getExplosionUndo(Entity explodingEntity) {
    UndoList blockList = controller.getEntityUndo(explodingEntity);
    if (blockList == null && autoRollbackDuration > 0 && rollbackExplosions.contains(explodingEntity.getType())) {
        Mage mage = controller.getMage(explodingEntity);
        blockList = new com.elmakers.mine.bukkit.block.UndoList(mage, "Explosion (" + explodingEntity.getType().name() + ")");
        blockList.setScheduleUndo(autoRollbackDuration);
        blockList.setUndoSpeed(autoRollbackSpeed);
        mage.prepareForUndo(blockList);
    }
    return blockList;
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Nullable(javax.annotation.Nullable)

Example 30 with UndoList

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

the class HangingController method onHangingBreakByEntity.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
    Entity breakingEntity = event.getRemover();
    if (breakingEntity == null)
        return;
    Hanging entity = event.getEntity();
    UndoList undoList = controller.getEntityUndo(breakingEntity);
    if (undoList != null && undoList.isScheduled()) {
        undoList.damage(entity);
        // Prevent item drops, but still remove it
        // Else it'll probably just break again.
        event.setCancelled(true);
    }
}
Also used : Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Hanging(org.bukkit.entity.Hanging) EventHandler(org.bukkit.event.EventHandler)

Aggregations

UndoList (com.elmakers.mine.bukkit.api.block.UndoList)36 EventHandler (org.bukkit.event.EventHandler)15 Entity (org.bukkit.entity.Entity)14 Block (org.bukkit.block.Block)13 Location (org.bukkit.Location)10 FallingBlock (org.bukkit.entity.FallingBlock)10 Mage (com.elmakers.mine.bukkit.api.magic.Mage)8 LivingEntity (org.bukkit.entity.LivingEntity)6 Player (org.bukkit.entity.Player)6 ItemStack (org.bukkit.inventory.ItemStack)6 Ageable (org.bukkit.entity.Ageable)4 PigZombie (org.bukkit.entity.PigZombie)4 Slime (org.bukkit.entity.Slime)4 Zombie (org.bukkit.entity.Zombie)4 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)3 Target (com.elmakers.mine.bukkit.utility.Target)3 Nullable (javax.annotation.Nullable)3 BlockFace (org.bukkit.block.BlockFace)3 Skeleton (org.bukkit.entity.Skeleton)3