Search in sources :

Example 1 with CastContext

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

the class UndoList method undo.

public void undo(boolean blocking, boolean undoEntities) {
    if (undone)
        return;
    undone = true;
    if (batch != null && !batch.isFinished()) {
        batch.finish();
    }
    // This is a hack to make forced-undo happen instantly
    if (undoEntities) {
        this.speed = 0;
    }
    undoEntityEffects = undoEntityEffects || undoEntities;
    unlink();
    CastContext context = getContext();
    if (context != null) {
        context.cancelEffects();
    }
    if (runnables != null) {
        for (Runnable runnable : runnables) {
            runnable.run();
        }
        runnables = null;
    }
    if (blockList == null) {
        undoEntityEffects();
        return;
    }
    // Block changes will be performed in a batch
    UndoBatch batch = new UndoBatch(this);
    if (blocking) {
        while (!batch.isFinished()) {
            batch.process(1000);
        }
    } else {
        owner.addUndoBatch(batch);
    }
}
Also used : CastContext(com.elmakers.mine.bukkit.api.action.CastContext) UndoBatch(com.elmakers.mine.bukkit.batch.UndoBatch)

Example 2 with CastContext

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

the class RecurseSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Block targetBlock = getTargetBlock();
    if (targetBlock == null) {
        return SpellResult.NO_TARGET;
    }
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (!isDestructible(targetBlock)) {
        return SpellResult.NO_TARGET;
    }
    BlockRecurse blockRecurse = new BlockRecurse();
    int size = parameters.getInt("size", 8);
    size = (int) (mage.getRadiusMultiplier() * size);
    blockRecurse.setMaxRecursion(size);
    ModifyBlockAction action = new ModifyBlockAction();
    action.initialize(this, parameters);
    blockRecurse.addReplaceable(new MaterialAndData(targetBlock));
    Material targetMaterial = targetBlock.getType();
    // A bit hacky, but is very handy!
    if (targetMaterial == Material.STATIONARY_WATER || targetMaterial == Material.WATER) {
        for (byte i = 0; i < 9; i++) {
            blockRecurse.addReplaceable(Material.STATIONARY_WATER, i);
            blockRecurse.addReplaceable(Material.WATER, i);
        }
    } else if (targetMaterial == Material.STATIONARY_LAVA || targetMaterial == Material.LAVA) {
        for (byte i = 0; i < 9; i++) {
            blockRecurse.addReplaceable(Material.STATIONARY_LAVA, i);
            blockRecurse.addReplaceable(Material.LAVA, i);
        }
    } else if (targetMaterial == Material.SNOW) {
        for (byte i = 0; i < 8; i++) {
            blockRecurse.addReplaceable(Material.SNOW, i);
        }
    }
    CastContext context = getCurrentCast();
    context.setTargetLocation(targetBlock.getLocation());
    blockRecurse.recurse(new ActionContext(action, parameters), context);
    registerForUndo();
    controller.updateBlock(targetBlock);
    return SpellResult.CAST;
}
Also used : CastContext(com.elmakers.mine.bukkit.api.action.CastContext) BlockRecurse(com.elmakers.mine.bukkit.batch.BlockRecurse) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) ModifyBlockAction(com.elmakers.mine.bukkit.action.builtin.ModifyBlockAction) Block(org.bukkit.block.Block) Material(org.bukkit.Material) ActionContext(com.elmakers.mine.bukkit.action.ActionContext)

Example 3 with CastContext

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

the class UndoList method undoNext.

@Nullable
@Override
public BlockData undoNext(boolean applyPhysics) {
    if (blockList.size() == 0) {
        return null;
    }
    BlockData blockData = blockList.removeFirst();
    BlockState currentState = blockData.getBlock().getState();
    if (undo(blockData, applyPhysics)) {
        blockIdMap.remove(blockData.getId());
        if (consumed && !isScheduled() && currentState.getType() != Material.AIR && owner != null) {
            owner.giveItem(new ItemStack(currentState.getType(), 1, DeprecatedUtils.getRawData(currentState)));
        }
        CastContext context = getContext();
        if (context != null && context.hasEffects("undo_block")) {
            Block block = blockData.getBlock();
            if (block.getType() != currentState.getType()) {
                context.playEffects("undo_block", 1.0f, null, null, block.getLocation(), null, block);
            }
        }
        return blockData;
    }
    blockList.addFirst(blockData);
    return null;
}
Also used : BlockState(org.bukkit.block.BlockState) CastContext(com.elmakers.mine.bukkit.api.action.CastContext) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) BlockData(com.elmakers.mine.bukkit.api.block.BlockData) ItemStack(org.bukkit.inventory.ItemStack) Nullable(javax.annotation.Nullable)

Example 4 with CastContext

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

the class UndoBatch method finish.

@Override
public void finish() {
    if (!finished) {
        finished = true;
        undoList.unregisterWatched();
        undoList.undoEntityEffects();
        if (!undoList.isScheduled()) {
            controller.update(undoList);
        }
        CastContext context = undoList.getContext();
        if (context != null) {
            context.playEffects("undo_finished");
        }
    }
}
Also used : CastContext(com.elmakers.mine.bukkit.api.action.CastContext)

Example 5 with CastContext

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

the class CastingCost method has.

@Override
public boolean has(Spell spell) {
    CastContext context = spell.getCurrentCast();
    Mage mage = context.getMage();
    Wand wand = context.getWand();
    return has(mage, wand, spell);
}
Also used : CastContext(com.elmakers.mine.bukkit.api.action.CastContext) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand)

Aggregations

CastContext (com.elmakers.mine.bukkit.api.action.CastContext)6 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 Wand (com.elmakers.mine.bukkit.api.wand.Wand)2 Block (org.bukkit.block.Block)2 ActionContext (com.elmakers.mine.bukkit.action.ActionContext)1 ModifyBlockAction (com.elmakers.mine.bukkit.action.builtin.ModifyBlockAction)1 BlockData (com.elmakers.mine.bukkit.api.block.BlockData)1 BlockRecurse (com.elmakers.mine.bukkit.batch.BlockRecurse)1 UndoBatch (com.elmakers.mine.bukkit.batch.UndoBatch)1 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)1 Nullable (javax.annotation.Nullable)1 Material (org.bukkit.Material)1 BlockState (org.bukkit.block.BlockState)1 FallingBlock (org.bukkit.entity.FallingBlock)1 ItemStack (org.bukkit.inventory.ItemStack)1