Search in sources :

Example 6 with UndoList

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

the class UndoableSpell method registerForUndo.

public void registerForUndo() {
    // Must add empty lists here since they may get added to later!
    UndoList list = getUndoList();
    if (!list.isScheduled()) {
        controller.update(list);
    }
    mage.registerForUndo(list);
}
Also used : UndoList(com.elmakers.mine.bukkit.block.UndoList)

Example 7 with UndoList

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

the class FillSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    boolean singleBlock = getTargetType() != TargetType.SELECT;
    Block targetBlock = getTargetBlock();
    if (!singleBlock && parameters.getBoolean("select_self", true) && isLookingDown()) {
        targetBlock = mage.getLocation().getBlock().getRelative(BlockFace.DOWN);
    }
    if (targetBlock == null) {
        return SpellResult.NO_TARGET;
    }
    MaterialBrush buildWith = getBrush();
    boolean hasPermission = buildWith != null && buildWith.isErase() ? hasBreakPermission(targetBlock) : hasBuildPermission(targetBlock);
    if (!hasPermission) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (singleBlock) {
        deactivate();
        if (isIndestructible(targetBlock)) {
            return SpellResult.NO_TARGET;
        }
        registerForUndo(targetBlock);
        buildWith.setTarget(targetBlock.getLocation());
        buildWith.update(mage, targetBlock.getLocation());
        buildWith.modify(targetBlock);
        controller.updateBlock(targetBlock);
        registerForUndo();
        return SpellResult.CAST;
    }
    if (targetLocation2 != null) {
        this.targetBlock = targetLocation2.getBlock();
    }
    if (this.targetBlock != null) {
        // Update the brush using the center of the fill volume.
        // This is kind of a hack to make map-building easier
        Location centerLocation = this.targetBlock.getLocation();
        Location secondLocation = this.targetBlock.getLocation();
        if (buildWith.getMode() == BrushMode.MAP) {
            centerLocation = targetBlock.getLocation();
            centerLocation.setX(Math.floor((centerLocation.getX() + secondLocation.getX()) / 2));
            centerLocation.setY(Math.floor((centerLocation.getY() + secondLocation.getY()) / 2));
            centerLocation.setZ(Math.floor((centerLocation.getZ() + secondLocation.getZ()) / 2));
        }
        buildWith.setTarget(this.targetBlock.getLocation(), centerLocation);
        FillBatch batch = new FillBatch(this, secondLocation, targetBlock.getLocation(), buildWith);
        boolean consumeBlocks = parameters.getBoolean("consume", false);
        batch.setConsume(consumeBlocks);
        UndoList undoList = getUndoList();
        if (undoList != null && !currentCast.isConsumeFree()) {
            undoList.setConsumed(consumeBlocks);
        }
        int maxDimension = parameters.getInt("max_dimension", DEFAULT_MAX_DIMENSION);
        maxDimension = parameters.getInt("md", maxDimension);
        maxDimension = (int) (mage.getConstructionMultiplier() * maxDimension);
        if (!batch.checkDimension(maxDimension)) {
            return SpellResult.FAIL;
        }
        boolean success = mage.addBatch(batch);
        deactivate();
        return success ? SpellResult.CAST : SpellResult.FAIL;
    } else {
        this.targetBlock = targetBlock;
        activate();
        return SpellResult.TARGET_SELECTED;
    }
}
Also used : MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) UndoList(com.elmakers.mine.bukkit.block.UndoList) Block(org.bukkit.block.Block) FillBatch(com.elmakers.mine.bukkit.batch.FillBatch) Location(org.bukkit.Location)

Aggregations

UndoList (com.elmakers.mine.bukkit.block.UndoList)7 Block (org.bukkit.block.Block)3 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)2 ArrayList (java.util.ArrayList)2 Location (org.bukkit.Location)2 ConstructBatch (com.elmakers.mine.bukkit.batch.ConstructBatch)1 FillBatch (com.elmakers.mine.bukkit.batch.FillBatch)1 ConstructionType (com.elmakers.mine.bukkit.block.ConstructionType)1 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)1 Target (com.elmakers.mine.bukkit.utility.Target)1 List (java.util.List)1 Random (java.util.Random)1 Material (org.bukkit.Material)1 TreeType (org.bukkit.TreeType)1 World (org.bukkit.World)1 Biome (org.bukkit.block.Biome)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 Vector (org.bukkit.util.Vector)1