use of com.elmakers.mine.bukkit.api.block.UndoQueue in project MagicPlugin by elBukkit.
the class TransmuteSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
BlockList transmuteAction = null;
/*
* Use target if targeting
*/
Block target = getTargetBlock();
if (target != null) {
UndoQueue undoQueue = mage.getUndoQueue();
transmuteAction = undoQueue.getLast(target);
}
if (transmuteAction == null) {
UndoQueue undoQueue = mage.getUndoQueue();
transmuteAction = undoQueue.getLast();
}
if (transmuteAction == null) {
return SpellResult.NO_TARGET;
}
MaterialBrush buildWith = getBrush();
for (BlockData undoBlock : transmuteAction) {
Block block = undoBlock.getBlock();
buildWith.modify(block);
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.block.UndoQueue in project MagicPlugin by elBukkit.
the class UndoSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
int timeout = parameters.getInt("target_timeout", 0);
boolean targetSelf = parameters.getBoolean("target_up_self", false);
boolean targetDown = parameters.getBoolean("target_down_block", false);
Entity targetEntity = target.getEntity();
SpellResult result = SpellResult.CAST;
if (targetSelf && isLookingUp()) {
targetEntity = mage.getEntity();
getCurrentCast().setTargetName(mage.getName());
result = SpellResult.ALTERNATE_UP;
}
if (targetEntity != null && controller.isMage(targetEntity)) {
Mage targetMage = controller.getMage(targetEntity);
Batch batch = targetMage.cancelPending();
if (batch != null) {
undoListName = (batch instanceof SpellBatch) ? ((SpellBatch) batch).getSpell().getName() : null;
return SpellResult.ALTERNATE;
}
UndoQueue queue = targetMage.getUndoQueue();
UndoList undoList = queue.undoRecent(timeout);
if (undoList != null) {
undoListName = undoList.getName();
}
return undoList != null ? result : SpellResult.NO_TARGET;
}
if (!parameters.getBoolean("target_blocks", true)) {
return SpellResult.NO_TARGET;
}
Block targetBlock = target.getBlock();
if (targetDown && isLookingDown()) {
targetBlock = getLocation().getBlock();
}
if (targetBlock != null) {
boolean targetAll = mage.isSuperPowered();
if (targetAll) {
UndoList undid = controller.undoRecent(targetBlock, timeout);
if (undid != null) {
Mage targetMage = undid.getOwner();
undoListName = undid.getName();
getCurrentCast().setTargetName(targetMage.getName());
return result;
}
} else {
getCurrentCast().setTargetName(mage.getName());
UndoList undoList = mage.undo(targetBlock);
if (undoList != null) {
undoListName = undoList.getName();
return result;
}
}
}
return SpellResult.NO_TARGET;
}
use of com.elmakers.mine.bukkit.api.block.UndoQueue in project MagicPlugin by elBukkit.
the class UndoAction method perform.
@Override
public SpellResult perform(CastContext context) {
// Start of new functionality
if (undoOldest > 0 || undoToSize > 0) {
return performNew(context);
}
// Old functionality- this should be converted into an action that processes
// blocks instead of creating a separate batch.
Entity targetEntity = context.getTargetEntity();
SpellResult result = SpellResult.CAST;
Mage mage = context.getMage();
if (targetSelf) {
targetEntity = context.getEntity();
context.setTargetName(mage.getName());
result = SpellResult.ALTERNATE_UP;
}
MageController controller = context.getController();
if (targetEntity != null && controller.isMage(targetEntity)) {
Mage targetMage = controller.getMage(targetEntity);
mage.sendDebugMessage(ChatColor.AQUA + "Undo checking last spell of " + ChatColor.GOLD + targetMage + ChatColor.AQUA + " with timeout of " + ChatColor.YELLOW + timeout + ChatColor.AQUA + " for target spellKey" + ChatColor.BLUE + targetSpellKey, 2);
Batch batch = targetMage.cancelPending(targetSpellKey);
if (batch != null) {
undoListName = batch.getName();
if (cancel) {
return SpellResult.DEACTIVATE;
}
}
UndoQueue queue = targetMage.getUndoQueue();
UndoList undoList = queue.undoRecent(timeout, targetSpellKey);
if (undoList != null) {
undoListName = undoList.getName();
}
return undoList != null ? result : SpellResult.NO_TARGET;
}
if (!targetBlocks) {
return SpellResult.NO_TARGET;
}
Block targetBlock = context.getTargetBlock();
if (targetDown) {
targetBlock = context.getLocation().getBlock();
}
if (targetBlock != null) {
boolean undoAny = targetOtherBlocks;
undoAny = undoAny || (adminPermission != null && context.getController().hasPermission(context.getMage().getCommandSender(), adminPermission));
undoAny = undoAny || mage.isSuperPowered();
if (undoAny) {
mage.sendDebugMessage(ChatColor.AQUA + "Looking for recent cast at " + ChatColor.GOLD + targetBlock + ChatColor.AQUA + " with timeout of " + ChatColor.YELLOW + blockTimeout, 2);
UndoList undid = controller.undoRecent(targetBlock, blockTimeout);
if (undid != null) {
Mage targetMage = undid.getOwner();
undoListName = undid.getName();
if (targetMage != null) {
context.setTargetName(targetMage.getName());
}
return result;
}
} else {
mage.sendDebugMessage(ChatColor.AQUA + "Looking for recent self-cast at " + ChatColor.GOLD + targetBlock, 2);
context.setTargetName(mage.getName());
UndoList undoList = mage.undo(targetBlock);
if (undoList != null) {
undoListName = undoList.getName();
return result;
}
}
}
return SpellResult.NO_TARGET;
}
Aggregations