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;
}
Aggregations