Search in sources :

Example 21 with SpellResult

use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.

the class AlterSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (target.hasEntity()) {
        SpellResult result = alterEntity(target.getEntity());
        if (result != SpellResult.NO_TARGET) {
            return result;
        }
    }
    Block targetBlock = target.getBlock();
    if (targetBlock == null) {
        return SpellResult.NO_TARGET;
    }
    int recurseDistance = parameters.getInt("depth", DEFAULT_RECURSE_DISTANCE);
    recurseDistance = (int) (mage.getRadiusMultiplier() * recurseDistance);
    List<Integer> adjustableMaterials = parseIntegers(DEFAULT_ADJUSTABLES);
    List<Integer> maxData = parseIntegers(DEFAULT_ADJUST_MAX);
    List<Integer> minData = parseIntegers(DEFAULT_ADJUST_MIN);
    if (adjustableMaterials.size() != maxData.size() || maxData.size() != minData.size()) {
        controller.getLogger().warning("Spells:Alter: Mis-match in adjustable material lists!");
    }
    if (!adjustableMaterials.contains(targetBlock.getTypeId())) {
        return SpellResult.FAIL;
    }
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (mage.isIndestructible(targetBlock)) {
        return SpellResult.NO_TARGET;
    }
    if (!isDestructible(targetBlock)) {
        return SpellResult.NO_TARGET;
    }
    int originalData = targetBlock.getData();
    int materialIndex = adjustableMaterials.indexOf(targetBlock.getTypeId());
    int minValue = minData.get(materialIndex);
    int maxValue = maxData.get(materialIndex);
    int dataSize = maxValue - minValue + 1;
    byte data = (byte) ((((originalData - minValue) + 1) % dataSize) + minValue);
    boolean recursive = recurseDistance > 0;
    adjust(targetBlock, data, recursive, recurseDistance, 0);
    registerForUndo();
    return SpellResult.CAST;
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) Block(org.bukkit.block.Block) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

Aggregations

SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)21 Entity (org.bukkit.entity.Entity)6 Mage (com.elmakers.mine.bukkit.api.magic.Mage)5 Block (org.bukkit.block.Block)5 Batch (com.elmakers.mine.bukkit.api.batch.Batch)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)3 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 Location (org.bukkit.Location)3 Vector (org.bukkit.util.Vector)3 ActionHandler (com.elmakers.mine.bukkit.action.ActionHandler)2 UndoQueue (com.elmakers.mine.bukkit.api.block.UndoQueue)2 Wand (com.elmakers.mine.bukkit.api.wand.Wand)2 Target (com.elmakers.mine.bukkit.utility.Target)2 ArrayList (java.util.ArrayList)2 ArmorStand (org.bukkit.entity.ArmorStand)2 ActionContext (com.elmakers.mine.bukkit.action.ActionContext)1 SpellBatch (com.elmakers.mine.bukkit.api.batch.SpellBatch)1 CastEvent (com.elmakers.mine.bukkit.api.event.CastEvent)1 PreCastEvent (com.elmakers.mine.bukkit.api.event.PreCastEvent)1 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1