use of com.elmakers.mine.bukkit.api.action.CastContext in project MagicPlugin by elBukkit.
the class UndoList method undo.
public void undo(boolean blocking, boolean undoEntities) {
if (undone)
return;
undone = true;
if (batch != null && !batch.isFinished()) {
batch.finish();
}
// This is a hack to make forced-undo happen instantly
if (undoEntities) {
this.speed = 0;
}
undoEntityEffects = undoEntityEffects || undoEntities;
unlink();
CastContext context = getContext();
if (context != null) {
context.cancelEffects();
}
if (runnables != null) {
for (Runnable runnable : runnables) {
runnable.run();
}
runnables = null;
}
if (blockList == null) {
undoEntityEffects();
return;
}
// Block changes will be performed in a batch
UndoBatch batch = new UndoBatch(this);
if (blocking) {
while (!batch.isFinished()) {
batch.process(1000);
}
} else {
owner.addUndoBatch(batch);
}
}
use of com.elmakers.mine.bukkit.api.action.CastContext in project MagicPlugin by elBukkit.
the class RecurseSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Block targetBlock = getTargetBlock();
if (targetBlock == null) {
return SpellResult.NO_TARGET;
}
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (!isDestructible(targetBlock)) {
return SpellResult.NO_TARGET;
}
BlockRecurse blockRecurse = new BlockRecurse();
int size = parameters.getInt("size", 8);
size = (int) (mage.getRadiusMultiplier() * size);
blockRecurse.setMaxRecursion(size);
ModifyBlockAction action = new ModifyBlockAction();
action.initialize(this, parameters);
blockRecurse.addReplaceable(new MaterialAndData(targetBlock));
Material targetMaterial = targetBlock.getType();
// A bit hacky, but is very handy!
if (targetMaterial == Material.STATIONARY_WATER || targetMaterial == Material.WATER) {
for (byte i = 0; i < 9; i++) {
blockRecurse.addReplaceable(Material.STATIONARY_WATER, i);
blockRecurse.addReplaceable(Material.WATER, i);
}
} else if (targetMaterial == Material.STATIONARY_LAVA || targetMaterial == Material.LAVA) {
for (byte i = 0; i < 9; i++) {
blockRecurse.addReplaceable(Material.STATIONARY_LAVA, i);
blockRecurse.addReplaceable(Material.LAVA, i);
}
} else if (targetMaterial == Material.SNOW) {
for (byte i = 0; i < 8; i++) {
blockRecurse.addReplaceable(Material.SNOW, i);
}
}
CastContext context = getCurrentCast();
context.setTargetLocation(targetBlock.getLocation());
blockRecurse.recurse(new ActionContext(action, parameters), context);
registerForUndo();
controller.updateBlock(targetBlock);
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.action.CastContext in project MagicPlugin by elBukkit.
the class UndoList method undoNext.
@Nullable
@Override
public BlockData undoNext(boolean applyPhysics) {
if (blockList.size() == 0) {
return null;
}
BlockData blockData = blockList.removeFirst();
BlockState currentState = blockData.getBlock().getState();
if (undo(blockData, applyPhysics)) {
blockIdMap.remove(blockData.getId());
if (consumed && !isScheduled() && currentState.getType() != Material.AIR && owner != null) {
owner.giveItem(new ItemStack(currentState.getType(), 1, DeprecatedUtils.getRawData(currentState)));
}
CastContext context = getContext();
if (context != null && context.hasEffects("undo_block")) {
Block block = blockData.getBlock();
if (block.getType() != currentState.getType()) {
context.playEffects("undo_block", 1.0f, null, null, block.getLocation(), null, block);
}
}
return blockData;
}
blockList.addFirst(blockData);
return null;
}
use of com.elmakers.mine.bukkit.api.action.CastContext in project MagicPlugin by elBukkit.
the class UndoBatch method finish.
@Override
public void finish() {
if (!finished) {
finished = true;
undoList.unregisterWatched();
undoList.undoEntityEffects();
if (!undoList.isScheduled()) {
controller.update(undoList);
}
CastContext context = undoList.getContext();
if (context != null) {
context.playEffects("undo_finished");
}
}
}
use of com.elmakers.mine.bukkit.api.action.CastContext in project MagicPlugin by elBukkit.
the class CastingCost method has.
@Override
public boolean has(Spell spell) {
CastContext context = spell.getCurrentCast();
Mage mage = context.getMage();
Wand wand = context.getWand();
return has(mage, wand, spell);
}
Aggregations