Search in sources :

Example 1 with RegenerateBatch

use of com.elmakers.mine.bukkit.batch.RegenerateBatch in project MagicPlugin by elBukkit.

the class RegenerateSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Block targetBlock = getTargetBlock();
    if (targetBlock == null) {
        return SpellResult.NO_TARGET;
    }
    if (!hasBuildPermission(targetBlock) || !hasBreakPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (targetLocation2 != null) {
        this.targetBlock = targetLocation2.getBlock();
    }
    TargetType targetType = getTargetType();
    if (this.targetBlock != null || targetType == TargetType.BLOCK) {
        Block secondBlock = targetType == TargetType.BLOCK ? targetBlock : this.targetBlock;
        RegenerateBatch batch = new RegenerateBatch(this, secondBlock.getLocation(), targetBlock.getLocation());
        int maxDimension = parameters.getInt("max_dimension", DEFAULT_MAX_DIMENSION);
        maxDimension = (int) (mage.getConstructionMultiplier() * maxDimension);
        if (!batch.checkDimension(maxDimension)) {
            return SpellResult.FAIL;
        }
        batch.setExpand(parameters.getBoolean("expand", false));
        boolean success = mage.addBatch(batch);
        deactivate();
        return success ? SpellResult.CAST : SpellResult.FAIL;
    } else {
        this.targetBlock = targetBlock;
        activate();
        return SpellResult.TARGET_SELECTED;
    }
}
Also used : TargetType(com.elmakers.mine.bukkit.api.spell.TargetType) Block(org.bukkit.block.Block) RegenerateBatch(com.elmakers.mine.bukkit.batch.RegenerateBatch)

Aggregations

TargetType (com.elmakers.mine.bukkit.api.spell.TargetType)1 RegenerateBatch (com.elmakers.mine.bukkit.batch.RegenerateBatch)1 Block (org.bukkit.block.Block)1