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